User prompt
Please fix the bug: 'undefined is not an object (evaluating 'submitBtnBg.height')' in or related to this line: 'var scoreRowY = btnY + 2 * (submitBtnBg.height + 30);' Line Number: 346
User prompt
Place score 2 rows below the submit button
User prompt
I’m lace button to unselect alphabet before submitting
User prompt
Score not visible
User prompt
Place score downwards in screen with caption score
User prompt
Add profile for users so that they can store their game scores ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Give points only when correct words are found
User prompt
Add music
User prompt
Add music
User prompt
Music background
User prompt
Blue colour for matrix of alphabets
User prompt
Place matrix of words in blue colour background having grids across each alphabets
User prompt
Make a bigger matrix of alphabets
User prompt
Place submit button alongside reshuffle button
Code edit (1 edits merged)
Please save this source code
User prompt
Word Matrix Challenge
Initial prompt
Make a word puzzle game. Player had to select alphabets from a matrix of alphabets randomly arranged. Player selects alphabets and then presses submit button. Give 1 point for every correct answer. Place 5 minutes timer per game of play. Give option to try the matrix of alphabets so that user can find different combinations of alphabets for different words
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // LetterTile: Represents a single letter in the grid var LetterTile = Container.expand(function () { var self = Container.call(this); self.letter = ''; self.selected = false; // Attach the tile background self.bg = self.attachAsset('letterTile_A', { anchorX: 0.5, anchorY: 0.5 }); // Attach the letter text self.letterText = new Text2('', { size: 90, fill: 0xFFFFFF }); self.letterText.anchor.set(0.5, 0.5); self.addChild(self.letterText); // Highlight overlay (hidden by default) self.highlight = self.attachAsset('tileHighlight', { anchorX: 0.5, anchorY: 0.5 }); self.highlight.alpha = 0; self.addChild(self.highlight); // Set the letter and update visuals self.setLetter = function (ch) { self.letter = ch; self.letterText.setText(ch); // Swap background asset for color variety self.bg.setAsset('letterTile_' + ch); }; // Set selected state self.setSelected = function (sel) { self.selected = sel; self.highlight.alpha = sel ? 0.4 : 0; }; // Touch/click event self.down = function (x, y, obj) { if (!self.selected && !self.disabled) { self.setSelected(true); onTileSelected(self); } }; // For disabling tile after use self.setDisabled = function (val) { self.disabled = val; self.alpha = val ? 0.4 : 1; }; return self; }); // Reshuffle Button var ReshuffleButton = Container.expand(function () { var self = Container.call(this); self.bg = self.attachAsset('reshuffleBtn', { anchorX: 0.5, anchorY: 0.5 }); self.label = new Text2('Reshuffle', { size: 60, fill: "#fff" }); self.label.anchor.set(0.5, 0.5); self.addChild(self.label); self.down = function (x, y, obj) { reshuffleMatrix(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222a36 }); /**** * Game Code ****/ // --- Game Constants --- // Letters: We'll use box shapes for each letter tile, and a highlight shape for selection. for (var i = 0; i < 26; i++) {} var GRID_ROWS = 5; var GRID_COLS = 5; var TILE_SIZE = 180; var TILE_GAP = 24; var GRID_TOP = 320; var GRID_LEFT = (2048 - (GRID_COLS * TILE_SIZE + (GRID_COLS - 1) * TILE_GAP)) / 2; // --- Game State --- var letterTiles = []; // 2D array [row][col] var selectedTiles = []; // Array of LetterTile var currentWord = ''; var score = 0; var timeLeft = 300; // seconds (5 minutes) var timerInterval = null; var reshuffleBtn = null; var wordInputText = null; var submitBtn = null; var scoreText = null; var timerText = null; var usedWords = {}; // To prevent duplicate submissions // --- Helper: Generate a shuffled alphabet array --- function getShuffledAlphabet() { var alphabet = []; for (var i = 0; i < 26; i++) alphabet.push(String.fromCharCode(65 + i)); // Fisher-Yates shuffle for (var i = alphabet.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var tmp = alphabet[i]; alphabet[i] = alphabet[j]; alphabet[j] = tmp; } return alphabet; } // --- Helper: Fill the grid with shuffled letters --- function fillGrid() { var letters = getShuffledAlphabet(); var idx = 0; for (var r = 0; r < GRID_ROWS; r++) { for (var c = 0; c < GRID_COLS; c++) { var tile = letterTiles[r][c]; var ch = letters[idx % letters.length]; tile.setLetter(ch); tile.setSelected(false); tile.setDisabled(false); idx++; } } } // --- Helper: Clear current selection --- function clearSelection() { for (var i = 0; i < selectedTiles.length; i++) { selectedTiles[i].setSelected(false); } selectedTiles = []; currentWord = ''; updateWordInput(); } // --- Helper: Update the word input display --- function updateWordInput() { wordInputText.setText(currentWord); } // --- Helper: Handle tile selection --- function onTileSelected(tile) { selectedTiles.push(tile); currentWord += tile.letter; updateWordInput(); } // --- Helper: Submit word --- function submitWord() { var word = currentWord; if (word.length < 2) { // Too short, flash input LK.effects.flashObject(wordInputText, 0xff0000, 400); return; } var wordKey = word.toUpperCase(); if (usedWords[wordKey]) { LK.effects.flashObject(wordInputText, 0xff0000, 400); return; } // Accept any word (no dictionary check for MVP) usedWords[wordKey] = true; score += 1; scoreText.setText(score); // Animate tiles for (var i = 0; i < selectedTiles.length; i++) { var t = selectedTiles[i]; t.setDisabled(true); tween(t, { alpha: 0.2 }, { duration: 300, easing: tween.easeOut }); } clearSelection(); } // --- Helper: Reshuffle matrix --- function reshuffleMatrix() { fillGrid(); clearSelection(); } // --- Helper: Timer tick --- function onTimerTick() { timeLeft--; var min = Math.floor(timeLeft / 60); var sec = timeLeft % 60; timerText.setText((min < 10 ? '0' : '') + min + ':' + (sec < 10 ? '0' : '') + sec); if (timeLeft <= 0) { LK.showGameOver(); } } // --- Build UI --- // Score display (top center) scoreText = new Text2('0', { size: 120, fill: "#fff" }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Timer display (top right) timerText = new Text2('05:00', { size: 90, fill: "#fff" }); timerText.anchor.set(1, 0); LK.gui.topRight.addChild(timerText); // Word input display (center, above grid) wordInputText = new Text2('', { size: 100, fill: 0xF9D423 }); wordInputText.anchor.set(0.5, 1); wordInputText.x = 2048 / 2; wordInputText.y = GRID_TOP - 40; game.addChild(wordInputText); // Submit and Reshuffle buttons (side by side, below grid) submitBtn = new Container(); var submitBtnBg = submitBtn.attachAsset('reshuffleBtn', { anchorX: 0.5, anchorY: 0.5 }); submitBtnBg.width = 320; submitBtnBg.height = 120; var submitBtnLabel = new Text2('Submit', { size: 60, fill: "#fff" }); submitBtnLabel.anchor.set(0.5, 0.5); submitBtn.addChild(submitBtnLabel); submitBtn.down = function (x, y, obj) { submitWord(); }; reshuffleBtn = new ReshuffleButton(); // Position both buttons horizontally centered below the grid, with a gap between them var btnY = GRID_TOP + GRID_ROWS * (TILE_SIZE + TILE_GAP) + 80; var btnGap = 60; submitBtn.x = 2048 / 2 - 200 - btnGap / 2; submitBtn.y = btnY; reshuffleBtn.x = 2048 / 2 + 200 + btnGap / 2; reshuffleBtn.y = btnY; game.addChild(submitBtn); game.addChild(reshuffleBtn); // --- Build Letter Grid --- for (var r = 0; r < GRID_ROWS; r++) { letterTiles[r] = []; for (var c = 0; c < GRID_COLS; c++) { var tile = new LetterTile(); tile.x = GRID_LEFT + c * (TILE_SIZE + TILE_GAP) + TILE_SIZE / 2; tile.y = GRID_TOP + r * (TILE_SIZE + TILE_GAP) + TILE_SIZE / 2; game.addChild(tile); letterTiles[r][c] = tile; } } fillGrid(); // --- Game Touch Handling --- // (Handled by LetterTile.down for selection, submitBtn.down for submit, reshuffleBtn.down for reshuffle) // --- Timer --- timerInterval = LK.setInterval(onTimerTick, 1000); // --- Game Over Handling --- // (Handled by LK.showGameOver when timer runs out) // --- Game Update (not needed for MVP, but required by LK) --- game.update = function () { // No per-frame logic needed for MVP }; // --- Clean up on game over --- game.onDestroy = function () { LK.clearInterval(timerInterval); };
===================================================================
--- original.js
+++ change.js
@@ -84,10 +84,10 @@
/****
* Game Code
****/
-// Letters: We'll use box shapes for each letter tile, and a highlight shape for selection.
// --- Game Constants ---
+// Letters: We'll use box shapes for each letter tile, and a highlight shape for selection.
for (var i = 0; i < 26; i++) {}
var GRID_ROWS = 5;
var GRID_COLS = 5;
var TILE_SIZE = 180;
@@ -222,9 +222,9 @@
wordInputText.anchor.set(0.5, 1);
wordInputText.x = 2048 / 2;
wordInputText.y = GRID_TOP - 40;
game.addChild(wordInputText);
-// Submit button (below word input)
+// Submit and Reshuffle buttons (side by side, below grid)
submitBtn = new Container();
var submitBtnBg = submitBtn.attachAsset('reshuffleBtn', {
anchorX: 0.5,
anchorY: 0.5
@@ -236,18 +236,20 @@
fill: "#fff"
});
submitBtnLabel.anchor.set(0.5, 0.5);
submitBtn.addChild(submitBtnLabel);
-submitBtn.x = 2048 / 2;
-submitBtn.y = wordInputText.y + 80;
submitBtn.down = function (x, y, obj) {
submitWord();
};
-game.addChild(submitBtn);
-// Reshuffle button (below grid)
reshuffleBtn = new ReshuffleButton();
-reshuffleBtn.x = 2048 / 2;
-reshuffleBtn.y = GRID_TOP + GRID_ROWS * (TILE_SIZE + TILE_GAP) + 80;
+// Position both buttons horizontally centered below the grid, with a gap between them
+var btnY = GRID_TOP + GRID_ROWS * (TILE_SIZE + TILE_GAP) + 80;
+var btnGap = 60;
+submitBtn.x = 2048 / 2 - 200 - btnGap / 2;
+submitBtn.y = btnY;
+reshuffleBtn.x = 2048 / 2 + 200 + btnGap / 2;
+reshuffleBtn.y = btnY;
+game.addChild(submitBtn);
game.addChild(reshuffleBtn);
// --- Build Letter Grid ---
for (var r = 0; r < GRID_ROWS; r++) {
letterTiles[r] = [];