Code edit (19 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.Sprite is not a constructor' in or related to this line: 'var backGroundImage = game.addChild(new LK.Sprite('BackGroundImage', {' Line Number: 268
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: cell is not defined' in or related to this line: 'scoreTest += cell.letter;' Line Number: 401
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: '[Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: https://beta.frvr.ai/game-template/index-0.0.3.html?frame_id=0&v2=1&1715679717556&disable_analytics=1 line 181 > injectedScript :: execute/window.getRenderer/t.Text.prototype.updateText :: line 1" data: no]' in or related to this line: 'scoreTestText.setText(nouveauScore);' Line Number: 357
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 (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
/****
* 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.
****/
// 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;
self.line = 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--;
self.x += cell.cellSize / 2; //Repositionnement de la grille
}
}; //Fin de la fonction removeCell
self.addLetter = function (letter) {
var added = false;
for (var i = 0; i < self.gridLines && !added; i++) {
for (var j = 0; j < self.gridColumns && !added; j++) {
if (self.cells[i][j].letter === '') {
self.cells[i][j].setLetter(letter);
added = true;
//Retrait de la cellule de la liste des cellules vides
if (self.emptyCells.includes(self.cells[i][j])) {
self.emptyCells.splice(self.emptyCells.indexOf(self.cells[i][j]), 1);
}
}
}
}
return added;
}; //Fin de la fonction addLetter
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(1, 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 lettersToAdd = [];
var currentLetterIndex = 0;
var wordsToBegin = pickAndShakeWords(1); // Pick and shuffle words from the main list
if (wordsToBegin.length > 0) {
// If there are words to begin
stackLettersFromWords(wordsToBegin); // Stack letters from words to add them to the grid
transfertLettersToMainGrid(); // Transfer letters to the grid
}
/****
* 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('');
scoreTest = wordShuffled;
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 liste 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 transfertLettersToGrid : permet de transférer les lettres de la liste lettersToAdd dans la grille principale
function transfertLettersToMainGrid() {
for (var i = 0; i < lettersGrid.gridColumns && lettersToAdd.length > 0; i++) {
mainGrid.addRandomLetter(lettersToAdd[0]);
lettersToAdd.splice(0, 1);
}
} //Fin de la fonction transfertLettersToMainGrid
//Fonction addCellLetterToWord : permet d'ajouter une cellule à la liste des lettres formant le mot situé sous la grille
function addCellLetterToWord(letter) {
var cellLetter = new GridCell(letter, 'cellWord');
wordGrid.addCell(letter, 'cell');
} //Fin de la fonction addCellLetterToWord
game.update = function () {
updateScoreTest(scoreTest);
//Recherche de la lettre cliquée 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) {
addCellLetterToWord(mainGrid.cells[i][j].letter);
mainGrid.cells[i][j].isClicked = false;
mainGrid.cells[i][j].setColorToLetter("#FFFFFF");
mainGrid.cells[i][j].setLetter('');
}
}
}
for (var i = 0; i < wordGrid.gridLines; i++) {
for (var j = 0; j < wordGrid.gridColumns; j++) {
if (wordGrid.cells[i][j].isClicked) {
//Retrait de la lettre cliquée du mot
wordGrid.cells[i][j].setLetter('');
wordGrid.cells[i][j].isClicked = false;
wordGrid.cells[i][j].removeCell(j);
//Ajout de la lettre à la grille principale
mainGrid.addRandomLetter(wordGrid.cells[i][j].letter);
}
}
}
if (LK.ticks % 60 == 0) {
//Si la liste des lettres à ajouter n'est pas vide, on ajoute toutes les lettres puis on supprime les lettres de la liste
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);
}
}
currentLetterIndex = (currentLetterIndex + 1) % lettersToAdd.length;
if (mainGrid.isFull()) {
mainGrid.colorAllCells("#FF0000");
LK.showGameOver();
}
}
}; //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"];
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.