User prompt
For first level distribute 0.25 and 0.75
User prompt
For first level use only 2 vials
User prompt
In checkWinCondition use something else than Set() something more classic
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var colorSet = new Set();' Line Number: 236
User prompt
checkWinCondition Is incomplete: each colour must be in an unique vial
User prompt
After each pouring, check win condition
Code edit (1 edits merged)
Please save this source code
User prompt
Rework distributeLiquids
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'self.liquids.push({' Line Number: 37
User prompt
Fix that
User prompt
distributeLiquids Should consider each colour to be available at a volume of 1 and distribute randomly multiples of BASE_LIQUID_RATIO among vials
Code edit (1 edits merged)
Please save this source code
User prompt
In initLiquids, colours should appear only once
User prompt
In liquidGraphics.height calculation use fillHeight
User prompt
Use baseLiquidY in vial class
User prompt
Add a baseLiquidY to vial class equal to tubeGraphics.height - 25
User prompt
Use self.fillHeight in vial class
User prompt
Add fill height property to vial class equal to tubeGraphics.height - 25 - 100
Code edit (1 edits merged)
Please save this source code
User prompt
When pouring 0.25 and 0.25 in the 3rd vial, the ratio is 0.5 but it appears like 0.25 in size. Fix that But don’t break initial positioning of liquid as it is correct.
User prompt
When pouring 0.25 and 0.25 in the 3rd vial, the ratio is 0.5 but it appears like 0.25 in size. Fix that
Code edit (1 edits merged)
Please save this source code
User prompt
In Down event, use updateDebugText to write selected tube liquids in a concise manner
Code edit (1 edits merged)
Please save this source code
User prompt
Add debug text in down event (Debugtxt, not console.log)
/**** * Classes ****/ var Liquid = Container.expand(function (color) { var self = Container.call(this); self.color = color; var liquidGraphics = self.attachAsset(color, { anchorX: 0.5, anchorY: 0.0 }); return self; }); var Vial = Container.expand(function () { var self = Container.call(this); // Attach graphical representation var tubeGraphics = self.attachAsset('tube', { anchorX: 0.5, anchorY: 0.0, alpha: 0.65 }); self.fillHeight = tubeGraphics.height - 25 - 100; self.baseLiquidY = tubeGraphics.height - 25; 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.canPour = 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; }; self.renderLiquids = function () { // Remove all existing liquid graphics for (var i = self.children.length - 1; i >= 0; i--) { if (self.children[i] !== tubeGraphics) { self.removeChild(self.children[i]); } } // Add new liquid graphics based on the current state of self.liquids for (var j = 0; j < self.liquids.length; j++) { var liquid = self.liquids[j]; var liquidGraphics = self.attachAsset(liquid.color, { anchorX: 0.5, anchorY: 1.0 }); liquidGraphics.y = self.baseLiquidY; // Adjust the offset to prevent liquids from appearing out of the vial bottom liquidGraphics.height = self.fillHeight * liquid.ratio; self.addChildAt(liquidGraphics, 0); // Add debug text for liquidGraphics.y for index 0 and tubeGraphics.height if (j === 0) { updateDebugText('.y for index 0: ' + liquidGraphics.y + ' | .height: ' + tubeGraphics.height); } } }; self.down = function (x, y, obj) { var liquidInfo = self.liquids.map(function (liquid) { return liquid.color + ": " + liquid.ratio; }).join(", "); updateDebugText("Selected Vial Liquids: " + liquidInfo); if (selectedTube === self) { self.scale.set(1, 1); // Reset the scale of the selected tube selectedTube = null; // Unselect the tube } else if (selectedTube) { var pourRatio = selectedTube.canPour(self); if (pourRatio > 0) { var liquid = selectedTube.removeLiquid(pourRatio); self.addLiquid(liquid, liquid.ratio); selectedTube.renderLiquids(); self.renderLiquids(); selectedTube.scale.set(1, 1); // Reset the scale of the previously selected tube selectedTube = null; } else if (!selectedTube) { selectedTube.scale.set(1, 1); // Reset the scale if selection is wrong selectedTube = null; } } else { selectedTube = self; self.scale.set(1.1, 1.1); // Highlight the selected tube by making it bigger } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Create debug text var debugTxt = new Text2('Debug Info', { size: 50, fill: "#FFFFFF" }); debugTxt.anchor.set(0, 1); LK.gui.bottomLeft.addChild(debugTxt); // Function to update debug text function updateDebugText(info) { debugTxt.setText(info); } // Create an instance of the PuzzleManager var PuzzleManager = function PuzzleManager() { var self = this; self.liquids = []; // Public property to store liquids self.initVials = function () { self.vials = [new Vial(), new Vial(), new Vial()]; // Initialize vials with new Vial instances var positions = [{ x: 2048 / 4, y: (2732 - 735.42 * 2) / 2 + 600 }, { x: 2048 * 2 / 4, y: (2732 - 735.42 * 2) / 2 + 600 }, { x: 2048 * 3 / 4, y: (2732 - 735.42 * 2) / 2 + 600 }]; for (var i = 0; i < self.vials.length; i++) { self.vials[i].x = positions[i].x; self.vials[i].y = positions[i].y; game.addChild(self.vials[i]); } }; // Initialize liquids self.initLiquids = function (level) { // Create and initialize liquid objects based on level if (level === 1) { self.liquids = [new Liquid('liquidGreen')]; } else { self.liquids = [new Liquid('liquidBlue'), new Liquid('liquidGreen'), new Liquid('liquidRed')]; } }; // Distribute liquids into tubes or vials self.distributeLiquids = function () { // Distribute initialized liquids into the provided vials if (self.vials.length > 0) { var totalVolume = self.liquids.length; var remainingVolume = totalVolume; var vialVolumes = new Array(self.vials.length).fill(0); // Distribute volumes randomly while (remainingVolume > 0) { for (var i = 0; i < self.vials.length; i++) { if (remainingVolume <= 0) { break; } var volumeToAdd = Math.min(BASE_LIQUID_RATIO, remainingVolume); vialVolumes[i] += volumeToAdd; remainingVolume -= volumeToAdd; } } // Assign liquids to vials based on distributed volumes for (var j = 0; j < self.liquids.length; j++) { var vialIndex = j % self.vials.length; self.vials[vialIndex].addLiquid(self.liquids[j], vialVolumes[vialIndex]); } } }; // 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.initVials(); self.initLiquids(level); self.distributeLiquids(); for (var i = 0; i < self.vials.length; i++) { self.vials[i].renderLiquids(); } }; return self; }; var BASE_LIQUID_RATIO = 0.25; // var tubes = []; // Removed redundant initialization var puzzleManager = new PuzzleManager(); puzzleManager.init(1); // Example level parameter // var tubes = []; // Removed redundant initialization var selectedTube = null; 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()); } // 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 // Update debug text with current time and score updateDebugText('Time: ' + timeLeft + ' | Score: ' + score); } ; LK.showGameOver(); } } };
===================================================================
--- original.js
+++ change.js
@@ -189,12 +189,27 @@
// 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 < self.liquids.length; i++) {
- var vialIndex = i % self.vials.length;
- self.vials[vialIndex].addLiquid(self.liquids[i], BASE_LIQUID_RATIO);
+ var totalVolume = self.liquids.length;
+ var remainingVolume = totalVolume;
+ var vialVolumes = new Array(self.vials.length).fill(0);
+ // Distribute volumes randomly
+ while (remainingVolume > 0) {
+ for (var i = 0; i < self.vials.length; i++) {
+ if (remainingVolume <= 0) {
+ break;
+ }
+ var volumeToAdd = Math.min(BASE_LIQUID_RATIO, remainingVolume);
+ vialVolumes[i] += volumeToAdd;
+ remainingVolume -= volumeToAdd;
+ }
}
+ // Assign liquids to vials based on distributed volumes
+ for (var j = 0; j < self.liquids.length; j++) {
+ var vialIndex = j % self.vials.length;
+ self.vials[vialIndex].addLiquid(self.liquids[j], vialVolumes[vialIndex]);
+ }
}
};
// Check if the puzzle is solvable
self.isSolvable = function () {
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