User prompt
log states enter and change and the checkWinCondition
Code edit (1 edits merged)
Please save this source code
User prompt
add logs in checkWinCondition
User prompt
Please fix the bug: 'Uncaught TypeError: Set is not a constructor' in or related to this line: 'return self.canReachEnd(startX, startY, new Set());' Line Number: 676
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: self.checkWinCondition is not a function' in or related to this line: 'if (self.checkWinCondition()) {' Line Number: 640
Code edit (1 edits merged)
Please save this source code
User prompt
add log in initPuzlle
User prompt
add a log in each initXXXState function
User prompt
add log on states changes
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'updatePosition')' in or related to this line: 'emptyTile.updatePosition(x, y);' Line Number: 493
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '1')' in or related to this line: 'var baseTileAsset = type == 'start' || type == 'end' || puzzleManager && puzzleManager.levelConfigs[puzzleManager.currentLevel].fixedTiles.includes(x + ',' + y) ? 'baseTile' : 'baseMobileTile';' Line Number: 43
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: puzzleManager.rotateTile is not a function' in or related to this line: 'puzzleManager.rotateTile(angle);' Line Number: 1033
User prompt
Please fix the bug: 'Uncaught TypeError: puzzleManager.deselectTile is not a function' in or related to this line: 'puzzleManager.deselectTile();' Line Number: 1037
User prompt
Please fix the bug: 'Uncaught TypeError: puzzleManager.reset is not a function' in or related to this line: 'puzzleManager.reset();' Line Number: 916
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: PuzzleManager is not a constructor' in or related to this line: 'puzzleManager = new PuzzleManager();' Line Number: 439
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: gridBoard.hideMessage is not a function' in or related to this line: 'gridBoard.hideMessage();' Line Number: 493
User prompt
Please fix the bug: 'TypeError: gridBoard.hideMessage is not a function' in or related to this line: 'gridBoard.hideMessage();' Line Number: 494
User prompt
Please fix the bug: 'TypeError: gridBoard.hideMessage is not a function' in or related to this line: 'gridBoard.hideMessage();' Line Number: 493
User prompt
Please fix the bug: 'Uncaught ReferenceError: GridBoard is not defined' in or related to this line: 'gridBoard = new GridBoard();' Line Number: 439
Code edit (3 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -243,8 +243,33 @@
self.x = x * tileSize + gridBoard.x - gridBoard.width / 2 + tileSize / 2 + boardOffsetX;
self.y = y * tileSize + gridBoard.y - gridBoard.height / 2 + tileSize / 2 + boardOffsetY;
log('Tile index:', x, y, 'Tile position:', self.x, self.y, 'Tile dimensions:', self.width, self.height, ' self:', self);
};
+ self.normalizeRotation = function (rotation) {
+ // If rotation is a number (radians), convert it to our direction system
+ if (typeof rotation === 'number') {
+ // Convert radians to our direction system
+ // 0 = right
+ // π/2 = down
+ // π = left
+ // 3π/2 = up
+ var angle = rotation % (2 * Math.PI);
+ if (angle < 0) {
+ angle += 2 * Math.PI;
+ }
+ if (angle < Math.PI / 4 || angle > 7 * Math.PI / 4) {
+ return 'right';
+ }
+ if (angle < 3 * Math.PI / 4) {
+ return 'down';
+ }
+ if (angle < 5 * Math.PI / 4) {
+ return 'left';
+ }
+ return 'up';
+ }
+ return rotation || 'down';
+ };
self.setRotation = function (direction) {
switch (direction) {
case 'left':
self.rotation = Math.PI * 0.5;
@@ -638,139 +663,185 @@
levelText.setText('Level: ' + self.currentLevel + ' Solved!');
isPlaying = false;
}
};
+ self.startWaterFlow = function () {
+ if (self.waterFlowing) {
+ return;
+ }
+ self.waterFlowing = true;
+ // Find start position
+ var startX = -1,
+ startY = -1;
+ for (var i = 0; i < self.gridSize; i++) {
+ for (var j = 0; j < self.gridSize; j++) {
+ if (self.grid[i][j].type === 'start') {
+ startX = i;
+ startY = j;
+ break;
+ }
+ }
+ if (startX !== -1) {
+ break;
+ }
+ }
+ // Start the flow animation from the start tile
+ if (startX !== -1) {
+ var startTile = self.grid[startX][startY];
+ startTile.flow = true;
+ startTile.startFlowTicks = 0;
+ // Start valve animation
+ if (startTile.valve) {
+ startTile.valve.rotationSpeed = 0.1;
+ }
+ // Start flowing through pipes
+ self.flowThroughPipe(startX, startY + 1, [startX + ',' + startY]);
+ }
+ };
+ self.flowThroughPipe = function (x, y, visited) {
+ if (x < 0 || x >= self.gridSize || y < 0 || y >= self.gridSize) {
+ return;
+ }
+ var key = x + ',' + y;
+ if (visited.includes(key)) {
+ return;
+ }
+ visited.push(key);
+ var tile = self.grid[x][y];
+ if (!tile || tile.type === 'empty') {
+ return;
+ }
+ // Start flow animation for this tile
+ tile.flow = true;
+ tile.startFlowTicks = visited.length * 30; // Delay based on distance from start
+ // Get next positions to flow to
+ var nextPositions = [];
+ switch (tile.type) {
+ case 'straightPipeV':
+ nextPositions.push([x, y - 1], [x, y + 1]); // Up and down
+ break;
+ case 'straightPipeH':
+ nextPositions.push([x - 1, y], [x + 1, y]); // Left and right
+ break;
+ case 'cornerPipe':
+ switch (tile.rotation) {
+ case 'up':
+ // ┗
+ nextPositions.push([x, y - 1], [x + 1, y]); // Up and right
+ break;
+ case 'right':
+ // ┏
+ nextPositions.push([x + 1, y], [x, y + 1]); // Right and down
+ break;
+ case 'down':
+ // ┓
+ nextPositions.push([x - 1, y], [x, y + 1]); // Left and down
+ break;
+ case 'left':
+ // ┛
+ nextPositions.push([x - 1, y], [x, y - 1]); // Left and up
+ break;
+ }
+ break;
+ case 'end':
+ // Create water drops effect
+ createWaterDrops(tile.x, tile.y + 100, game);
+ break;
+ }
+ // Continue flow to next positions
+ for (var i = 0; i < nextPositions.length; i++) {
+ self.flowThroughPipe(nextPositions[i][0], nextPositions[i][1], visited);
+ }
+ };
self.reset = function () {
self.currentLevel = 1;
self.selectedTile = null;
self.isComplete = false;
self.waterFlowing = false;
self.initPuzzle();
};
self.checkWinCondition = function () {
- // Find start tile
- var startTile = null;
- var startX = 0;
- var startY = 0;
+ // Find start position
+ console.log("Checking win condition");
+ var startX = -1,
+ startY = -1;
for (var i = 0; i < self.gridSize; i++) {
for (var j = 0; j < self.gridSize; j++) {
if (self.grid[i][j].type === 'start') {
- startTile = self.grid[i][j];
startX = i;
startY = j;
- log("Start tile found at:", startX, startY);
break;
}
}
- if (startTile) {
+ if (startX !== -1) {
break;
}
}
- if (!startTile) {
- log("No start tile found");
- return false;
- }
- // Check if there's a valid path from start to end
- var result = self.canReachEnd(startX, startY, new SimpleSet());
- log("Win condition result:", result);
- return result;
+ // Use array to track visited positions (simpler than Set)
+ var visited = [];
+ // Start flowing down from start
+ return self.canReachEnd(startX, startY + 1, visited);
};
self.canReachEnd = function (x, y, visited) {
- log("Checking position:", x, y);
// Check bounds
if (x < 0 || x >= self.gridSize || y < 0 || y >= self.gridSize) {
- log("Out of bounds");
return false;
}
- // Get current tile
- var tile = self.grid[x][y];
- if (!tile) {
- log("No tile at position");
+ // Create position key
+ var key = x + ',' + y;
+ if (visited.includes(key)) {
return false;
}
- // Mark as visited
- var key = x + ',' + y;
- if (visited.has(key)) {
- log("Already visited");
+ visited.push(key);
+ var tile = self.grid[x][y];
+ if (!tile || tile.type === 'empty') {
return false;
}
- visited.add(key);
- log("Checking tile type:", tile.type);
- // If we reached the end tile, success!
+ // If we reached the end, success!
if (tile.type === 'end') {
- log("Found end tile!");
return true;
}
- // Get possible directions based on tile type and rotation
- var directions = [];
+ // Get next possible positions based on current tile type and rotation
+ var nextPositions = [];
switch (tile.type) {
- case 'start':
- directions.push([0, 1]); // Down
- break;
case 'straightPipeV':
- directions.push([0, 1], [0, -1]); // Up and down
+ nextPositions.push([x, y - 1], [x, y + 1]); // Up and down
break;
case 'straightPipeH':
- directions.push([1, 0], [-1, 0]); // Left and right
+ nextPositions.push([x - 1, y], [x + 1, y]); // Left and right
break;
case 'cornerPipe':
switch (tile.rotation) {
case 'up':
- directions.push([1, 0], [0, -1]); // Right and up
+ // ┗
+ nextPositions.push([x, y - 1], [x + 1, y]); // Up and right
break;
case 'right':
- directions.push([1, 0], [0, 1]); // Right and down
+ // ┏
+ nextPositions.push([x + 1, y], [x, y + 1]); // Right and down
break;
case 'down':
- directions.push([-1, 0], [0, 1]); // Left and down
+ // ┓
+ nextPositions.push([x - 1, y], [x, y + 1]); // Left and down
break;
- default:
- // left
- directions.push([-1, 0], [0, -1]); // Left and up
+ case 'left':
+ // ┛
+ nextPositions.push([x - 1, y], [x, y - 1]); // Left and up
break;
}
break;
}
- log("Possible directions:", directions);
- // Try each direction
- for (var i = 0; i < directions.length; i++) {
- var dx = directions[i][0];
- var dy = directions[i][1];
- if (self.canReachEnd(x + dx, y + dy, visited)) {
+ // Try each possible next position
+ for (var i = 0; i < nextPositions.length; i++) {
+ var nextX = nextPositions[i][0];
+ var nextY = nextPositions[i][1];
+ if (self.canReachEnd(nextX, nextY, visited)) {
return true;
}
}
return false;
};
- self.startWaterFlow = function () {
- if (self.waterFlowing) {
- return;
- }
- self.waterFlowing = true;
- // Find start tile
- var startTile = null;
- for (var i = 0; i < self.gridSize; i++) {
- for (var j = 0; j < self.gridSize; j++) {
- if (self.grid[i][j].type === 'start') {
- startTile = self.grid[i][j];
- break;
- }
- }
- if (startTile) {
- break;
- }
- }
- if (startTile) {
- // Start water animation on the start tile
- startTile.flow = true;
- startTile.startFlowTicks = 0;
- // Start valve animation
- if (startTile.valve) {
- startTile.valve.rotationSpeed = 0.1;
- }
- }
- };
- return self;
+ return this;
};
/****
* Game Variables
****/
@@ -856,8 +927,9 @@
changeGameState(GAME_STATE.MENU);
}
function initMenuState() {
// Show level selection UI
+ console.log("Entering Menu State");
isPlaying = false;
levelText.visible = true;
levelText.text = "Level 1\nTap to Start";
}
@@ -869,8 +941,9 @@
levelText.text = "Level 1";
}
function initNewRoundState() {
// Reset puzzle manager for new round
+ console.log("Entering New Round State");
if (puzzleManager) {
puzzleManager.reset();
}
// After a short delay, transition to PLAYING state
@@ -885,8 +958,9 @@
// Clean up any new round state
}
function initPlayingState() {
// Start the gameplay
+ console.log("Entering Playing State");
isPlaying = true;
}
function handlePlayingLoop() {
// Update game logic
@@ -902,8 +976,9 @@
isPlaying = false;
}
function initScoreState() {
// Show score screen
+ console.log("Entering Score State");
levelText.visible = true;
levelText.text = "Level Complete!\nTap to continue";
}
function handleScoreLoop() {
@@ -916,8 +991,9 @@
levelText.visible = false;
}
function changeGameState(newState) {
// Clean up current state
+ console.log("Changing state from", currentState, "to", newState);
switch (currentState) {
case GAME_STATE.MENU:
cleanMenuState();
break;
straigth zenith view square light wooden pallet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
straigth zenith view square wooden pallet with big screws in each corner Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
simple yellow rating star. Modern video game style
tileSlide
Sound effect
levelWon
Sound effect
tileBlocked
Sound effect
fountain
Sound effect
waterInPipe
Sound effect
bgMusic
Music
logoBounce
Sound effect
levelStart
Sound effect
bgMusic2
Music
flowerPop
Sound effect
roundResult
Sound effect
gameWon
Sound effect
resetSound
Sound effect
birds
Sound effect
birds2
Sound effect
birds3
Sound effect