User prompt
the buttons in the main menu are not correctly clicable
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toLowerCase')' in or related to this line: 'if (guess.toLowerCase() === self.words[self.currentWordIndex]) {' Line Number: 22
Initial prompt
Word Guesser
/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for managing the word puzzle var WordPuzzle = Container.expand(function () { var self = Container.call(this); self.words = ["apple", "banana", "cherry", "date", "elderberry"]; self.currentWordIndex = 0; self.timeLimit = 10; // 10 seconds to guess each word self.timer = null; self.score = 0; // Display the current word with missing letters self.displayWord = function () { var word = self.words[self.currentWordIndex]; var maskedWord = word.replace(/[a-z]/g, "_ "); self.wordText.setText(maskedWord); }; // Check if the guessed word is correct self.checkGuess = function (guess) { if (guess && guess.toLowerCase() === self.words[self.currentWordIndex]) { self.score++; self.nextWord(); } else { self.endGame(); } }; // Move to the next word self.nextWord = function () { self.currentWordIndex++; if (self.currentWordIndex < self.words.length) { self.displayWord(); self.resetTimer(); } else { self.winGame(); } }; // Reset the timer for the next word self.resetTimer = function () { if (self.timer) { LK.clearTimeout(self.timer); } self.timer = LK.setTimeout(self.endGame, self.timeLimit * 1000); }; // End the game self.endGame = function () { LK.showGameOver(); }; // Win the game self.winGame = function () { LK.showYouWin(); }; // Initialize the word text display self.wordText = new Text2('', { size: 100, fill: 0xFFFFFF }); self.wordText.anchor.set(0.5, 0.5); LK.gui.center.addChild(self.wordText); // Start the game self.startGame = function () { self.currentWordIndex = 0; self.score = 0; self.displayWord(); self.resetTimer(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize the word puzzle var wordPuzzle = game.addChild(new WordPuzzle()); // Start the game wordPuzzle.startGame(); // Handle user input for guessing words game.down = function (x, y, obj) { // For simplicity, let's assume the user inputs a guess through a prompt var userGuess = prompt("Enter your guess:"); wordPuzzle.checkGuess(userGuess); };
===================================================================
--- original.js
+++ change.js
@@ -1,90 +1,90 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for managing the word puzzle
var WordPuzzle = Container.expand(function () {
- var self = Container.call(this);
- self.words = ["apple", "banana", "cherry", "date", "elderberry"];
- self.currentWordIndex = 0;
- self.timeLimit = 10; // 10 seconds to guess each word
- self.timer = null;
- self.score = 0;
- // Display the current word with missing letters
- self.displayWord = function () {
- var word = self.words[self.currentWordIndex];
- var maskedWord = word.replace(/[a-z]/g, "_ ");
- self.wordText.setText(maskedWord);
- };
- // Check if the guessed word is correct
- self.checkGuess = function (guess) {
- if (guess.toLowerCase() === self.words[self.currentWordIndex]) {
- self.score++;
- self.nextWord();
- } else {
- self.endGame();
- }
- };
- // Move to the next word
- self.nextWord = function () {
- self.currentWordIndex++;
- if (self.currentWordIndex < self.words.length) {
- self.displayWord();
- self.resetTimer();
- } else {
- self.winGame();
- }
- };
- // Reset the timer for the next word
- self.resetTimer = function () {
- if (self.timer) {
- LK.clearTimeout(self.timer);
- }
- self.timer = LK.setTimeout(self.endGame, self.timeLimit * 1000);
- };
- // End the game
- self.endGame = function () {
- LK.showGameOver();
- };
- // Win the game
- self.winGame = function () {
- LK.showYouWin();
- };
- // Initialize the word text display
- self.wordText = new Text2('', {
- size: 100,
- fill: 0xFFFFFF
- });
- self.wordText.anchor.set(0.5, 0.5);
- LK.gui.center.addChild(self.wordText);
- // Start the game
- self.startGame = function () {
- self.currentWordIndex = 0;
- self.score = 0;
- self.displayWord();
- self.resetTimer();
- };
- return self;
+ var self = Container.call(this);
+ self.words = ["apple", "banana", "cherry", "date", "elderberry"];
+ self.currentWordIndex = 0;
+ self.timeLimit = 10; // 10 seconds to guess each word
+ self.timer = null;
+ self.score = 0;
+ // Display the current word with missing letters
+ self.displayWord = function () {
+ var word = self.words[self.currentWordIndex];
+ var maskedWord = word.replace(/[a-z]/g, "_ ");
+ self.wordText.setText(maskedWord);
+ };
+ // Check if the guessed word is correct
+ self.checkGuess = function (guess) {
+ if (guess && guess.toLowerCase() === self.words[self.currentWordIndex]) {
+ self.score++;
+ self.nextWord();
+ } else {
+ self.endGame();
+ }
+ };
+ // Move to the next word
+ self.nextWord = function () {
+ self.currentWordIndex++;
+ if (self.currentWordIndex < self.words.length) {
+ self.displayWord();
+ self.resetTimer();
+ } else {
+ self.winGame();
+ }
+ };
+ // Reset the timer for the next word
+ self.resetTimer = function () {
+ if (self.timer) {
+ LK.clearTimeout(self.timer);
+ }
+ self.timer = LK.setTimeout(self.endGame, self.timeLimit * 1000);
+ };
+ // End the game
+ self.endGame = function () {
+ LK.showGameOver();
+ };
+ // Win the game
+ self.winGame = function () {
+ LK.showYouWin();
+ };
+ // Initialize the word text display
+ self.wordText = new Text2('', {
+ size: 100,
+ fill: 0xFFFFFF
+ });
+ self.wordText.anchor.set(0.5, 0.5);
+ LK.gui.center.addChild(self.wordText);
+ // Start the game
+ self.startGame = function () {
+ self.currentWordIndex = 0;
+ self.score = 0;
+ self.displayWord();
+ self.resetTimer();
+ };
+ return self;
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize the word puzzle
var wordPuzzle = game.addChild(new WordPuzzle());
// Start the game
wordPuzzle.startGame();
// Handle user input for guessing words
game.down = function (x, y, obj) {
- // For simplicity, let's assume the user inputs a guess through a prompt
- var userGuess = prompt("Enter your guess:");
- wordPuzzle.checkGuess(userGuess);
+ // For simplicity, let's assume the user inputs a guess through a prompt
+ var userGuess = prompt("Enter your guess:");
+ wordPuzzle.checkGuess(userGuess);
};
\ No newline at end of file