Code edit (12 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: word is not defined' in or related to this line: 'scoreTest = "firtWord: " + word;' Line Number: 922
Code edit (1 edits merged)
Please save this source code
Code edit (15 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: wordGgrid is not defined' in or related to this line: 'var letter = clueWord[wordGgrid.gridColumns];' Line Number: 633
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: wordOfGrid is undefined' in or related to this line: 'if (notEnoughtMoneyForDrop || clueWord == '' && !wordGrid.isEmpty() || clueWord.length < wordOfGrid.length) {' Line Number: 903
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: wordGrid.words[0] is undefined' in or related to this line: 'return true;' Line Number: 267
Code edit (1 edits merged)
Please save this source code
Code edit (20 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: clueButtonLetter is not defined' in or related to this line: 'scrollCostCoins(clueButtonLetter.x, clueButtonLetter.y, 1, 10);' Line Number: 549
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: 'Timeout.tick error: options is undefined' in or related to this line: 'var imageToScrollRescale = {' Line Number: 775
Code edit (15 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: options is undefined' in or related to this line: 'var imageToScrollRescale = {' Line Number: 775
Code edit (1 edits merged)
Please save this source code
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: options is undefined' in or related to this line: 'var imageToScrollRescale = {' Line Number: 748
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: createRewardImages is not defined' in or related to this line: 'createRewardImages('RewardsCoin', tableauFrom);' Line Number: 469
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: imagesToScrollRescale[i] is undefined' in or related to this line: 'if (imagesToScrollRescale[i].isDestroyedOnEnd) {' Line Number: 725
/**** * Classes ****/ var Button = Container.expand(function (text, options) { var self = Container.call(this); var buttonGraphics = self.attachAsset(options.assetName || '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 && options.text.size || 50, fill: options.text && 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.wordFrom = ''; //Mot d'origine de la lettre self.letter = letter; self.policeSize = policeSize; var text = new Text2(letter.toUpperCase(), { size: self.policeSize, fill: "#000000" }); 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.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; var oneCell = new GridCell('', assetName); //Taille de reference self.width = oneCell.cellSize * self.gridColumns; self.height = oneCell.cellSize + oneCell.cellSize * (self.gridLines - 1); self.clickable = true; //Indique si la grille est cliquable self.cells = []; self.emptyCells = []; //Liste des cellules vides self.words = []; //Liste des mots actuellement dans la grille 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.resetGrid = function () { //Réinitialise la grille : remove all cells and repositionnement de la grille for (var i = 0; i < self.gridLines; i++) { for (var j = 0; j < self.gridColumns; j++) { self.removeChild(self.cells[i][j]); } } self.cells = []; self.emptyCells = []; self.gridColumns = 0; self.gridLines = 0; }; //Fin de la fonction resetGrid 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.findNclickCell = function (letter) { //Trouve et clique sur la première cellule contenant la lettre letter for (var i = 0; i < self.gridLines; i++) { for (var j = 0; j < self.gridColumns; j++) { if (self.cells[i][j].letter === letter) { self.cells[i][j].onClickCell(); return; } } } }; //Fin de la fonction findNclickCell self.addWord = function (word) { // Add a word in the list of words self.words.push(word); }; //Fin de la fonction addWord self.removeWord = function (word) { // Remove a word from the list of words if (self.words.includes(word)) { self.words.splice(self.words.indexOf(word), 1); } }; //Fin de la fonction removeWord 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.colorWordCells = function (word, color) { //Colorie les cellules du mot word en couleur color for (var j = 0; j < self.gridLines; j++) { for (var k = 0; k < self.gridColumns; k++) { if (word.includes(self.cells[j][k].letter)) { self.cells[j][k].setColorToLetter(color); word = word.replace(self.cells[j][k].letter, ''); } } } }; //Fin de la fonction colorWordCells 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 clueWord = ''; // Button class for creating buttons in the game /**** * GAME DESCRIPTION: * Game Principle: * -There is a board filled with letters, 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 main list, it is valid, and the player earns points. * -The score obtained is proportional to the length of the word. * -These letters move randomly within the grid to empty spaces. * -If the word is not valid, the letters forming the word are returned to their original position in the grid. * -A new word is selected from the main list, shuffled and randomly dispatched in the empty cells. * -If there is no more space in the grid, the game is over. * Game Areas: * The screen is divided into 5 main zones in the following descending order: 1. Score area: displays the player's score. 2. The grid: the letter grid (main grid). 3. Word area: displays the word formed by the player (word grid). 4. Validation area: button to validate the word or erase letters. 5. Options area (or advertisement). * Game Progression: * At the beginning of the game, the grid is almost empty, containing one shuffled word. * 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. * If the word is not valid, the letters forming the word are returned to their original position in the grid. * A new word appears randomly within the grid to empty spaces. * If there is no more space in the grid, the game is over. ****/ var backGroundsList = ["BackGroundPlanetesNSatellites", "BackGroundUSAStates", "BackGroundEuropeanCapitales"]; //Liste des assets de fond var mainListsList = [planetesNsatellites, usaStates, europeanCapitales]; //Liste des listes de mots principales //var wordsMainListTest = ["AARDVARK", "ALBATROSS", "ALLIGATOR", "ALPACA", "ANT"]; //The real main list is at the end var usaStates = ["ALABAMA", "ALASKA", "ARIZONA", "ARKANSAS", "CALIFORNIA", "COLORADO", "CONNECTICUT", "DELAWARE", "FLORIDA", "GEORGIA", "HAWAII", "IDAHO", "ILLINOIS", "INDIANA", "IOWA", "KANSAS", "KENTUCKY", "LOUISIANA", "MAINE", "MARYLAND", "MASSACHUSETTS", "MICHIGAN", "MINNESOTA", "MISSISSIPPI", "MISSOURI", "MONTANA", "NEBRASKA", "NEVADA", "NEW-HAMPSHIRE", "NEW-JERSEY", "NEW-MEXICO", "NEW-YORK", "NORTH-CAROLINA", "NORTH-DAKOTA", "OHIO", "OKLAHOMA", "OREGON", "PENNSYLVANIA", "RHODE-ISLAND", "SOUTH-CAROLINA", "SOUTH-DAKOTA", "TENNESSEE", "TEXAS", "UTAH", "VERMONT", "VIRGINIA", "WASHINGTON", "WEST-VIRGINIA", "WISCONSIN", "WYOMING"]; var europeanCapitales = ["AMSTERDAM", "ANDORRA-LA-VELLA", "ANKARA", "ATHENS", "BELGRADE", "BERLIN", "BERN", "BRATISLAVA", "BRUSSELS", "BUCHAREST", "BUDAPEST", "CHISINAU", "COPENHAGEN", "DUBLIN", "HELSINKI", "KIEV", "LISBON", "LJUBLJANA", "LONDON", "LUXEMBOURG", "MADRID", "MINSK", "MONACO", "MOSCOW", "NICOSIA", "OSLO", "PARIS", "PODGORICA", "PRAGUE", "REYKJAVIK", "RIGA", "ROME", "SAN-MARINO", "SARAJEVO", "SKOPJE", "SOFIA", "STOCKHOLM", "TALLINN", "TBILISI", "TIRANA", "VADUZ", "VALLETTA", "VIENNA", "VILNIUS", "WARSAW", "ZAGREB"]; //var planetesNsatellites = ["SUN", "MERCURY", "VENUS", "EARTH", "MOON", "MARS", "PHOBOS", "DEIMOS", "JUPITER", "IO", "EUROPA", "GANYMEDE", "CALLISTO", "SATURN", "TITAN", "MIMAS", "ENCELADUS", "TETHYS", "DIONE", "RHEA", "HYPERION", "LAPETUS", "PHOEBE", "URANUS", "PUCK", "MIRANDA", "ARIEL", "UMBRIEL", "TITANIA", "OBERON", "NEPTUNE", "TRITON", "PROTEUS", "NEREID", "PLUTO", "CHARON"]; var planetesNsatellites = ["SUN", "MERCURY", "VENUS", "EARTH", "MOON", "MARS"]; var scoreTest = 0; // Define scoreTest variable var score = 0; /**** * Game zones and backgrounds ****/ var ScoreZone = { x: 0, y: 0, width: game.width, height: 200 * game.height / 2732 }; var MainZone = { x: 0, y: ScoreZone.height, width: game.width, height: game.height - 2 * ScoreZone.height }; var OptionsZone = { x: 0, y: game.height - ScoreZone.height, width: game.width, height: 200 * game.height / 2732 }; var backGroundScoreZone = LK.getAsset('ScoreZoneBackGround', { x: ScoreZone.x, y: ScoreZone.y, width: ScoreZone.width, height: ScoreZone.height }); game.addChild(backGroundScoreZone); var backGroundOptionsZone = LK.getAsset('OptionsZoneBackGround', { x: OptionsZone.x, y: OptionsZone.y, width: OptionsZone.width, height: OptionsZone.height }); game.addChild(backGroundOptionsZone); /**** * Score ****/ var scoreTestText = new Text2('0', { size: 30, fill: "#ffff00", anchorX: 0.5, anchorY: 0 }); LK.gui.topLeft.addChild(scoreTestText); var scoreText = new Text2('0', { size: 100, fill: "#00ff00", anchorX: 0.5, anchorY: 0 }); LK.gui.top.addChild(scoreText); /**** * Main zone foreground ****/ var policeSize = 128; var mainGrid = new LettersGrid(6, 6, 'cell'); var wordGrid = null; var isGameStarted = false; var isMGRefillrequired = false; //Indique si le remplissage de la grille principale est nécessaire var isWordValid = false; //Indique si le mot formé est valide var validateButton = null; var clueLevel = 0; //Niveau d'indice var clueButton = null; var clueButtonWord = null; var clueButtonDrop = null; var animatingImageOn = false; //Drapeau indiquant qu'une image est a scrollscaller var imagesToScrollRescale = []; //Liste des images a scrollscaller //initGameThema(planetesNsatellites, 'BackGroundPlanetesNSatellites'); //initGameThema(usaStates, 'BackGroundUSAStates'); initGameThema(europeanCapitales, 'BackGroundEuropeanCapitales'); /**** * Functions ****/ //Fonction initGameThema : permet d'initialiser le thème du jeu (liste des mots et image de fond) function initGameThema(mainList, backGround) { isGameStarted = false; isMGRefillrequired = false; isWordValid = false; clueLevel = 0; setMainWordsList(mainList); setBackGroundImage(backGround); mainGrid.initializeGrid(); mainGrid.x = game.width / 2 - mainGrid.width / 2 + mainGrid.width / (mainGrid.gridColumns + 2); mainGrid.y = MainZone.height / 6; game.addChild(mainGrid); initWordGrid(); setValidateButton('buttonValidate'); setClueButton('buttonClue'); setClueButtonWord('ButtonClue1'); setClueButtonDrop('ButtonClue2'); } //Fin de la fonction initGameThema function updateScoreTest(nouveauScore) { scoreTestText.setText(nouveauScore); } //fin updateScoreTest function updateScore(nouveauScore) { scoreText.setText(nouveauScore); } //fin updateScore //Fonction setMainWordsList : permet de définir la liste principale des mots function setMainWordsList(liste) { wordsMainList = liste; } //Fin de la fonction setMainWordsList //Fonction setBackGroundImage : permet de définir l'image de fond du jeu function setBackGroundImage(image) { backGroundImage = LK.getAsset(image, { x: MainZone.x, y: MainZone.y, width: MainZone.width, height: MainZone.height }); game.addChild(backGroundImage); } //Fin de la fonction setBackGroundImage //Fonction onClickValidateButton : permet de valider le mot formé par le joueur function onClickValidateButton() { if (validateWord(mainGrid.words)) { //On vide la grille des lettres formant le mot final apres x secondes LK.setTimeout(function () { createRewardImage(wordGrid.x, wordGrid.y); wordGrid.resetGrid(); initWordGrid(); }, 1000); if (mainGrid.isEmpty()) { score += 100; //Bonus for emptying the main grid isMGRefillrequired = true; } } else { //Le mot n'est pas valide, on remet les lettres dans la grille principale LK.setTimeout(function () { for (var i = 0; i < wordGrid.gridColumns; i++) { mainGrid.setLetter(wordGrid.cells[0][i].columnFrom, wordGrid.cells[0][i].lineFrom, wordGrid.cells[0][i].letter); } isMGRefillrequired = true; wordGrid.resetGrid(); initWordGrid(); }, 1000); } clueLevel = 0; //On remet le niveau d'indice à 0 } //Fin de la fonction onClickValidateButton //Fonction setValidateButton : permet de définir le bouton de validation function setValidateButton(asset) { validateButton = new Button('', { assetName: asset, x: game.width / 2 + 50, y: wordGrid.y + wordGrid.height + 350, width: 300, height: 300, fill: "#00FF00", text: { size: 50, fill: "#000000" }, onClick: onClickValidateButton }); game.addChild(validateButton); } //Fin de la fonction setValidateButton //Fonction onClickClueButton : permet de donner un indice au joueur function onClickClueButton() { if (!wordGrid.isEmpty()) { //Si le joueur a déjà commencé à former un mot, on ne donne pas d'indice return; } if (mainGrid.words.length >= 1) { var randomIndex = Math.floor(Math.random() * mainGrid.words.length); var word = mainGrid.words[randomIndex]; var firstLetter = word[0]; var line = -1; var col = -1; for (var i = 0; i < mainGrid.gridLines; i++) { //On colorie la première lettre du mot pendant 2 secondes for (var j = 0; j < mainGrid.gridColumns; j++) { if (mainGrid.cells[i][j].letter == firstLetter) { mainGrid.cells[i][j].setColorToLetter("#FF5500"); line = i; col = j; break; } } } LK.setTimeout(function () { if (mainGrid.cells[line] && mainGrid.cells[line][col]) { mainGrid.cells[line][col].setColorToLetter("#000000"); } }, 2000); } } //Fin de la fonction onClickClueButton //Fonction setClueButton : permet de définir le bouton d'indice function setClueButton(asset) { clueButton = new Button('', { assetName: asset, x: game.width / 2 - 350, y: 150, // Set a default y position width: 200, height: 200, fill: "#00FF00", text: { size: 50, fill: "#000000" }, onClick: onClickClueButton }); clueButton.x = game.width - clueButton.width; // Adjust x position after initialization clueButton.y = mainGrid.y + clueButton.height; // Adjust y position after initialization game.addChild(clueButton); } //Fin de la fonction setClueButton //Fonction onClickClueButtonWord : permet de donner un indice au joueur (change la couleur des lettres d'un des mots au hasard) function onClickClueButtonWord() { if (!wordGrid.isEmpty()) { //Si le joueur a déjà commencé à former un mot, on ne donne pas d'indice return; } //On change la couleur des lettres d'un des mots au hasard de mainGrid.words if (mainGrid.words.length >= 1) { var randomIndex = Math.floor(Math.random() * mainGrid.words.length); var word = mainGrid.words[randomIndex]; mainGrid.colorWordCells(word, "#FF5500"); LK.setTimeout(function () { mainGrid.colorWordCells(word, "#000000"); }, 3000); } } //Fin de la fonction onClickClueButtonWord //Fonction setClueButtonWord : permet de définir le bouton d'indice focus word function setClueButtonWord(asset) { clueButtonWord = new Button('', { assetName: asset, x: game.width / 2 - 350, y: mainGrid.y, // Set a default y position width: 200, height: 200, fill: "#00FF00", text: { size: 50, fill: "#000000" }, onClick: onClickClueButtonWord }); clueButtonWord.x = game.width - clueButtonWord.width; // Adjust x position after initialization clueButtonWord.y = mainGrid.y + 2 * clueButtonWord.height; // Adjust y position after initialization game.addChild(clueButtonWord); } //Fin de la fonction setClueButtonWord //Fonction onClickClueButtonDrop : permet de donner un indice au joueur (drop letter) function onClickClueButtonDrop() { if (!wordGrid.isEmpty() && clueLevel == 0) { //Si le joueur a déjà commencé à former un mot, on ne donne pas d'indice return; } switch (clueLevel) { case 0: //On prend un mot au hasard dans la liste principale et on clique sur la première lettre (isClicked = true) if (mainGrid.words.length > 0) { var randomIndex = Math.floor(Math.random() * mainGrid.words.length); var word = mainGrid.words[randomIndex]; clueWord = word; //On garde le mot pour le prochain indice var firstLetter = word[0]; var secondLetter = word[1]; mainGrid.findNclickCell(firstLetter); LK.setTimeout(function () { mainGrid.findNclickCell(secondLetter); }, 100); } break; default: //On descend les lettres d'un mot if (clueWord != '') { var letter = clueWord[clueLevel + 1]; mainGrid.findNclickCell(letter); } break; } //Fin du switch clueLevel++; } //Fin de la fonction onClickClueButtonDrop //Fonction setClueButtonDrop : permet de définir le bouton d'indice drop letter function setClueButtonDrop(asset) { clueButtonDrop = new Button('', { assetName: asset, x: game.width / 2 - 350, y: mainGrid.y, // Set a default y position width: 200, height: 200, fill: "#00FF00", text: { size: 50, fill: "#000000" }, onClick: onClickClueButtonDrop }); clueButtonDrop.x = game.width - clueButtonDrop.width; // Adjust x position after initialization clueButtonDrop.y = mainGrid.y + 3 * clueButtonDrop.height; // Adjust y position after initialization game.addChild(clueButtonDrop); } //Fin de la fonction setClueButtonDrop //Fonction initWordGrid : permet d'initialiser la grille des lettres formant le mot function initWordGrid() { //Initialise la grille des lettres formant le mot wordGrid = game.addChild(new LettersGrid(0, 1, 'cellWord')); wordGrid.initializeGrid(); wordGrid.x = game.width / 2 + 100; wordGrid.y = ScoreZone.height + mainGrid.height + 300; } //Fin de la fonction initWordGrid //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() * wordsMainList.length); var word = wordsMainList[randomIndex]; if (!word) { return { word: '', wordShuffled: '' }; } var wordShuffled = word.split('').sort(function () { return 0.5 - Math.random(); }).join(''); wordsMainList.splice(randomIndex, 1); //Retire le mot de la liste principale pour ne pas le reprendre return { word: word, wordShuffled: 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 words = []; var wordsShuffeled = []; for (var i = 0; i < numberOfWords; i++) { var wordSingle = pickAndShakeSingleWord(); var word = wordSingle.word; var shuffledWord = wordSingle.wordShuffled; words.push(word); wordsShuffeled.push(shuffledWord); } return { words: words, wordsShuffeled: wordsShuffeled }; } //Fin de la fonction pickAndShakeWords //Fonction putRandomShuffledWordInGrid : permet de mettre un mot mélangé dans la grille principale function putRandomShuffledWordInGrid() { var word = pickAndShakeSingleWord().word; var isPossibleToAddletter = true; //Indique si le mot peut être ajouté dans la grille principale for (var i = 0; i < word.length && isPossibleToAddletter; i++) { isPossibleToAddletter = mainGrid.addRandomLetter(word[i]); } if (isPossibleToAddletter && word != '') { mainGrid.addWord(word); } return isPossibleToAddletter; } //Fin de la fonction putRandomShuffledWordInGrid //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 dans une liste de mots function validateWord(liste) { var word = ''; for (var i = 0; i < wordGrid.gridColumns; i++) { word += wordGrid.cells[0][i].letter; } if (liste.includes(word)) { wordGrid.addWord(word); //Archive les mots trouves mainGrid.removeWord(word); //Retire le mot de la grille principale score += word.length * 10; isWordValid = true; } else { isWordValid = false; } wordGrid.colorAllCells(isWordValid ? "#00FF00" : "#FF0000"); return isWordValid; } //Fin de la fonction validateWord // Fonction pour créer une image à faire défiler et redimensionner function createImageToSrollRescale(asset, xFrom, yFrom) { // Création d'une nouvelle instance de l'image asset var assetToScrollRescale = LK.getAsset(asset, { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1, x: xFrom, y: yFrom }); var imageToScrollRescale = { animate: false, image: assetToScrollRescale, xToReach: 0, yToReach: 0, scaleToReach: 1, nbTicksLeft: 0, isDestroyedOnEnd: false }; game.addChild(assetToScrollRescale); return imageToScrollRescale; } //fin createImageToSrollRescale //Fonction scrollRescaleImages permettant de faire défiler et redimensionner des images function scrollRescaleImages() { for (var i = 0; i < imagesToScrollRescale.length; i++) { if (imagesToScrollRescale[i].animate) { if (imagesToScrollRescale[i].nbTicksLeft == 0) { //On retire l'image du tableau si le nombre de ticks est nul imagesToScrollRescale.splice(i, 1); //On détruit l'image si isDestroyedOnEnd est vrai if (imagesToScrollRescale[i] && imagesToScrollRescale[i].isDestroyedOnEnd) { imagesToScrollRescale[i].image.destroy(); } } else { var x = imagesToScrollRescale[i].image.x; var y = imagesToScrollRescale[i].image.y; var scale = imagesToScrollRescale[i].image.scale.x; var xToReach = imagesToScrollRescale[i].xToReach; var yToReach = imagesToScrollRescale[i].yToReach; var scaleToReach = imagesToScrollRescale[i].scaleToReach; var nbTicksLeft = imagesToScrollRescale[i].nbTicksLeft; var dx = (xToReach - x) / nbTicksLeft; var dy = (yToReach - y) / nbTicksLeft; var dscale = (scaleToReach - scale) / nbTicksLeft; imagesToScrollRescale[i].image.x += dx; imagesToScrollRescale[i].image.y += dy; imagesToScrollRescale[i].image.scale.x += dscale; imagesToScrollRescale[i].image.scale.y += dscale; imagesToScrollRescale[i].nbTicksLeft -= 1; } } } } //fin scrollRescaleImages //Fonction createRewardImage : permet de créer une image de récompense //Une image de RewardsCoin est crée à la position x, y puis elle est scrollRescalée à la position du score function createRewardImage(x, y) { var rewardImage = createImageToSrollRescale('RewardsCoin', x, y); scoreTest = "xFrom = " + x + " / yFrom = " + y; rewardImage.xToReach = game.width / 2; rewardImage.yToReach = MainZone.y - scoreText.height / 2; rewardImage.scaleToReach = 1.0; rewardImage.nbTicksLeft = 70; rewardImage.animate = true; rewardImage.isDestroyedOnEnd = true; imagesToScrollRescale.push(rewardImage); } //fin createRewardImage /**** * Main loop ****/ game.update = function () { //Mise à jour score updateScoreTest(scoreTest); updateScore(score); //Animation des images scrollRescaleImages(); //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]); } } } //Affichage ou pas du bouton de validation if (validateButton) { if (wordGrid.isEmpty()) { validateButton.visible = false; } else { validateButton.visible = true; } } //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; clueLevel = 0; //On remet le niveau d'indice à 0 } //Autres actions à effectuer sans urgence if (LK.ticks % 10 == 0) { //Chargement initiale de la grille principale si nécessaire (vide): //mot(s) 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).words; for (var i = 0; i < wordsToBegin.length; i++) { var isPossibleToAddletter = true; for (var j = 0; j < wordsToBegin[i].length && isPossibleToAddletter; j++) { isPossibleToAddletter = mainGrid.addRandomLetter(wordsToBegin[i][j]); } if (isPossibleToAddletter) { mainGrid.addWord(wordsToBegin[i]); } } isGameStarted = true; isMGRefillrequired = false; } //Chargement d'un mot mélangé dans la grille principale si demandé (isMGRefillrequired = true) et fin de partie if (isMGRefillrequired) { if (!putRandomShuffledWordInGrid()) { LK.setTimeout(function () { LK.showGameOver(); }, 1000); } isMGRefillrequired = false; } } }; //Fin de la fonction update //Liste des mots en majuscule var animals = ["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", "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"]; //var animaux = ["ORYCTEROPE", "ALBATROS", "ALLIGATOR", "ALPAGA", "FOURMI", "FOURMILIER", "ANTILOPE", "SINGE", "TATOU", "BABOUIN", "BLAIREAU", "OURS", "CASTOR", "ABEILLE", "SCARABEE", "BISON", "SANGLIER", "BUFFLE", "PAPILLON", "CHAMEAU", "CANARI", "CAPYBARA", "CARIBOU", "CARPE", "CHAT", "CHENILLE", "GUEPARD", "POULET", "CHIMPANZE", "CHINCHILLA", "CRAVE", "PALOURDE", "COBRA", "CAFARD", "MORUE", "CORMORAN", "COYOTE", "CRABE", "GRUE", "CROCODILE", "CORBEAU", "COURLIS", "CERF", "DINOSAURE", "CHIEN", "AIGLEFIN", "DAUPHIN", "ANE", "ECHANDE", "COLOMBE", "LIBELLULE", "CANARD", "DUGONG", "BECASSEAU", "AIGLE", "ECHIDNE", "ANGUILLE", "ELAND", "ELEPHANT", "ELAN", "EMEU", "FAUCON", "FUROT", "PINSON", "POISSON", "FLAMANT", "MOUCHE", "RENARD", "GRENOUILLE", "GAUR", "GAZELLE", "GERBILLE", "GIRAFE", "MOUSTIQUE", "GNU", "CHEVRE", "CHARDONNERET", "OIE", "GORILLE", "AUTOUR", "SAUTERELLE", "GELINOTTE", "GUANACO", "MOUETTE", "HAMSTER", "LIEVRE", "FAUCON", "HERISSON", "HERON", "HARENG", "HIPPOPOTAME", "FRELON", "CHEVAL", "COLIBRI", "HYENE", "BOUC", "IBIS", "CHACAL", "JAGUAR", "GEAI", "MEDUSE", "KANGOUROU", "KOALA", "KOOKABURRA", "KOUROU", "VANNEAU", "ALOUETTE", "LEMURIEN", "LEOPARD", "LION", "LAMA", "HOMARD", "CRIQUET", "LORIS", "POUX", "MENURE", "PIE", "COLVERT", "LAMANTIN", "MANDRILL", "MANTIS", "MARTRE", "SURICATE", "VISON", "TAUPE", "SINGE", "ORIGNAL", "MOUSTIQUE", "SOURIS", "MULET", "NARVAL", "TRITON", "ROSSIGNOL", "PIEUVRE", "OKAPI", "OPOSSUM", "ORYX", "AUTRUCHE", "LOUTRE", "HIBOU", "HUITRE", "PANTHERE", "PERROQUET", "PERDRIX", "PAON", "PELICAN", "PINGOUIN", "FAISAN", "COCHON", "PIGEON", "MARSOUIN", "CAILLE", "QUELEA", "QUETZAL", "LAPIN", "RALE", "BELIER", "RAT", "CORBEAU", "RENNE", "RHINOCEROS", "FREUX", "SALAMANDRE", "SAUMON", "BECASSE", "SARDINE", "SCORPION", "HIPPOCAMPE", "PHOQUE", "REQUIN", "MOUTON", "MUSARAIGNE", "MOUFETTE", "ESCARGOT", "SERPENT", "MOINEAU", "ARAIGNEE", "SPATULE", "CALMAR", "ECUREUIL", "ETOURNEAU", "RAIE", "PUNAISE", "CIGOGNE", "HIRONDELLE", "CYGNE", "TAPIR", "TARSIER", "TERMITE", "TIGRE", "STERNE", "GRIVE", "TIGRE", "CRAPAUD", "TOUCAN", "TRUITE", "DINDON", "TORTUE", "VIPERE", "VOLTURE", "WALLABY", "MORSE", "GUEPE", "BELETTE", "BALEINE", "CHAT SAUVAGE", "LOUP", "WOMBAT", "BECASSE", "PIVOINE", "VER", "ROITELET", "YACK", "ZEBRE"]; //var usaStates = ["ALABAMA", "ALASKA", "ARIZONA", "ARKANSAS", "CALIFORNIA", "COLORADO", "CONNECTICUT", "DELAWARE", "FLORIDA", "GEORGIA", "HAWAII", "IDAHO", "ILLINOIS", "INDIANA", "IOWA", "KANSAS", "KENTUCKY", "LOUISIANA", "MAINE", "MARYLAND", "MASSACHUSETTS", "MICHIGAN", "MINNESOTA", "MISSISSIPPI", "MISSOURI", "MONTANA", "NEBRASKA", "NEVADA", "NEW HAMPSHIRE", "NEW-JERSEY", "NEW MEXICO", "NEW-YORK", "NORTH CAROLINA", "NORTH-DAKOTA", "OHIO", "OKLAHOMA", "OREGON", "PENNSYLVANIA", "RHODE-ISLAND", "SOUTH-CAROLINA", "SOUTH-DAKOTA", "TENNESSEE", "TEXAS", "UTAH", "VERMONT", "VIRGINIA", "WASHINGTON", "WEST VIRGINIA", "WISCONSIN", "WYOMING"]; //var europeanCapitales = ["AMSTERDAM", "ANDORRA-LA-VELLA", "ANKARA", "ATHENS", "BELGRADE", "BERLIN", "BERN", "BRATISLAVA", "BRUSSELS", "BUCHAREST", "BUDAPEST", "CHISINAU", "COPENHAGEN", "DUBLIN", "HELSINKI", "KIEV", "LISBON", "LJUBLJANA", "LONDON", "LUXEMBOURG", "MADRID", "MINSK", "MONACO", "MOSCOW", "NICOSIA", "OSLO", "PARIS", "PODGORICA", "PRAGUE", "REYKJAVIK", "RIGA", "ROME", "SAN-MARINO", "SARAJEVO", "SKOPJE", "SOFIA", "STOCKHOLM", "TALLINN", "TBILISI", "TIRANA", "VADUZ", "VALLETTA", "VIENNA", "VILNIUS", "WARSAW", "ZAGREB"]; //var planetesNsatellites = ["SUN", "MERCURY", "VENUS", "EARTH", "MOON", "MARS", "PHOBOS", "DEIMOS", "JUPITER", "IO", "EUROPA", "GANYMEDE", "CALLISTO", "SATURN", "TITAN", "MIMAS", "ENCELADUS", "TETHYS", "DIONE", "RHEA", "HYPERION", "LAPETUS", "PHOEBE", "URANUS", "PUCK", "MIRANDA", "ARIEL", "UMBRIEL", "TITANIA", "OBERON", "NEPTUNE", "TRITON", "PROTEUS", "NEREID", "PLUTO", "CHARON"];
/****
* Classes
****/
var Button = Container.expand(function (text, options) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset(options.assetName || '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 && options.text.size || 50,
fill: options.text && 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.wordFrom = ''; //Mot d'origine de la lettre
self.letter = letter;
self.policeSize = policeSize;
var text = new Text2(letter.toUpperCase(), {
size: self.policeSize,
fill: "#000000"
});
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.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;
var oneCell = new GridCell('', assetName); //Taille de reference
self.width = oneCell.cellSize * self.gridColumns;
self.height = oneCell.cellSize + oneCell.cellSize * (self.gridLines - 1);
self.clickable = true; //Indique si la grille est cliquable
self.cells = [];
self.emptyCells = []; //Liste des cellules vides
self.words = []; //Liste des mots actuellement dans la grille
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.resetGrid = function () {
//Réinitialise la grille : remove all cells and repositionnement de la grille
for (var i = 0; i < self.gridLines; i++) {
for (var j = 0; j < self.gridColumns; j++) {
self.removeChild(self.cells[i][j]);
}
}
self.cells = [];
self.emptyCells = [];
self.gridColumns = 0;
self.gridLines = 0;
}; //Fin de la fonction resetGrid
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.findNclickCell = function (letter) {
//Trouve et clique sur la première cellule contenant la lettre letter
for (var i = 0; i < self.gridLines; i++) {
for (var j = 0; j < self.gridColumns; j++) {
if (self.cells[i][j].letter === letter) {
self.cells[i][j].onClickCell();
return;
}
}
}
}; //Fin de la fonction findNclickCell
self.addWord = function (word) {
// Add a word in the list of words
self.words.push(word);
}; //Fin de la fonction addWord
self.removeWord = function (word) {
// Remove a word from the list of words
if (self.words.includes(word)) {
self.words.splice(self.words.indexOf(word), 1);
}
}; //Fin de la fonction removeWord
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.colorWordCells = function (word, color) {
//Colorie les cellules du mot word en couleur color
for (var j = 0; j < self.gridLines; j++) {
for (var k = 0; k < self.gridColumns; k++) {
if (word.includes(self.cells[j][k].letter)) {
self.cells[j][k].setColorToLetter(color);
word = word.replace(self.cells[j][k].letter, '');
}
}
}
}; //Fin de la fonction colorWordCells
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 clueWord = '';
// Button class for creating buttons in the game
/****
* GAME DESCRIPTION:
* Game Principle:
* -There is a board filled with letters, 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 main list, it is valid, and the player earns points.
* -The score obtained is proportional to the length of the word.
* -These letters move randomly within the grid to empty spaces.
* -If the word is not valid, the letters forming the word are returned to their original position in the grid.
* -A new word is selected from the main list, shuffled and randomly dispatched in the empty cells.
* -If there is no more space in the grid, the game is over.
* Game Areas:
* The screen is divided into 5 main zones in the following descending order:
1. Score area: displays the player's score.
2. The grid: the letter grid (main grid).
3. Word area: displays the word formed by the player (word grid).
4. Validation area: button to validate the word or erase letters.
5. Options area (or advertisement).
* Game Progression:
* At the beginning of the game, the grid is almost empty, containing one shuffled word.
* 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.
* If the word is not valid, the letters forming the word are returned to their original position in the grid.
* A new word appears randomly within the grid to empty spaces.
* If there is no more space in the grid, the game is over.
****/
var backGroundsList = ["BackGroundPlanetesNSatellites", "BackGroundUSAStates", "BackGroundEuropeanCapitales"]; //Liste des assets de fond
var mainListsList = [planetesNsatellites, usaStates, europeanCapitales]; //Liste des listes de mots principales
//var wordsMainListTest = ["AARDVARK", "ALBATROSS", "ALLIGATOR", "ALPACA", "ANT"]; //The real main list is at the end
var usaStates = ["ALABAMA", "ALASKA", "ARIZONA", "ARKANSAS", "CALIFORNIA", "COLORADO", "CONNECTICUT", "DELAWARE", "FLORIDA", "GEORGIA", "HAWAII", "IDAHO", "ILLINOIS", "INDIANA", "IOWA", "KANSAS", "KENTUCKY", "LOUISIANA", "MAINE", "MARYLAND", "MASSACHUSETTS", "MICHIGAN", "MINNESOTA", "MISSISSIPPI", "MISSOURI", "MONTANA", "NEBRASKA", "NEVADA", "NEW-HAMPSHIRE", "NEW-JERSEY", "NEW-MEXICO", "NEW-YORK", "NORTH-CAROLINA", "NORTH-DAKOTA", "OHIO", "OKLAHOMA", "OREGON", "PENNSYLVANIA", "RHODE-ISLAND", "SOUTH-CAROLINA", "SOUTH-DAKOTA", "TENNESSEE", "TEXAS", "UTAH", "VERMONT", "VIRGINIA", "WASHINGTON", "WEST-VIRGINIA", "WISCONSIN", "WYOMING"];
var europeanCapitales = ["AMSTERDAM", "ANDORRA-LA-VELLA", "ANKARA", "ATHENS", "BELGRADE", "BERLIN", "BERN", "BRATISLAVA", "BRUSSELS", "BUCHAREST", "BUDAPEST", "CHISINAU", "COPENHAGEN", "DUBLIN", "HELSINKI", "KIEV", "LISBON", "LJUBLJANA", "LONDON", "LUXEMBOURG", "MADRID", "MINSK", "MONACO", "MOSCOW", "NICOSIA", "OSLO", "PARIS", "PODGORICA", "PRAGUE", "REYKJAVIK", "RIGA", "ROME", "SAN-MARINO", "SARAJEVO", "SKOPJE", "SOFIA", "STOCKHOLM", "TALLINN", "TBILISI", "TIRANA", "VADUZ", "VALLETTA", "VIENNA", "VILNIUS", "WARSAW", "ZAGREB"];
//var planetesNsatellites = ["SUN", "MERCURY", "VENUS", "EARTH", "MOON", "MARS", "PHOBOS", "DEIMOS", "JUPITER", "IO", "EUROPA", "GANYMEDE", "CALLISTO", "SATURN", "TITAN", "MIMAS", "ENCELADUS", "TETHYS", "DIONE", "RHEA", "HYPERION", "LAPETUS", "PHOEBE", "URANUS", "PUCK", "MIRANDA", "ARIEL", "UMBRIEL", "TITANIA", "OBERON", "NEPTUNE", "TRITON", "PROTEUS", "NEREID", "PLUTO", "CHARON"];
var planetesNsatellites = ["SUN", "MERCURY", "VENUS", "EARTH", "MOON", "MARS"];
var scoreTest = 0; // Define scoreTest variable
var score = 0;
/****
* Game zones and backgrounds
****/
var ScoreZone = {
x: 0,
y: 0,
width: game.width,
height: 200 * game.height / 2732
};
var MainZone = {
x: 0,
y: ScoreZone.height,
width: game.width,
height: game.height - 2 * ScoreZone.height
};
var OptionsZone = {
x: 0,
y: game.height - ScoreZone.height,
width: game.width,
height: 200 * game.height / 2732
};
var backGroundScoreZone = LK.getAsset('ScoreZoneBackGround', {
x: ScoreZone.x,
y: ScoreZone.y,
width: ScoreZone.width,
height: ScoreZone.height
});
game.addChild(backGroundScoreZone);
var backGroundOptionsZone = LK.getAsset('OptionsZoneBackGround', {
x: OptionsZone.x,
y: OptionsZone.y,
width: OptionsZone.width,
height: OptionsZone.height
});
game.addChild(backGroundOptionsZone);
/****
* Score
****/
var scoreTestText = new Text2('0', {
size: 30,
fill: "#ffff00",
anchorX: 0.5,
anchorY: 0
});
LK.gui.topLeft.addChild(scoreTestText);
var scoreText = new Text2('0', {
size: 100,
fill: "#00ff00",
anchorX: 0.5,
anchorY: 0
});
LK.gui.top.addChild(scoreText);
/****
* Main zone foreground
****/
var policeSize = 128;
var mainGrid = new LettersGrid(6, 6, 'cell');
var wordGrid = null;
var isGameStarted = false;
var isMGRefillrequired = false; //Indique si le remplissage de la grille principale est nécessaire
var isWordValid = false; //Indique si le mot formé est valide
var validateButton = null;
var clueLevel = 0; //Niveau d'indice
var clueButton = null;
var clueButtonWord = null;
var clueButtonDrop = null;
var animatingImageOn = false; //Drapeau indiquant qu'une image est a scrollscaller
var imagesToScrollRescale = []; //Liste des images a scrollscaller
//initGameThema(planetesNsatellites, 'BackGroundPlanetesNSatellites');
//initGameThema(usaStates, 'BackGroundUSAStates');
initGameThema(europeanCapitales, 'BackGroundEuropeanCapitales');
/****
* Functions
****/
//Fonction initGameThema : permet d'initialiser le thème du jeu (liste des mots et image de fond)
function initGameThema(mainList, backGround) {
isGameStarted = false;
isMGRefillrequired = false;
isWordValid = false;
clueLevel = 0;
setMainWordsList(mainList);
setBackGroundImage(backGround);
mainGrid.initializeGrid();
mainGrid.x = game.width / 2 - mainGrid.width / 2 + mainGrid.width / (mainGrid.gridColumns + 2);
mainGrid.y = MainZone.height / 6;
game.addChild(mainGrid);
initWordGrid();
setValidateButton('buttonValidate');
setClueButton('buttonClue');
setClueButtonWord('ButtonClue1');
setClueButtonDrop('ButtonClue2');
} //Fin de la fonction initGameThema
function updateScoreTest(nouveauScore) {
scoreTestText.setText(nouveauScore);
} //fin updateScoreTest
function updateScore(nouveauScore) {
scoreText.setText(nouveauScore);
} //fin updateScore
//Fonction setMainWordsList : permet de définir la liste principale des mots
function setMainWordsList(liste) {
wordsMainList = liste;
} //Fin de la fonction setMainWordsList
//Fonction setBackGroundImage : permet de définir l'image de fond du jeu
function setBackGroundImage(image) {
backGroundImage = LK.getAsset(image, {
x: MainZone.x,
y: MainZone.y,
width: MainZone.width,
height: MainZone.height
});
game.addChild(backGroundImage);
} //Fin de la fonction setBackGroundImage
//Fonction onClickValidateButton : permet de valider le mot formé par le joueur
function onClickValidateButton() {
if (validateWord(mainGrid.words)) {
//On vide la grille des lettres formant le mot final apres x secondes
LK.setTimeout(function () {
createRewardImage(wordGrid.x, wordGrid.y);
wordGrid.resetGrid();
initWordGrid();
}, 1000);
if (mainGrid.isEmpty()) {
score += 100; //Bonus for emptying the main grid
isMGRefillrequired = true;
}
} else {
//Le mot n'est pas valide, on remet les lettres dans la grille principale
LK.setTimeout(function () {
for (var i = 0; i < wordGrid.gridColumns; i++) {
mainGrid.setLetter(wordGrid.cells[0][i].columnFrom, wordGrid.cells[0][i].lineFrom, wordGrid.cells[0][i].letter);
}
isMGRefillrequired = true;
wordGrid.resetGrid();
initWordGrid();
}, 1000);
}
clueLevel = 0; //On remet le niveau d'indice à 0
} //Fin de la fonction onClickValidateButton
//Fonction setValidateButton : permet de définir le bouton de validation
function setValidateButton(asset) {
validateButton = new Button('', {
assetName: asset,
x: game.width / 2 + 50,
y: wordGrid.y + wordGrid.height + 350,
width: 300,
height: 300,
fill: "#00FF00",
text: {
size: 50,
fill: "#000000"
},
onClick: onClickValidateButton
});
game.addChild(validateButton);
} //Fin de la fonction setValidateButton
//Fonction onClickClueButton : permet de donner un indice au joueur
function onClickClueButton() {
if (!wordGrid.isEmpty()) {
//Si le joueur a déjà commencé à former un mot, on ne donne pas d'indice
return;
}
if (mainGrid.words.length >= 1) {
var randomIndex = Math.floor(Math.random() * mainGrid.words.length);
var word = mainGrid.words[randomIndex];
var firstLetter = word[0];
var line = -1;
var col = -1;
for (var i = 0; i < mainGrid.gridLines; i++) {
//On colorie la première lettre du mot pendant 2 secondes
for (var j = 0; j < mainGrid.gridColumns; j++) {
if (mainGrid.cells[i][j].letter == firstLetter) {
mainGrid.cells[i][j].setColorToLetter("#FF5500");
line = i;
col = j;
break;
}
}
}
LK.setTimeout(function () {
if (mainGrid.cells[line] && mainGrid.cells[line][col]) {
mainGrid.cells[line][col].setColorToLetter("#000000");
}
}, 2000);
}
} //Fin de la fonction onClickClueButton
//Fonction setClueButton : permet de définir le bouton d'indice
function setClueButton(asset) {
clueButton = new Button('', {
assetName: asset,
x: game.width / 2 - 350,
y: 150,
// Set a default y position
width: 200,
height: 200,
fill: "#00FF00",
text: {
size: 50,
fill: "#000000"
},
onClick: onClickClueButton
});
clueButton.x = game.width - clueButton.width; // Adjust x position after initialization
clueButton.y = mainGrid.y + clueButton.height; // Adjust y position after initialization
game.addChild(clueButton);
} //Fin de la fonction setClueButton
//Fonction onClickClueButtonWord : permet de donner un indice au joueur (change la couleur des lettres d'un des mots au hasard)
function onClickClueButtonWord() {
if (!wordGrid.isEmpty()) {
//Si le joueur a déjà commencé à former un mot, on ne donne pas d'indice
return;
}
//On change la couleur des lettres d'un des mots au hasard de mainGrid.words
if (mainGrid.words.length >= 1) {
var randomIndex = Math.floor(Math.random() * mainGrid.words.length);
var word = mainGrid.words[randomIndex];
mainGrid.colorWordCells(word, "#FF5500");
LK.setTimeout(function () {
mainGrid.colorWordCells(word, "#000000");
}, 3000);
}
} //Fin de la fonction onClickClueButtonWord
//Fonction setClueButtonWord : permet de définir le bouton d'indice focus word
function setClueButtonWord(asset) {
clueButtonWord = new Button('', {
assetName: asset,
x: game.width / 2 - 350,
y: mainGrid.y,
// Set a default y position
width: 200,
height: 200,
fill: "#00FF00",
text: {
size: 50,
fill: "#000000"
},
onClick: onClickClueButtonWord
});
clueButtonWord.x = game.width - clueButtonWord.width; // Adjust x position after initialization
clueButtonWord.y = mainGrid.y + 2 * clueButtonWord.height; // Adjust y position after initialization
game.addChild(clueButtonWord);
} //Fin de la fonction setClueButtonWord
//Fonction onClickClueButtonDrop : permet de donner un indice au joueur (drop letter)
function onClickClueButtonDrop() {
if (!wordGrid.isEmpty() && clueLevel == 0) {
//Si le joueur a déjà commencé à former un mot, on ne donne pas d'indice
return;
}
switch (clueLevel) {
case 0:
//On prend un mot au hasard dans la liste principale et on clique sur la première lettre (isClicked = true)
if (mainGrid.words.length > 0) {
var randomIndex = Math.floor(Math.random() * mainGrid.words.length);
var word = mainGrid.words[randomIndex];
clueWord = word; //On garde le mot pour le prochain indice
var firstLetter = word[0];
var secondLetter = word[1];
mainGrid.findNclickCell(firstLetter);
LK.setTimeout(function () {
mainGrid.findNclickCell(secondLetter);
}, 100);
}
break;
default:
//On descend les lettres d'un mot
if (clueWord != '') {
var letter = clueWord[clueLevel + 1];
mainGrid.findNclickCell(letter);
}
break;
} //Fin du switch
clueLevel++;
} //Fin de la fonction onClickClueButtonDrop
//Fonction setClueButtonDrop : permet de définir le bouton d'indice drop letter
function setClueButtonDrop(asset) {
clueButtonDrop = new Button('', {
assetName: asset,
x: game.width / 2 - 350,
y: mainGrid.y,
// Set a default y position
width: 200,
height: 200,
fill: "#00FF00",
text: {
size: 50,
fill: "#000000"
},
onClick: onClickClueButtonDrop
});
clueButtonDrop.x = game.width - clueButtonDrop.width; // Adjust x position after initialization
clueButtonDrop.y = mainGrid.y + 3 * clueButtonDrop.height; // Adjust y position after initialization
game.addChild(clueButtonDrop);
} //Fin de la fonction setClueButtonDrop
//Fonction initWordGrid : permet d'initialiser la grille des lettres formant le mot
function initWordGrid() {
//Initialise la grille des lettres formant le mot
wordGrid = game.addChild(new LettersGrid(0, 1, 'cellWord'));
wordGrid.initializeGrid();
wordGrid.x = game.width / 2 + 100;
wordGrid.y = ScoreZone.height + mainGrid.height + 300;
} //Fin de la fonction initWordGrid
//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() * wordsMainList.length);
var word = wordsMainList[randomIndex];
if (!word) {
return {
word: '',
wordShuffled: ''
};
}
var wordShuffled = word.split('').sort(function () {
return 0.5 - Math.random();
}).join('');
wordsMainList.splice(randomIndex, 1); //Retire le mot de la liste principale pour ne pas le reprendre
return {
word: word,
wordShuffled: 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 words = [];
var wordsShuffeled = [];
for (var i = 0; i < numberOfWords; i++) {
var wordSingle = pickAndShakeSingleWord();
var word = wordSingle.word;
var shuffledWord = wordSingle.wordShuffled;
words.push(word);
wordsShuffeled.push(shuffledWord);
}
return {
words: words,
wordsShuffeled: wordsShuffeled
};
} //Fin de la fonction pickAndShakeWords
//Fonction putRandomShuffledWordInGrid : permet de mettre un mot mélangé dans la grille principale
function putRandomShuffledWordInGrid() {
var word = pickAndShakeSingleWord().word;
var isPossibleToAddletter = true; //Indique si le mot peut être ajouté dans la grille principale
for (var i = 0; i < word.length && isPossibleToAddletter; i++) {
isPossibleToAddletter = mainGrid.addRandomLetter(word[i]);
}
if (isPossibleToAddletter && word != '') {
mainGrid.addWord(word);
}
return isPossibleToAddletter;
} //Fin de la fonction putRandomShuffledWordInGrid
//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 dans une liste de mots
function validateWord(liste) {
var word = '';
for (var i = 0; i < wordGrid.gridColumns; i++) {
word += wordGrid.cells[0][i].letter;
}
if (liste.includes(word)) {
wordGrid.addWord(word); //Archive les mots trouves
mainGrid.removeWord(word); //Retire le mot de la grille principale
score += word.length * 10;
isWordValid = true;
} else {
isWordValid = false;
}
wordGrid.colorAllCells(isWordValid ? "#00FF00" : "#FF0000");
return isWordValid;
} //Fin de la fonction validateWord
// Fonction pour créer une image à faire défiler et redimensionner
function createImageToSrollRescale(asset, xFrom, yFrom) {
// Création d'une nouvelle instance de l'image asset
var assetToScrollRescale = LK.getAsset(asset, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 1,
x: xFrom,
y: yFrom
});
var imageToScrollRescale = {
animate: false,
image: assetToScrollRescale,
xToReach: 0,
yToReach: 0,
scaleToReach: 1,
nbTicksLeft: 0,
isDestroyedOnEnd: false
};
game.addChild(assetToScrollRescale);
return imageToScrollRescale;
} //fin createImageToSrollRescale
//Fonction scrollRescaleImages permettant de faire défiler et redimensionner des images
function scrollRescaleImages() {
for (var i = 0; i < imagesToScrollRescale.length; i++) {
if (imagesToScrollRescale[i].animate) {
if (imagesToScrollRescale[i].nbTicksLeft == 0) {
//On retire l'image du tableau si le nombre de ticks est nul
imagesToScrollRescale.splice(i, 1);
//On détruit l'image si isDestroyedOnEnd est vrai
if (imagesToScrollRescale[i] && imagesToScrollRescale[i].isDestroyedOnEnd) {
imagesToScrollRescale[i].image.destroy();
}
} else {
var x = imagesToScrollRescale[i].image.x;
var y = imagesToScrollRescale[i].image.y;
var scale = imagesToScrollRescale[i].image.scale.x;
var xToReach = imagesToScrollRescale[i].xToReach;
var yToReach = imagesToScrollRescale[i].yToReach;
var scaleToReach = imagesToScrollRescale[i].scaleToReach;
var nbTicksLeft = imagesToScrollRescale[i].nbTicksLeft;
var dx = (xToReach - x) / nbTicksLeft;
var dy = (yToReach - y) / nbTicksLeft;
var dscale = (scaleToReach - scale) / nbTicksLeft;
imagesToScrollRescale[i].image.x += dx;
imagesToScrollRescale[i].image.y += dy;
imagesToScrollRescale[i].image.scale.x += dscale;
imagesToScrollRescale[i].image.scale.y += dscale;
imagesToScrollRescale[i].nbTicksLeft -= 1;
}
}
}
} //fin scrollRescaleImages
//Fonction createRewardImage : permet de créer une image de récompense
//Une image de RewardsCoin est crée à la position x, y puis elle est scrollRescalée à la position du score
function createRewardImage(x, y) {
var rewardImage = createImageToSrollRescale('RewardsCoin', x, y);
scoreTest = "xFrom = " + x + " / yFrom = " + y;
rewardImage.xToReach = game.width / 2;
rewardImage.yToReach = MainZone.y - scoreText.height / 2;
rewardImage.scaleToReach = 1.0;
rewardImage.nbTicksLeft = 70;
rewardImage.animate = true;
rewardImage.isDestroyedOnEnd = true;
imagesToScrollRescale.push(rewardImage);
} //fin createRewardImage
/****
* Main loop
****/
game.update = function () {
//Mise à jour score
updateScoreTest(scoreTest);
updateScore(score);
//Animation des images
scrollRescaleImages();
//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]);
}
}
}
//Affichage ou pas du bouton de validation
if (validateButton) {
if (wordGrid.isEmpty()) {
validateButton.visible = false;
} else {
validateButton.visible = true;
}
}
//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;
clueLevel = 0; //On remet le niveau d'indice à 0
}
//Autres actions à effectuer sans urgence
if (LK.ticks % 10 == 0) {
//Chargement initiale de la grille principale si nécessaire (vide):
//mot(s) 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).words;
for (var i = 0; i < wordsToBegin.length; i++) {
var isPossibleToAddletter = true;
for (var j = 0; j < wordsToBegin[i].length && isPossibleToAddletter; j++) {
isPossibleToAddletter = mainGrid.addRandomLetter(wordsToBegin[i][j]);
}
if (isPossibleToAddletter) {
mainGrid.addWord(wordsToBegin[i]);
}
}
isGameStarted = true;
isMGRefillrequired = false;
}
//Chargement d'un mot mélangé dans la grille principale si demandé (isMGRefillrequired = true) et fin de partie
if (isMGRefillrequired) {
if (!putRandomShuffledWordInGrid()) {
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
isMGRefillrequired = false;
}
}
}; //Fin de la fonction update
//Liste des mots en majuscule
var animals = ["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", "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"];
//var animaux = ["ORYCTEROPE", "ALBATROS", "ALLIGATOR", "ALPAGA", "FOURMI", "FOURMILIER", "ANTILOPE", "SINGE", "TATOU", "BABOUIN", "BLAIREAU", "OURS", "CASTOR", "ABEILLE", "SCARABEE", "BISON", "SANGLIER", "BUFFLE", "PAPILLON", "CHAMEAU", "CANARI", "CAPYBARA", "CARIBOU", "CARPE", "CHAT", "CHENILLE", "GUEPARD", "POULET", "CHIMPANZE", "CHINCHILLA", "CRAVE", "PALOURDE", "COBRA", "CAFARD", "MORUE", "CORMORAN", "COYOTE", "CRABE", "GRUE", "CROCODILE", "CORBEAU", "COURLIS", "CERF", "DINOSAURE", "CHIEN", "AIGLEFIN", "DAUPHIN", "ANE", "ECHANDE", "COLOMBE", "LIBELLULE", "CANARD", "DUGONG", "BECASSEAU", "AIGLE", "ECHIDNE", "ANGUILLE", "ELAND", "ELEPHANT", "ELAN", "EMEU", "FAUCON", "FUROT", "PINSON", "POISSON", "FLAMANT", "MOUCHE", "RENARD", "GRENOUILLE", "GAUR", "GAZELLE", "GERBILLE", "GIRAFE", "MOUSTIQUE", "GNU", "CHEVRE", "CHARDONNERET", "OIE", "GORILLE", "AUTOUR", "SAUTERELLE", "GELINOTTE", "GUANACO", "MOUETTE", "HAMSTER", "LIEVRE", "FAUCON", "HERISSON", "HERON", "HARENG", "HIPPOPOTAME", "FRELON", "CHEVAL", "COLIBRI", "HYENE", "BOUC", "IBIS", "CHACAL", "JAGUAR", "GEAI", "MEDUSE", "KANGOUROU", "KOALA", "KOOKABURRA", "KOUROU", "VANNEAU", "ALOUETTE", "LEMURIEN", "LEOPARD", "LION", "LAMA", "HOMARD", "CRIQUET", "LORIS", "POUX", "MENURE", "PIE", "COLVERT", "LAMANTIN", "MANDRILL", "MANTIS", "MARTRE", "SURICATE", "VISON", "TAUPE", "SINGE", "ORIGNAL", "MOUSTIQUE", "SOURIS", "MULET", "NARVAL", "TRITON", "ROSSIGNOL", "PIEUVRE", "OKAPI", "OPOSSUM", "ORYX", "AUTRUCHE", "LOUTRE", "HIBOU", "HUITRE", "PANTHERE", "PERROQUET", "PERDRIX", "PAON", "PELICAN", "PINGOUIN", "FAISAN", "COCHON", "PIGEON", "MARSOUIN", "CAILLE", "QUELEA", "QUETZAL", "LAPIN", "RALE", "BELIER", "RAT", "CORBEAU", "RENNE", "RHINOCEROS", "FREUX", "SALAMANDRE", "SAUMON", "BECASSE", "SARDINE", "SCORPION", "HIPPOCAMPE", "PHOQUE", "REQUIN", "MOUTON", "MUSARAIGNE", "MOUFETTE", "ESCARGOT", "SERPENT", "MOINEAU", "ARAIGNEE", "SPATULE", "CALMAR", "ECUREUIL", "ETOURNEAU", "RAIE", "PUNAISE", "CIGOGNE", "HIRONDELLE", "CYGNE", "TAPIR", "TARSIER", "TERMITE", "TIGRE", "STERNE", "GRIVE", "TIGRE", "CRAPAUD", "TOUCAN", "TRUITE", "DINDON", "TORTUE", "VIPERE", "VOLTURE", "WALLABY", "MORSE", "GUEPE", "BELETTE", "BALEINE", "CHAT SAUVAGE", "LOUP", "WOMBAT", "BECASSE", "PIVOINE", "VER", "ROITELET", "YACK", "ZEBRE"];
//var usaStates = ["ALABAMA", "ALASKA", "ARIZONA", "ARKANSAS", "CALIFORNIA", "COLORADO", "CONNECTICUT", "DELAWARE", "FLORIDA", "GEORGIA", "HAWAII", "IDAHO", "ILLINOIS", "INDIANA", "IOWA", "KANSAS", "KENTUCKY", "LOUISIANA", "MAINE", "MARYLAND", "MASSACHUSETTS", "MICHIGAN", "MINNESOTA", "MISSISSIPPI", "MISSOURI", "MONTANA", "NEBRASKA", "NEVADA", "NEW HAMPSHIRE", "NEW-JERSEY", "NEW MEXICO", "NEW-YORK", "NORTH CAROLINA", "NORTH-DAKOTA", "OHIO", "OKLAHOMA", "OREGON", "PENNSYLVANIA", "RHODE-ISLAND", "SOUTH-CAROLINA", "SOUTH-DAKOTA", "TENNESSEE", "TEXAS", "UTAH", "VERMONT", "VIRGINIA", "WASHINGTON", "WEST VIRGINIA", "WISCONSIN", "WYOMING"];
//var europeanCapitales = ["AMSTERDAM", "ANDORRA-LA-VELLA", "ANKARA", "ATHENS", "BELGRADE", "BERLIN", "BERN", "BRATISLAVA", "BRUSSELS", "BUCHAREST", "BUDAPEST", "CHISINAU", "COPENHAGEN", "DUBLIN", "HELSINKI", "KIEV", "LISBON", "LJUBLJANA", "LONDON", "LUXEMBOURG", "MADRID", "MINSK", "MONACO", "MOSCOW", "NICOSIA", "OSLO", "PARIS", "PODGORICA", "PRAGUE", "REYKJAVIK", "RIGA", "ROME", "SAN-MARINO", "SARAJEVO", "SKOPJE", "SOFIA", "STOCKHOLM", "TALLINN", "TBILISI", "TIRANA", "VADUZ", "VALLETTA", "VIENNA", "VILNIUS", "WARSAW", "ZAGREB"];
//var planetesNsatellites = ["SUN", "MERCURY", "VENUS", "EARTH", "MOON", "MARS", "PHOBOS", "DEIMOS", "JUPITER", "IO", "EUROPA", "GANYMEDE", "CALLISTO", "SATURN", "TITAN", "MIMAS", "ENCELADUS", "TETHYS", "DIONE", "RHEA", "HYPERION", "LAPETUS", "PHOEBE", "URANUS", "PUCK", "MIRANDA", "ARIEL", "UMBRIEL", "TITANIA", "OBERON", "NEPTUNE", "TRITON", "PROTEUS", "NEREID", "PLUTO", "CHARON"];
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.