Code edit (1 edits merged)
Please save this source code
User prompt
Include self.vials = [new Vial(), new Vial(), new Vial()]; // Initialize vials with new Vial instances in initVials
Code edit (1 edits merged)
Please save this source code
User prompt
Don’t use 'liquid' + color.charAt(0).toUpperCase() + color.slice(1) just color
User prompt
In Liquid class store the colour parameter in a public property
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var liquidGraphics = self.attachAsset('liquid' + liquid.color.charAt(0).toUpperCase() + liquid.color.slice(1), {' Line Number: 101
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var liquidGraphics = self.attachAsset('liquid' + liquid.color.charAt(0).toUpperCase() + liquid.color.slice(1) + 'Shape', {' Line Number: 101
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var liquidGraphics = self.attachAsset('liquid' + liquid.color.charAt(0).toUpperCase() + liquid.color.slice(1), {' Line Number: 101
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var liquidGraphics = self.attachAsset('liquid' + color.charAt(0).toUpperCase() + color.slice(1), {' Line Number: 101
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var liquidGraphics = self.attachAsset(liquid.color, {' Line Number: 101
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var liquidGraphics = self.attachAsset(liquid.color, {' Line Number: 101
User prompt
In PuzzleManager init at the end call renderLiquids on vials
User prompt
Remove createLiquid
User prompt
Don’t call puzzleManager.checkWinCondition() in game update
User prompt
Now puzzleManger and vials are ready so remove tubes related code
Code edit (1 edits merged)
Please save this source code
User prompt
In PuzzleManager add a initVials function to create and position vials
Code edit (1 edits merged)
Please save this source code
User prompt
Add a renderLiquids to vial class responsible of displaying liquids in the vial depending on the colour index and ratio
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'tubes[0].addLiquid(createLiquid('liquidGreen'));' Line Number: 287
User prompt
Pass level to initLiquids and for level 1 use only green
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'tubes.push(newTube);' Line Number: 267
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'newTube.x = 2048 / 4 * (tubes.length + 1);' Line Number: 265
User prompt
In self.vials = […] don’t use tube but vial
/**** * Classes ****/ var Liquid = Container.expand(function (color) { var self = Container.call(this); var liquidGraphics = self.attachAsset(color, { anchorX: 0.5, anchorY: 0.0 }); return self; }); //<Assets used in the game will automatically appear here> var Tube = Container.expand(function () { var self = Container.call(this); var tubeGraphics = self.attachAsset('tube', { anchorX: 0.5, anchorY: 0.0 }); self.liquids = []; // Initialize functional representation self.liquidsAssets = []; tubeGraphics.alpha = 0.6; self.addChild(tubeGraphics); self.addLiquid = function (liquid) { self.liquidsAssets.push(liquid); self.addChildAt(liquid, 0); self.liquids.push({ color: liquid.color, index: self.liquidsAssets.length - 1 }); // Add functional representation self.updateGraphics(); }; self.removeLiquid = function () { var liquid = self.liquidsAssets.pop(); self.removeChild(liquid); self.updateGraphics(); liquid.scale.set(1, 2); // Ensure the width remains constant self.liquids.pop(); // Remove functional representation self.updateLiquids(); // Update functional representation return liquid; }; self.updateLiquids = function () { for (var i = 0; i < self.liquids.length; i++) { self.liquids[i].index = i; // Ratio calculation removed } }; self.containsPoint = function (point) { var bounds = self.getBounds(); return point.x >= bounds.x && point.x <= bounds.x + bounds.width && point.y >= bounds.y && point.y <= bounds.y + bounds.height; }; self.down = function (x, y, obj) { if (selectedTube) { if (selectedTube !== self && self.liquidsAssets.length < MAX_TUBE_CAPACITY) { var topLiquid = selectedTube.liquidsAssets[selectedTube.liquidsAssets.length - 1]; if (topLiquid && (self.liquidsAssets.length === 0 || self.liquidsAssets[self.liquidsAssets.length - 1].color === topLiquid.color)) { var sameColorCount = 0; for (var i = selectedTube.liquidsAssets.length - 1; i >= 0; i--) { if (selectedTube.liquidsAssets[i].color === topLiquid.color) { sameColorCount++; } else { break; } } if (self.liquidsAssets.length + sameColorCount <= 1 / BASE_LIQUID_RATIO) { for (var j = 0; j < sameColorCount; j++) { self.addLiquid(selectedTube.removeLiquid()); } } } } selectedTube.scale.set(1.4, 1.4); // Reset the scale of the previously selected tube selectedTube = null; } else { selectedTube = self; self.scale.set(1.7, 1.7); // Increase the scale of the selected tube } }; self.updateFunctionalLiquids = function () { for (var i = 0; i < self.liquids.length; i++) { self.liquids[i].index = i; // Ratio calculation removed } }; self.updateGraphics = function () { for (var i = 0; i < self.liquidsAssets.length; i++) { self.liquidsAssets[i].scale.x = 1; // Ensure the width remains constant self.liquidsAssets[i].scale.y = 1; // Ensure the height remains constant self.liquidsAssets[i].y = tubeGraphics.height - (i + 1) * 200 - 20; // Adjust the position of each liquid } }; }); var Vial = Container.expand(function () { var self = Container.call(this); // Attach graphical representation var tubeGraphics = self.attachAsset('tube', { anchorX: 0.5, anchorY: 0.0 }); self.addChild(tubeGraphics); self.liquids = []; // Initialize functional representation self.addLiquid = function (liquid, ratio) { if (self.liquids.length > 0 && self.liquids[self.liquids.length - 1].color === liquid.color) { self.liquids[self.liquids.length - 1].ratio += ratio; } else { self.liquids.push({ color: liquid.color, index: self.liquids.length, ratio: ratio }); } }; self.removeLiquid = function (ratio) { if (self.liquids.length > 0) { var topLiquid = self.liquids[self.liquids.length - 1]; if (ratio >= topLiquid.ratio) { var removedLiquid = self.liquids.pop(); if (self.liquids.length > 0 && self.liquids[self.liquids.length - 1].color === removedLiquid.color) { self.liquids[self.liquids.length - 1].ratio += removedLiquid.ratio; } return removedLiquid; } else { topLiquid.ratio -= ratio; return { color: topLiquid.color, ratio: ratio }; } } return null; }; self.containsPoint = function (point) { var bounds = self.getBounds(); return point.x >= bounds.x && point.x <= bounds.x + bounds.width && point.y >= bounds.y + bounds.height; }; self.canPoure = function (destinationTube) { if (self.liquids.length === 0) { return 0; // No liquid to pour } if (destinationTube.liquids.length === 0) { return 1; // Destination tube is empty, can pour all } var topLiquid = self.liquids[self.liquids.length - 1]; var destinationTopLiquid = destinationTube.liquids[destinationTube.liquids.length - 1]; if (topLiquid.color !== destinationTopLiquid.color) { return 0; // Different colors, cannot pour } var sameColorCount = 0; for (var i = self.liquids.length - 1; i >= 0; i--) { if (self.liquids[i].color === topLiquid.color) { sameColorCount++; } else { break; } } var totalRatio = destinationTube.liquids.reduce(function (sum, liquid) { return sum + liquid.ratio; }, 0); var availableSpace = 1 - totalRatio; return Math.min(sameColorCount, availableSpace) / sameColorCount; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Create an instance of the PuzzleManager var PuzzleManager = function PuzzleManager() { var self = this; // Initialize liquids self.initLiquids = function () { // Create and initialize liquid objects liquids = [createLiquid('liquidBlue'), createLiquid('liquidBlue'), createLiquid('liquidGreen'), createLiquid('liquidGreen'), createLiquid('liquidRed'), createLiquid('liquidRed')]; }; // Distribute liquids into tubes or vials self.distributeLiquids = function () { // Distribute initialized liquids into the provided vials if (self.vials.length > 0) { for (var i = 0; i < liquids.length; i++) { var vialIndex = i % self.vials.length; self.vials[vialIndex].addLiquid(liquids[i], BASE_LIQUID_RATIO); } } }; // Check if the puzzle is solvable self.isSolvable = function () { // Implement logic to check if the current state of the puzzle is solvable // Placeholder logic: always return true for now return true; }; // Check for win conditions self.checkWinCondition = function () { // Implement logic to check if the puzzle is solved for (var i = 0; i < self.vials.length; i++) { if (self.vials[i].liquids.length > 0) { var firstColor = self.vials[i].liquids[0].color; for (var j = 1; j < self.vials[i].liquids.length; j++) { if (self.vials[i].liquids[j].color !== firstColor) { return false; } } } } return true; }; // Initialize the puzzle manager self.init = function (level) { self.vials = [new Vial(), new Vial(), new Vial()]; // Initialize vials with new Vial instances self.initLiquids(level); self.distributeLiquids(); }; return self; }; // var tubes = []; // Removed redundant initialization var puzzleManager = new PuzzleManager(); puzzleManager.init(1); // Example level parameter var BASE_LIQUID_RATIO = 0.25; // var tubes = []; // Removed redundant initialization var selectedTube = null; var liquids = []; var timeLeft = 60; // Initialize the timer with 60 seconds var score = 0; // Initialize the score with 0 var scoreTxt = new Text2('0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create timer display var timerTxt = new Text2('60', { size: 100, fill: "#ffffff" }); timerTxt.anchor.set(1, 0); LK.gui.topRight.addChild(timerTxt); // Function to update score function updateScore(newScore) { score = newScore; scoreTxt.setText(score.toString()); } // Function to update timer function updateTimer(newTime) { timeLeft = newTime; timerTxt.setText(timeLeft.toString()); } function createTube(x, y) { var newTube = new Tube(); newTube.scale.set(1.4, 1.4); newTube.x = 2048 / 4 * (tubes.length + 1); newTube.y = (2732 - 735.42 * 2) / 2 + 600; tubes.push(newTube); game.addChild(newTube); } function createLiquid(color) { var liquid = new Liquid(color); liquid.color = color; return liquid; } // Create initial tubes createTube(2048 / 4, (2732 - 735.42 * 2) / 2 + 600); createTube(2048 * 2 / 4, (2732 - 735.42 * 2) / 2 + 600); createTube(2048 * 3 / 4, (2732 - 735.42 * 2) / 2 + 600); tubes[0].addLiquid(createLiquid('liquidGreen')); tubes[1].addLiquid(createLiquid('liquidGreen')); // Game update function game.update = function () { // Update timer if (LK.ticks % 60 == 0) { // Decrease time every second updateTimer(timeLeft - 1); if (timeLeft <= 0) { if (selectedTube) { selectedTube.scale.set(1, 1); // Reset the scale of the selected tube } LK.showGameOver(); } // Check if all liquids of the same color are grouped in the same tube var allGrouped = true; if (puzzleManager.checkWinCondition()) { LK.showGameOver(); } } };
/****
* Classes
****/
var Liquid = Container.expand(function (color) {
var self = Container.call(this);
var liquidGraphics = self.attachAsset(color, {
anchorX: 0.5,
anchorY: 0.0
});
return self;
});
//<Assets used in the game will automatically appear here>
var Tube = Container.expand(function () {
var self = Container.call(this);
var tubeGraphics = self.attachAsset('tube', {
anchorX: 0.5,
anchorY: 0.0
});
self.liquids = []; // Initialize functional representation
self.liquidsAssets = [];
tubeGraphics.alpha = 0.6;
self.addChild(tubeGraphics);
self.addLiquid = function (liquid) {
self.liquidsAssets.push(liquid);
self.addChildAt(liquid, 0);
self.liquids.push({
color: liquid.color,
index: self.liquidsAssets.length - 1
}); // Add functional representation
self.updateGraphics();
};
self.removeLiquid = function () {
var liquid = self.liquidsAssets.pop();
self.removeChild(liquid);
self.updateGraphics();
liquid.scale.set(1, 2); // Ensure the width remains constant
self.liquids.pop(); // Remove functional representation
self.updateLiquids(); // Update functional representation
return liquid;
};
self.updateLiquids = function () {
for (var i = 0; i < self.liquids.length; i++) {
self.liquids[i].index = i;
// Ratio calculation removed
}
};
self.containsPoint = function (point) {
var bounds = self.getBounds();
return point.x >= bounds.x && point.x <= bounds.x + bounds.width && point.y >= bounds.y && point.y <= bounds.y + bounds.height;
};
self.down = function (x, y, obj) {
if (selectedTube) {
if (selectedTube !== self && self.liquidsAssets.length < MAX_TUBE_CAPACITY) {
var topLiquid = selectedTube.liquidsAssets[selectedTube.liquidsAssets.length - 1];
if (topLiquid && (self.liquidsAssets.length === 0 || self.liquidsAssets[self.liquidsAssets.length - 1].color === topLiquid.color)) {
var sameColorCount = 0;
for (var i = selectedTube.liquidsAssets.length - 1; i >= 0; i--) {
if (selectedTube.liquidsAssets[i].color === topLiquid.color) {
sameColorCount++;
} else {
break;
}
}
if (self.liquidsAssets.length + sameColorCount <= 1 / BASE_LIQUID_RATIO) {
for (var j = 0; j < sameColorCount; j++) {
self.addLiquid(selectedTube.removeLiquid());
}
}
}
}
selectedTube.scale.set(1.4, 1.4); // Reset the scale of the previously selected tube
selectedTube = null;
} else {
selectedTube = self;
self.scale.set(1.7, 1.7); // Increase the scale of the selected tube
}
};
self.updateFunctionalLiquids = function () {
for (var i = 0; i < self.liquids.length; i++) {
self.liquids[i].index = i;
// Ratio calculation removed
}
};
self.updateGraphics = function () {
for (var i = 0; i < self.liquidsAssets.length; i++) {
self.liquidsAssets[i].scale.x = 1; // Ensure the width remains constant
self.liquidsAssets[i].scale.y = 1; // Ensure the height remains constant
self.liquidsAssets[i].y = tubeGraphics.height - (i + 1) * 200 - 20; // Adjust the position of each liquid
}
};
});
var Vial = Container.expand(function () {
var self = Container.call(this);
// Attach graphical representation
var tubeGraphics = self.attachAsset('tube', {
anchorX: 0.5,
anchorY: 0.0
});
self.addChild(tubeGraphics);
self.liquids = []; // Initialize functional representation
self.addLiquid = function (liquid, ratio) {
if (self.liquids.length > 0 && self.liquids[self.liquids.length - 1].color === liquid.color) {
self.liquids[self.liquids.length - 1].ratio += ratio;
} else {
self.liquids.push({
color: liquid.color,
index: self.liquids.length,
ratio: ratio
});
}
};
self.removeLiquid = function (ratio) {
if (self.liquids.length > 0) {
var topLiquid = self.liquids[self.liquids.length - 1];
if (ratio >= topLiquid.ratio) {
var removedLiquid = self.liquids.pop();
if (self.liquids.length > 0 && self.liquids[self.liquids.length - 1].color === removedLiquid.color) {
self.liquids[self.liquids.length - 1].ratio += removedLiquid.ratio;
}
return removedLiquid;
} else {
topLiquid.ratio -= ratio;
return {
color: topLiquid.color,
ratio: ratio
};
}
}
return null;
};
self.containsPoint = function (point) {
var bounds = self.getBounds();
return point.x >= bounds.x && point.x <= bounds.x + bounds.width && point.y >= bounds.y + bounds.height;
};
self.canPoure = function (destinationTube) {
if (self.liquids.length === 0) {
return 0; // No liquid to pour
}
if (destinationTube.liquids.length === 0) {
return 1; // Destination tube is empty, can pour all
}
var topLiquid = self.liquids[self.liquids.length - 1];
var destinationTopLiquid = destinationTube.liquids[destinationTube.liquids.length - 1];
if (topLiquid.color !== destinationTopLiquid.color) {
return 0; // Different colors, cannot pour
}
var sameColorCount = 0;
for (var i = self.liquids.length - 1; i >= 0; i--) {
if (self.liquids[i].color === topLiquid.color) {
sameColorCount++;
} else {
break;
}
}
var totalRatio = destinationTube.liquids.reduce(function (sum, liquid) {
return sum + liquid.ratio;
}, 0);
var availableSpace = 1 - totalRatio;
return Math.min(sameColorCount, availableSpace) / sameColorCount;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Create an instance of the PuzzleManager
var PuzzleManager = function PuzzleManager() {
var self = this;
// Initialize liquids
self.initLiquids = function () {
// Create and initialize liquid objects
liquids = [createLiquid('liquidBlue'), createLiquid('liquidBlue'), createLiquid('liquidGreen'), createLiquid('liquidGreen'), createLiquid('liquidRed'), createLiquid('liquidRed')];
};
// Distribute liquids into tubes or vials
self.distributeLiquids = function () {
// Distribute initialized liquids into the provided vials
if (self.vials.length > 0) {
for (var i = 0; i < liquids.length; i++) {
var vialIndex = i % self.vials.length;
self.vials[vialIndex].addLiquid(liquids[i], BASE_LIQUID_RATIO);
}
}
};
// Check if the puzzle is solvable
self.isSolvable = function () {
// Implement logic to check if the current state of the puzzle is solvable
// Placeholder logic: always return true for now
return true;
};
// Check for win conditions
self.checkWinCondition = function () {
// Implement logic to check if the puzzle is solved
for (var i = 0; i < self.vials.length; i++) {
if (self.vials[i].liquids.length > 0) {
var firstColor = self.vials[i].liquids[0].color;
for (var j = 1; j < self.vials[i].liquids.length; j++) {
if (self.vials[i].liquids[j].color !== firstColor) {
return false;
}
}
}
}
return true;
};
// Initialize the puzzle manager
self.init = function (level) {
self.vials = [new Vial(), new Vial(), new Vial()]; // Initialize vials with new Vial instances
self.initLiquids(level);
self.distributeLiquids();
};
return self;
};
// var tubes = []; // Removed redundant initialization
var puzzleManager = new PuzzleManager();
puzzleManager.init(1); // Example level parameter
var BASE_LIQUID_RATIO = 0.25;
// var tubes = []; // Removed redundant initialization
var selectedTube = null;
var liquids = [];
var timeLeft = 60; // Initialize the timer with 60 seconds
var score = 0; // Initialize the score with 0
var scoreTxt = new Text2('0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create timer display
var timerTxt = new Text2('60', {
size: 100,
fill: "#ffffff"
});
timerTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timerTxt);
// Function to update score
function updateScore(newScore) {
score = newScore;
scoreTxt.setText(score.toString());
}
// Function to update timer
function updateTimer(newTime) {
timeLeft = newTime;
timerTxt.setText(timeLeft.toString());
}
function createTube(x, y) {
var newTube = new Tube();
newTube.scale.set(1.4, 1.4);
newTube.x = 2048 / 4 * (tubes.length + 1);
newTube.y = (2732 - 735.42 * 2) / 2 + 600;
tubes.push(newTube);
game.addChild(newTube);
}
function createLiquid(color) {
var liquid = new Liquid(color);
liquid.color = color;
return liquid;
}
// Create initial tubes
createTube(2048 / 4, (2732 - 735.42 * 2) / 2 + 600);
createTube(2048 * 2 / 4, (2732 - 735.42 * 2) / 2 + 600);
createTube(2048 * 3 / 4, (2732 - 735.42 * 2) / 2 + 600);
tubes[0].addLiquid(createLiquid('liquidGreen'));
tubes[1].addLiquid(createLiquid('liquidGreen'));
// Game update function
game.update = function () {
// Update timer
if (LK.ticks % 60 == 0) {
// Decrease time every second
updateTimer(timeLeft - 1);
if (timeLeft <= 0) {
if (selectedTube) {
selectedTube.scale.set(1, 1); // Reset the scale of the selected tube
}
LK.showGameOver();
}
// Check if all liquids of the same color are grouped in the same tube
var allGrouped = true;
if (puzzleManager.checkWinCondition()) {
LK.showGameOver();
}
}
};
Basic white Restart icon (rounded arrow). UI
Une classe d’une école de sorcière sans les élèves.
un sablier de sorcière.
a bubble.
exploded broken glass
Yound generously beautifull teacher witch smiling, with glasses, a black witch hat, holding a little brown book in her hands and looking at the camera. wearing light black clothes. Torso head and hat should appear.
tap
Sound effect
drop
Sound effect
reset
Sound effect
wrong
Sound effect
yes
Sound effect
goodJob
Sound effect
pouring
Sound effect
welcome
Sound effect
rememberTheRules
Sound effect
letsgo
Sound effect
hurryUp
Sound effect
boom
Sound effect
tryAgain
Sound effect
rainbowBoom
Sound effect
youDidIt
Sound effect
letmetry
Sound effect
rainbowMix
Sound effect
thankYou1
Sound effect
thankYou2
Sound effect
thankYou3
Sound effect
thankYou4
Sound effect
bonusTime
Sound effect