Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.texte.letter is undefined' in or related to this line: 'self.texte.letter.fill = color;' Line Number: 71
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 (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: emptyCells is not defined' in or related to this line: 'if (emptyCells.includes(self.cells[i][j])) {' Line Number: 128
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Initial prompt
Cool Words
===================================================================
--- original.js
+++ change.js
@@ -45,17 +45,28 @@
anchorY: 0.5
});
self.letter = letter;
var text = new Text2(letter.toUpperCase(), {
- size: 96,
- fill: "#ffffff"
+ size: 128,
+ fill: "#ffffff",
+ anchorX: 0.5,
+ anchorY: 0.5
});
text.anchor.set(0.5, 0.5);
self.addChild(text);
self.setLetter = function (newLetter) {
self.letter = newLetter;
text.setText(newLetter.toUpperCase());
+ text.x = 0;
+ text.y = 0;
};
+ self.setColorToLetter = function (color) {
+ text.fill = color;
+ };
+ self.on('click', function () {
+ //Fonction appelée lors du click sur la cellule
+ self.setColorToLetter("#0000FF");
+ });
});
// LettersGrid class for managing the grid of letters, same as WordGrid but with control of number of columns and lines
var LettersGrid = Container.expand(function (columns, lines) {
var self = Container.call(this);
@@ -82,57 +93,31 @@
for (var j = 0; j < self.gridColumns && !added; j++) {
if (self.cells[i][j].letter === '') {
self.cells[i][j].setLetter(letter);
added = true;
+ //Gestion du click sur la cellule
+ self.cells[i][j].on('click', function () {
+ self.cells[i][j].setColorToLetter("#0000FF");
+ });
}
}
}
return added;
};
- 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;
- };
-});
-// WordGrid class for managing the grid of letters
-var WordGrid = Container.expand(function () {
- var self = Container.call(this);
- self.gridSize = 6; // 5x5 grid
- self.cellSize = 1280 / self.gridSize;
- self.cells = [];
- self.initializeGrid = function () {
- for (var i = 0; i < self.gridSize; i++) {
- self.cells[i] = [];
- for (var j = 0; j < self.gridSize; j++) {
- var cell = new GridCell('');
- cell.x = j * self.cellSize + self.cellSize / 2;
- cell.y = i * self.cellSize + self.cellSize / 2;
- self.addChild(cell);
- self.cells[i][j] = cell;
- }
- }
- };
- self.addLetter = function (letter) {
+ self.addRandomPlace = function (letter) {
+ // Add a letter in a random empty cell
var added = false;
- for (var i = 0; i < self.gridSize && !added; i++) {
- for (var j = 0; j < self.gridSize && !added; j++) {
- if (self.cells[i][j].letter === '') {
- self.cells[i][j].setLetter(letter);
- added = true;
- }
- }
+ var i = Math.floor(Math.random() * self.gridLines);
+ var j = Math.floor(Math.random() * self.gridColumns);
+ if (self.cells[i][j].letter === '') {
+ self.cells[i][j].setLetter(letter);
+ added = true;
}
return added;
};
self.isFull = function () {
- for (var i = 0; i < self.gridSize; i++) {
- for (var j = 0; j < self.gridSize; j++) {
+ for (var i = 0; i < self.gridLines; i++) {
+ for (var j = 0; j < self.gridColumns; j++) {
if (self.cells[i][j].letter === '') {
return false;
}
}
@@ -151,32 +136,18 @@
/****
* Game Code
****/
-var lettersGrid = game.addChild(new LettersGrid(6, 1));
+var lettersGrid = game.addChild(new LettersGrid(3, 1));
lettersGrid.initializeGrid();
lettersGrid.x = (2048 - lettersGrid.gridColumns * lettersGrid.cellSize) / 2;
lettersGrid.y = 200;
-var wordGrid = game.addChild(new WordGrid());
+var wordGrid = game.addChild(new LettersGrid(6, 6));
wordGrid.initializeGrid();
-wordGrid.x = (2048 - wordGrid.gridSize * wordGrid.cellSize) / 2;
-wordGrid.y = (2732 - wordGrid.gridSize * wordGrid.cellSize) / 2;
+wordGrid.x = (2048 - wordGrid.gridColumns * wordGrid.cellSize) / 2;
+wordGrid.y = 600;
var lettersToAdd = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
var currentLetterIndex = 0;
-game.update = function () {
- if (LK.ticks % 60 == 0) {
- // Add a letter every second
- var added = wordGrid.addLetter(lettersToAdd[currentLetterIndex]);
- if (!added) {
- LK.showGameOver();
- return;
- }
- currentLetterIndex = (currentLetterIndex + 1) % lettersToAdd.length;
- if (wordGrid.isFull()) {
- LK.showGameOver();
- }
- }
-};
var ScoreZone = {
x: 0,
y: 0,
width: game.width,
@@ -187,6 +158,67 @@
y: game.height - 200,
width: game.width,
height: 200
};
+//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];
+ var wordShuffled = word.split('').sort(function () {
+ return 0.5 - Math.random();
+ }).join('');
+ return {
+ word: word,
+ shuffled: 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 = [];
+ for (var i = 0; i < numberOfWords; i++) {
+ words.push(pickAndShakeSingleWord());
+ }
+ return words;
+} //Fin de la fonction pickAndShakeWords
+//Fonction displayWords : permet d'afficher les mots choisis et mélangés
+function displayWords(words) {
+ var wordsContainer = new Container();
+ wordsContainer.x = 0;
+ wordsContainer.y = 200;
+ var wordsTexts = [];
+ for (var i = 0; i < words.length; i++) {
+ var wordText = new Text2(words[i].shuffled, {
+ size: 48,
+ fill: "#ffffff"
+ });
+ wordText.x = 0;
+ wordText.y = i * 100;
+ wordsContainer.addChild(wordText);
+ wordsTexts.push(wordText);
+ }
+ game.addChild(wordsContainer);
+ return wordsTexts;
+} //Fin de la fonction displayWords
+//Fonction pickLettersFromWord : permet de choisir des lettres dans un mot
+function pickLettersFromWord(word, numberOfLetters) {
+ var letters = [];
+ for (var i = 0; i < numberOfLetters; i++) {
+ letters.push(word[Math.floor(Math.random() * word.length)]);
+ }
+ return letters;
+} //Fin de la fonction pickLettersFromWord
+game.update = function () {
+ if (LK.ticks % 60 == 0) {
+ // Add a letter every second
+ var added = wordGrid.addRandomPlace(lettersToAdd[currentLetterIndex]);
+ if (!added) {
+ //LK.showGameOver();
+ return;
+ }
+ currentLetterIndex = (currentLetterIndex + 1) % lettersToAdd.length;
+ if (wordGrid.isFull()) {
+ LK.showGameOver();
+ }
+ }
+};
//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"];
\ No newline at end of file
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.