Code edit (1 edits merged)
Please save this source code
Code edit (23 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: Button is not defined' in or related to this line: 'var validateButton = new Button('Validate', {' Line Number: 271
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: columnFrom is not defined' in or related to this line: 'scoreTest = columnFrom;' Line Number: 89
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: cells is not defined' in or related to this line: 'mainGrid.cells[i][j].setLetter(cells[i][j].columnFrom, cells[i][j].lineFrom, wordGrid.cells[i][j].letter);' Line Number: 346
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: newLetter.toUpperCase is not a function' in or related to this line: 'self.texte.setText(newLetter.toUpperCase());' Line Number: 71
User prompt
Please fix the bug: 'ReferenceError: cells is not defined' in or related to this line: 'mainGrid.cells[i][j].setLetter(cells[i][j].column, cells[i][j].line, wordGrid.cells[i][j].letter);' Line Number: 342
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: wordGrid.cells[i][j].removeCell is not a function' in or related to this line: 'wordGrid.cells[i][j].removeCell(j);' Line Number: 342
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
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.cells[i][j] is undefined' in or related to this line: 'if (self.cells[i][j].letter !== '') {' Line Number: 192
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.cells[i][j] is undefined' in or related to this line: 'if (self.cells[i][j].letter !== '') {' Line Number: 192
User prompt
Please fix the bug: 'TypeError: self.cells[i][j] is undefined' in or related to this line: 'if (self.cells[i][j].letter !== '') {' Line Number: 192
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: word is not defined' in or related to this line: 'cellLetter.x = game.width / 2 + cellSize * (word.length / 2);' Line Number: 285
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ /**** * GAME DESCRIPTION: * Game Principle: * -There is a board filled with words, where the player selects letters from a partially filled grid. * -With these letters, the player forms a word that appears below the grid, then validates their word. * -If the word is among the words on the board, it is valid, and the player earns points. * -The score obtained is proportional to the length of the word. * -Above the grid, there are letters randomly taken from the word board. * -These letters move randomly within the grid to empty spaces. * -New letters are placed above the grid. * -If the word is not valid, the letters forming the word are returned to their original position in the grid. * -The letters above the grid move randomly within the grid to empty spaces. * -If there is no more space in the grid, the game is over. * Game Areas: * The screen is divided into 6 main zones in the following descending order: 1. Score area: displays the player's score. 2. Next letters area: displays the letters that will fall into the grid. 3. The grid: the letter grid. 4. Word area: displays the word formed by the player. 5. Validation area: button to validate the word or erase letters. 6. Options area (or advertisement). * Game Progression: * At the start of the game, the grid is almost full, containing 5 letters. * Above the grid, there are 4 letters randomly taken from the word board. * The player can choose a letter in the grid by clicking on it. * The chosen letter is added to the word area. * The player can validate the word or erase a letter by clicking on the letter in the word, which then returns to its place in the grid. * When the player thinks he has formed a word, he can validate it with the validate button located below the word area. * If the word is valid, the player earns points, and the score is updated. * The letters located above the grid move randomly within the grid to empty spaces. * New letters are added above the grid. * If the word is not valid, the letters forming the word are returned to their original position in the grid. * The letters located above the grid move randomly within the grid to empty spaces. * If there is no more space in the grid, the game is over. ****/ // Button class for creating buttons in the game var Button = Container.expand(function (text, options) { var self = Container.call(this); var buttonGraphics = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); self.width = options.width || 200; self.height = options.height || 100; self.fill = options.fill || 0x00FF00; self.text = new Text2(text, { size: options.text.size || 50, fill: options.text.fill || "#000000" }); self.text.anchor.set(0.5, 0.5); self.addChild(self.text); self.x = options.x || 0; self.y = options.y || 0; self.on('down', function () { if (options.onClick) { options.onClick(); } }); }); // Assets will be automatically created and loaded by the LK engine based on usage in the game code. // GridCell class for individual letters in the grid var GridCell = Container.expand(function (letter, assetName) { var self = Container.call(this); var cellGraphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.cellSize = cellGraphics.width; self.clickable = true; //Indique si la cellule est cliquable self.letter = letter; self.policeSize = policeSize; var text = new Text2(letter.toUpperCase(), { size: self.policeSize, fill: "#ffffff" }); self.texte = text; self.texte.anchor.set(0.5, 0.5); self.addChild(self.texte); self.column = 0; //From 0 to gridColumns - 1 self.line = 0; //From 0 to gridLines - 1 self.columnFrom = 0; //Used in case of moving back to the main grid of a letter self.lineFrom = 0; self.setLetter = function (newLetter) { self.letter = newLetter; self.texte.setText(newLetter.toUpperCase()); self.texte.x = -10; self.texte.y = -10; }; self.setColorToLetter = function (color) { self.texte.setStyle({ fill: color }); }; self.onClickCell = function () { //Fonction appelée lors du click sur la cellule if (!self.clickable || self.letter == '') { return; } self.isClicked = true; self.setColorToLetter("#FF0000"); }; 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, assetName) { var self = Container.call(this); self.gridColumns = columns; self.gridLines = lines; self.clickable = true; //Indique si la grille est cliquable 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++) { var cell = new GridCell('', assetName); cell.x = j * cell.cellSize; cell.y = i * cell.cellSize + cell.cellSize / 2; self.addChild(cell); self.cells[i][j] = cell; cell.column = j; cell.line = i; cell.on('down', function () { //Fonction appelée lors du click sur la cellule this.onClickCell(); }); cell.clickable = self.clickable; self.emptyCells.push(cell); } } }; //Fin de la fonction initializeGrid self.addCell = function (letter, assetName) { //Only when there is only one gridLine, add a cell to the grid with the given letter var cell = null; if (self.gridLines === 1) { cell = new GridCell(letter, assetName); cell.x = self.gridColumns * cell.cellSize; cell.y = cell.cellSize / 2; self.addChild(cell); self.cells[0][self.gridColumns] = cell; cell.column = self.gridColumns; cell.line = 0; cell.on('down', function () { //Fonction appelée lors du click sur la cellule this.onClickCell(); }); cell.clickable = self.clickable; if (letter === '') { self.emptyCells.push(cell); } self.gridColumns++; self.x -= cell.cellSize / 2; //Repositionnement de la grille } return cell; }; //Fin de la fonction addCell self.removeCell = function (index) { //Only when there is only one gridLine, remove a cell from the grid at the given index if (self.gridLines === 1 && index >= 0 && index < self.gridColumns) { var cell = self.cells[0][index]; self.removeChild(cell); self.cells[0].splice(index, 1); self.gridColumns--; //Decale les cellules suivantes vers la gauche de une cellule for (var i = index; i < self.gridColumns; i++) { self.cells[0][i].x -= self.cells[0][i].cellSize; self.cells[0][i].column = i; } self.x += cell.cellSize / 2; //Repositionnement de la grille } }; //Fin de la fonction removeCell self.setLetter = function (column, line, letter) { // Set a letter in the grid at (column, line) if (column >= 0 && column < self.gridColumns && line >= 0 && line < self.gridLines) { self.cells[line][column].setLetter(letter); //Retrait de la cellule de la liste des cellules vides if (self.emptyCells.includes(self.cells[line][column]) && letter !== '') { self.emptyCells.splice(self.emptyCells.indexOf(self.cells[line][column]), 1); } else if (!self.emptyCells.includes(self.cells[line][column]) && letter === '') { self.emptyCells.push(self.cells[line][column]); } } }; //Fin de la fonction setLetter 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 === '') { return false; } } } return true; }; //Fin de la fonction isFull self.isEmpty = function () { for (var i = 0; i < self.gridLines; i++) { for (var j = 0; j < self.gridColumns; j++) { if (self.cells[i][j].letter !== '') { return false; } } } return true; }; //Fin de la fonction isEmpty 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); } } }; //Fin de la fonction colorAllCells }); /**** * Initialize Game ****/ //Fin de la classe LettersGrid var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var wordsMainListTest = ["AARDVARK", "ALBATROSS", "ALLIGATOR", "ALPACA", "ANT"]; //The real main list is at the end var scoreTest = 0; // Define scoreTest variable var ScoreZone = { x: 0, y: 0, width: game.width, height: 200 }; var OptionsZone = { x: 0, y: game.height - 200, width: game.width, height: 200 }; var scoreTestText = new Text2('0', { size: 70, fill: "#ffff00", anchorX: 0.5, anchorY: 0 }); LK.gui.top.addChild(scoreTestText); var policeSize = 128; var lettersGrid = game.addChild(new LettersGrid(3, 1, 'cell')); lettersGrid.clickable = false; lettersGrid.initializeGrid(); lettersGrid.x = (game.width - lettersGrid.width) / 2 + lettersGrid.height / 2; lettersGrid.y = ScoreZone.height + lettersGrid.height / 2; var mainGrid = game.addChild(new LettersGrid(6, 6, 'cell')); mainGrid.initializeGrid(); mainGrid.x = (game.width - mainGrid.width) / 2 + lettersGrid.height / 2; mainGrid.y = ScoreZone.height + 2 * lettersGrid.height; var wordGrid = game.addChild(new LettersGrid(0, 1, 'cellWord')); wordGrid.initializeGrid(); wordGrid.x = (game.width - wordGrid.width) / 2 - wordGrid.height / 2 + lettersGrid.height / 2; wordGrid.y = ScoreZone.height + lettersGrid.height + mainGrid.height + 2 * lettersGrid.height; var validateButton = new Button('Validate', { x: (game.width - 200) / 2, y: ScoreZone.height + lettersGrid.height + mainGrid.height + 2 * lettersGrid.height + wordGrid.height, width: 200, height: 100, fill: "#00FF00", text: { size: 50, fill: "#000000" } }); game.addChild(validateButton); var lettersToAdd = []; //File d'attente des lettres à ajouter dans la lettersGrid var isGameStarted = false; var isMGRefillrequired = true; //Indique si le remplissage de la grille principale est nécessaire var isWordValid = false; //Indique si le mot formé est valide /**** * Functions ****/ function updateScoreTest(nouveauScore) { scoreTestText.setText(nouveauScore); } //fin updateScoreTest //Fonction pickAndShakeSingleWord : permet de choisir un mot dans la liste des mots et de le mélanger function pickAndShakeSingleWord() { var randomIndex = Math.floor(Math.random() * wordsMainListTest.length); var word = wordsMainListTest[randomIndex]; var wordShuffled = wordShuffled = word.split('').sort(function () { return 0.5 - Math.random(); }).join(''); return wordShuffled; } //Fin de la fonction pickAndShakeSingleWord //Fonction pickAndShakeWords : permet de choisir plusieurs mots dans la liste des mots et de les mélanger function pickAndShakeWords(numberOfWords) { var wordsShuffeled = []; for (var i = 0; i < numberOfWords; i++) { var shuffledWord = pickAndShakeSingleWord(); wordsShuffeled.push(shuffledWord); } return wordsShuffeled; } //Fin de la fonction pickAndShakeWords //Fonction stackLettersFromWords : permet de stocker les lettres de plusieurs mots dans la file d'attente lettersToAdd function stackLettersFromWords(words) { for (var i = 0; i < words.length; i++) { var word = words[i]; var letters = word.split(''); for (var j = 0; j < letters.length; j++) { lettersToAdd.push(letters[j]); } } } //Fin de la fonction stackLettersFromWords //Fonction transfertLettersGridToMainGrid : permet de transférer les lettres de la liste lettersToAdd dans la grille principale function transfertLettersGridToMainGrid() { for (var i = 0; i < lettersGrid.gridColumns && lettersToAdd.length > 0; i++) { mainGrid.addRandomLetter(lettersToAdd[0]); lettersToAdd.splice(0, 1); } } //Fin de la fonction transfertLettersGridToMainGrid //Fonction addCellLetterToWord : permet d'ajouter une cellule à la liste des lettres formant le mot situé sous la grille function addCellLetterToWord(letter) { var cellLetter = wordGrid.addCell(letter, 'cellWord'); return cellLetter; } //Fin de la fonction addCellLetterToWord //Fonction validateWord : permet de valider le mot formé par le joueur function validateWord() { var word = ''; for (var i = 0; i < wordGrid.gridColumns; i++) { word += wordGrid.cells[0][i].letter; } if (wordsMainList.includes(word)) { scoreTest += word.length; isWordValid = true; } else { isWordValid = false; } wordGrid.colorAllCells(isWordValid ? "#00FF00" : "#FF0000"); return isWordValid; } //Fin de la fonction validateWord game.update = function () { updateScoreTest(scoreTest); //Recherche de la lettre cliquée dans la mainGrid et ajout de la lettre à la liste des lettres formant le mot for (var i = 0; i < mainGrid.gridLines; i++) { for (var j = 0; j < mainGrid.gridColumns; j++) { if (mainGrid.cells[i][j].isClicked) { var newCell = addCellLetterToWord(mainGrid.cells[i][j].letter); if (newCell) { newCell.columnFrom = j; newCell.lineFrom = i; } mainGrid.cells[i][j].isClicked = false; mainGrid.cells[i][j].setLetter(''); mainGrid.emptyCells.push(mainGrid.cells[i][j]); } } } //Recherche de la lettre cliquée dans la wordGrid et retour de la lettre à la mainGrid var indexCellToRemove = -1; for (var j = 0; j < wordGrid.gridColumns; j++) { if (wordGrid.cells[0][j].isClicked) { //Retour de la lettre à la grille principale var columnBack = wordGrid.cells[0][j].columnFrom; var lineBack = wordGrid.cells[0][j].lineFrom; mainGrid.setLetter(columnBack, lineBack, wordGrid.cells[0][j].letter); //Retrait de la lettre cliquée du mot wordGrid.cells[0][j].setLetter(''); wordGrid.cells[0][j].isClicked = false; indexCellToRemove = j; } } if (indexCellToRemove >= 0) { wordGrid.removeCell(indexCellToRemove); indexCellToRemove = -1; } //Autres actions à effectuer toutes les secondes sans urgence if (LK.ticks % 60 == 0) { //Chargement initiale de la grille principale si nécessaire (vide): //un mot est choisi au hasard dans la liste principale, //il est mélangé et les lettres sont directement ajoutées à la grille principale avec la fonction addRandomLetter if (mainGrid.isEmpty() && !isGameStarted) { var wordsToBegin = pickAndShakeWords(1); if (wordsToBegin.length > 0) { scoreTest = "Fist word: " + wordsToBegin; for (var i = 0; i < wordsToBegin[0].length; i++) { mainGrid.addRandomLetter(wordsToBegin[0][i]); } isGameStarted = true; isMGRefillrequired = false; } } //Remplissage de la file d'attente des lettres à ajouter dans la lettersGrid //Si le nombre de lettres est inférieur à la taille de la lettersGrid, //on prendre un mot au hasard dans la liste principale, on le mélange et on ajoute les lettres à la file d'attente if (lettersToAdd.length < lettersGrid.gridColumns) { var wordsToBegin = pickAndShakeWords(1); if (wordsToBegin.length > 0) { stackLettersFromWords(wordsToBegin); } } //Remplissage lettersGrid si elle est vide, //on retire les premières lettres de la liste des lettres à ajouter, et on les ajoute à la grille principale //sachant que le nombre de lettres à ajouter est égal à la taille de la lettersGrid if (lettersToAdd.length > 0 && lettersGrid.isEmpty()) { for (var i = 0; i < lettersGrid.gridColumns && lettersToAdd.length > 0; i++) { lettersGrid.addRandomLetter(lettersToAdd[0]); lettersToAdd.splice(0, 1); } } //Rechargement de la grille principale si nécessaire if (isMGRefillrequired) { transfertLettersGridToMainGrid(); isMGRefillrequired = false; } } }; //Fin de la fonction update //Liste des mots en majuscule var wordsMainList = ["AARDVARK", "ALBATROSS", "ALLIGATOR", "ALPACA", "ANT", "ANTEATER", "ANTELOPE", "APE", "ARMADILLO", "BABOON", "BADGER", "BAT", "BEAR", "BEAVER", "BEE", "BEETLE", "BISON", "BOAR", "BUFFALO", "BUTTERFLY", "CAMEL", "CANARY", "CAPYBARA", "CARIBOU", "CARP", "CAT", "CATERPILLAR", "CHEETAH", "CHICKEN", "CHIMPANZEE", "CHINCHILLA", "CHOUGH", "CLAM", "COBRA", "COCKROACH", "COD", "CORMORANT", "COYOTE", "CRAB", "CRANE", "CROCODILE", "CROW", "CURLEW", "DEER", "DINOSAUR", "DOG", "DOGFISH", "DOLPHIN", "DONKEY", "DOTTEREL", "DOVE", "DRAGONFLY", "DUCK", "DUGONG", "DUNLIN", "EAGLE", "ECHIDNA", "EEL", "ELAND", "ELEPHANT", "ELK", "EMU", "FALCON", "FERRET", "FINCH", "FISH", "FLAMINGO", "FLY", "FOX", "FROG", "GAUR", "GAZELLE", "GERBIL", "GIRAFFE", "GNAT", "GNU", "GOAT", "GOLDFINCH", "GOLDFISH", "GOOSE", "GORILLA", "GOSHAWK", "GRASSHOPPER", "GROUSE", "GUANACO", "GULL", "HAMSTER", "HARE", "HAWK", "HEDGEHOG", "HERON", "HERRING", "HIPPOPOTAMUS", "HORNET", "HORSE", "HUMMINGBIRD", "HYENA", "IBEX", "IBIS", "JACKAL", "JAGUAR", "JAY", "JELLYFISH", "KANGAROO", "KINGFISHER", "KOALA", "KOOKABURA", "KUDU", "LAPWING", "LARK", "LEMUR", "LEOPARD", "LION", "LLAMA", "LOBSTER", "LOCUST", "LORIS", "LOUSE", "LYREBIRD", "MAGPIE", "MALLARD", "MANATEE", "MANDRILL", "MANTIS", "MARTEN", "MEERKAT", "MINK", "MOLE", "MONKEY", "MOOSE", "MOSQUITO", "MOUSE", "MULE", "NARWHAL", "NEWT", "NIGHTINGALE", "OCTOPUS", "OKAPI", "OPOSSUM", "ORYX", "OSTRICH", "OTTER", "OWL", "OYSTER", "PANTHER", "PARROT", "PARTRIDGE", "PEAFOWL", "PELICAN", "PENGUIN", "PHEASANT", "PIG", "PIGEON", "POLAR BEAR", "PORCUPINE", "PORPOISE", "QUAIL", "QUELEA", "QUETZAL", "RABBIT", "RACCOON", "RAIL", "RAM", "RAT", "RAVEN", "REINDEER", "RHINOCEROS", "ROOK", "SALAMANDER", "SALMON", "SANDPIPER", "SARDINE", "SCORPION", "SEAHORSE", "SEAL", "SHARK", "SHEEP", "SHREW", "SKUNK", "SNAIL", "SNAKE", "SPARROW", "SPIDER", "SPOONBILL", "SQUID", "SQUIRREL", "STARLING", "STINGRAY", "STINKBUG", "STORK", "SWALLOW", "SWAN", "TAPIR", "TARSIER", "TERMITE", "TIGER", "TERN", "THRUSH", "TIGER", "TOAD", "TOUCAN", "TROUT", "TURKEY", "TURTLE", "VIPER", "VULTURE", "WALLABY", "WALRUS", "WASP", "WEASEL", "WHALE", "WILDCAT", "WOLF", "WOMBAT", "WOODCOCK", "WOODPECKER", "WORM", "WREN", "YAK", "ZEBRA"];
===================================================================
--- original.js
+++ change.js
@@ -293,8 +293,9 @@
size: 50,
fill: "#000000"
}
});
+game.addChild(validateButton);
var lettersToAdd = []; //File d'attente des lettres à ajouter dans la lettersGrid
var isGameStarted = false;
var isMGRefillrequired = true; //Indique si le remplissage de la grille principale est nécessaire
var isWordValid = false; //Indique si le mot formé est valide
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.