Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: emptyCells is not defined' in or related to this line: 'if (emptyCells.includes(self.cells[i][j])) {' Line Number: 128
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Initial prompt
Cool Words
===================================================================
--- original.js
+++ change.js
@@ -46,27 +46,29 @@
});
self.letter = letter;
var text = new Text2(letter.toUpperCase(), {
size: 128,
- fill: "#ffffff",
- anchorX: 0.5,
- anchorY: 0.5
+ fill: "#ffffff"
});
text.anchor.set(0.5, 0.5);
self.addChild(text);
+ self.column = 0;
+ self.line = 0;
self.setLetter = function (newLetter) {
self.letter = newLetter;
text.setText(newLetter.toUpperCase());
- text.x = 0;
- text.y = 0;
+ text.x = -10;
+ text.y = -10;
};
self.setColorToLetter = function (color) {
text.fill = color;
};
self.on('click', function () {
//Fonction appelée lors du click sur la cellule
self.setColorToLetter("#0000FF");
+ self.isClicked = true;
});
+ self.isClicked = false; //Indique si la cellule a été cliquée
});
// LettersGrid class for managing the grid of letters, same as WordGrid but with control of number of columns and lines
var LettersGrid = Container.expand(function (columns, lines) {
var self = Container.call(this);
@@ -74,8 +76,9 @@
self.gridColumns = columns;
self.gridLines = lines;
self.cellSize = 1280 / self.gridColumns;
self.cells = [];
+ self.emptyCells = []; //Liste des cellules vides
self.initializeGrid = function () {
for (var i = 0; i < self.gridLines; i++) {
self.cells[i] = [];
for (var j = 0; j < self.gridColumns; j++) {
@@ -83,8 +86,11 @@
cell.x = j * self.cellSize + self.cellSize / 2;
cell.y = i * self.cellSize + self.cellSize / 2;
self.addChild(cell);
self.cells[i][j] = cell;
+ cell.column = j;
+ cell.line = i;
+ self.emptyCells.push(cell);
}
}
};
self.addLetter = function (letter) {
@@ -93,28 +99,57 @@
for (var j = 0; j < self.gridColumns && !added; j++) {
if (self.cells[i][j].letter === '') {
self.cells[i][j].setLetter(letter);
added = true;
- //Gestion du click sur la cellule
- self.cells[i][j].on('click', function () {
- self.cells[i][j].setColorToLetter("#0000FF");
- });
+ //Retrait de la cellule de la liste des cellules vides
+ if (self.emptyCells.includes(self.cells[i][j])) {
+ self.emptyCells.splice(self.emptyCells.indexOf(self.cells[i][j]), 1);
+ }
}
}
}
return added;
- };
+ }; //Fin de la fonction addLetter
self.addRandomPlace = function (letter) {
// Add a letter in a random empty cell
var added = false;
var i = Math.floor(Math.random() * self.gridLines);
var j = Math.floor(Math.random() * self.gridColumns);
if (self.cells[i][j].letter === '') {
self.cells[i][j].setLetter(letter);
added = true;
+ //Retrait de la cellule de la liste des cellules vides
+ if (self.emptyCells.includes(self.cells[i][j])) {
+ self.emptyCells.splice(self.emptyCells.indexOf(self.cells[i][j]), 1);
+ }
}
return added;
- };
+ }; //Fin de la fonction addRandomPlace
+ self.addRandomLetter = function (letter) {
+ // Add a letter in a random empty cell using emptyCells list
+ var added = false;
+ if (self.emptyCells.length > 0) {
+ var randomIndex = Math.floor(Math.random() * self.emptyCells.length);
+ var cell = self.emptyCells[randomIndex];
+ cell.setLetter(letter);
+ added = true;
+ //Retrait de la cellule de la liste des cellules vides
+ if (self.emptyCells.includes(cell)) {
+ self.emptyCells.splice(self.emptyCells.indexOf(cell), 1);
+ }
+ }
+ return added;
+ }; //Fin de la fonction addRandomLetter
+ self.removeLetter = function (column, line) {
+ // Remove a letter from the grid at (column, line)
+ if (column >= 0 && column < self.gridColumns && line >= 0 && line < self.gridLines) {
+ self.cells[line][column].setLetter('');
+ //Ajout de la cellule à la liste des cellules vides
+ if (!self.emptyCells.includes(self.cells[line][column])) {
+ self.emptyCells.push(self.cells[line][column]);
+ }
+ }
+ }; //Fin de la fonction removeLetter
self.isFull = function () {
for (var i = 0; i < self.gridLines; i++) {
for (var j = 0; j < self.gridColumns; j++) {
if (self.cells[i][j].letter === '') {
@@ -123,8 +158,15 @@
}
}
return true;
};
+ self.colorAllCells = function (color) {
+ for (var i = 0; i < self.gridLines; i++) {
+ for (var j = 0; j < self.gridColumns; j++) {
+ self.cells[i][j].setColorToLetter(color);
+ }
+ }
+ };
});
/****
* Initialize Game
@@ -215,8 +257,9 @@
return;
}
currentLetterIndex = (currentLetterIndex + 1) % lettersToAdd.length;
if (wordGrid.isFull()) {
+ wordGrid.colorAllCells("#FF0000");
LK.showGameOver();
}
}
};
An empty cell.
Drapeau national des USA en fond d'un patchwork des États américains.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Une jeton de scrabble sans lettre.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Un bouton arrondi suggérant une validation mais sans texte écrit dessus.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A round button with a cyan interrogation mark.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A round cyan button with a yellow lamp bulb.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Planetes.
Remove the white square and the red lines.
A patchwork of european countries with the european unio flag in back ground.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A yellow coin wher we can see '+10' written on it.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A red coin wher we can see '-10' written on it... Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Patchwork of heads of plenty animals.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
The periodic table of the elements.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Patchwork de mots sur un fond cyan.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Patchwork of scene extracted from video games.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
It is written "COOL QUIZZ".
A cyan circle button with a home silhouette in the center. The button means "go back to start window". Avoid white color.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.