/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.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. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } for (var i = 0; i < 26; i++) {} var GRID_ROWS = 8; var GRID_COLS = 8; var TILE_SIZE = 140; var TILE_GAP = 18; var GRID_TOP = 220; 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 = ''; // Load score from storage if available, otherwise 0 var score = typeof storage.score === "number" ? storage.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 _validWords; 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; } // Only give points if the word is correct (simple dictionary check) var validWords = (_validWords = { "CAT": true, "DOG": true, "TREE": true, "WORD": true, "GAME": true, "CODE": true, "BLUE": true, "GRID": true, "TILE": true, "ALPHA": true, "BETA": true, "DELTA": true, "OMEGA": true, "APPLE": true, "BANANA": true, "ORANGE": true, "PEAR": true, "PEACH": true, "PLUM": true, "MANGO": true, "BERRY": true, "LEMON": true, "LIME": true, "GRAPE": true, "CHERRY": true, "MELON": true, "KIWI": true, "PINE": true, "FISH": true, "BIRD": true, "LION": true, "TIGER": true, "BEAR": true, "WOLF": true, "FOX": true, "DEER": true, "MOUSE": true, "HORSE": true, "SHEEP": true, "GOAT": true, "DUCK": true, "SWAN": true, "CROW": true, "HAWK": true, "OWL": true, "FROG": true, "TOAD": true, "SNAKE": true, "SHARK": true, "WHALE": true, "CRAB": true, "ANT": true, "BEE": true, "BUG": true, "FLY": true, "MOTH": true, "WASP": true, "SPARROW": true, "ROBIN": true, "EAGLE": true, "DOVE": true, "FINCH": true, "COIN": true, "GOLD": true, "SILVER": true, "IRON": true, "STEEL": true, "BRONZE": true, "COPPER": true, "STONE": true, "ROCK": true, "SAND": true, "CLAY": true, "DIRT": true, "SOIL": true, "GRASS": true, "WEED": true, "FERN": true, "PALM": true, "OAK": true }, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "PINE", true), "MAPLE", true), "BIRCH", true), "ELM", true), "ASH", true), "YEW", true), "IVY", true), "ROSE", true), "LILY", true), "TULIP", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "DAISY", true), "VINE", true), "MOSS", true), "ROOT", true), "STEM", true), "LEAF", true), "BARK", true), "SEED", true), "NUT", true), "CONE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "BUD", true), "POD", true), "PEA", true), "BEAN", true), "CORN", true), "RICE", true), "OATS", true), "WHEAT", true), "RYE", true), "BARLEY", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SALT", true), "SUGAR", true), "SPICE", true), "HERB", true), "MINT", true), "BASIL", true), "THYME", true), "SAGE", true), "DILL", true), "ROSEMARY", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "GARLIC", true), "ONION", true), "CHIVE", true), "PEPPER", true), "CHILI", true), "CURRY", true), "GINGER", true), "CLOVE", true), "NUTMEG", true), "CINNAMON", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "VANILLA", true), "COCOA", true), "COFFEE", true), "TEA", true), "JUICE", true), "WATER", true), "MILK", true), "CREAM", true), "CHEESE", true), "BREAD", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "CAKE", true), "PIE", true), "TART", true), "ROLL", true), "BUN", true), "LOAF", true), "PASTA", true), "NOODLE", true), "SOUP", true), "STEW", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "BROTH", true), "SAUCE", true), "GRAVY", true), "DRESSING", true), "SALAD", true), "FRUIT", true), "VEG", true), "MEAT", true), "FISH", true), "EGG", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "YOLK", true), "WHITE", true), "SHELL", true), "BONE", true), "SKIN", true), "FUR", true), "HAIR", true), "WOOL", true), "FEATHER", true), "SCALE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "FIN", true), "TAIL", true), "HORN", true), "TUSK", true), "FANG", true), "CLAW", true), "PAW", true), "HOOF", true), "WING", true), "BEAK", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SNOUT", true), "JAW", true), "TOOTH", true), "EYE", true), "EAR", true), "NOSE", true), "MOUTH", true), "LIP", true), "TONGUE", true), "THROAT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "NECK", true), "BACK", true), "CHEST", true), "BELLY", true), "SIDE", true), "HIP", true), "LEG", true), "ARM", true), "HAND", true), "FOOT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "FINGER", true), "THUMB", true), "NAIL", true), "KNEE", true), "ELBOW", true), "SHOULDER", true), "WRIST", true), "ANKLE", true), "SPINE", true), "RIB", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "HEART", true), "LUNG", true), "LIVER", true), "KIDNEY", true), "BRAIN", true), "BLOOD", true), "VEIN", true), "BONE", true), "MUSCLE", true), "FAT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SKIN", true), "CELL", true), "GENE", true), "CODE", true), "WORD", true), "GAME", true), "PLAY", true), "WIN", true), "LOSE", true), "DRAW", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "TURN", true), "MOVE", true), "STEP", true), "JUMP", true), "RUN", true), "WALK", true), "SIT", true), "STAND", true), "LIE", true), "REST", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SLEEP", true), "WAKE", true), "DREAM", true), "THINK", true), "FEEL", true), "SEE", true), "HEAR", true), "SAY", true), "TELL", true), "ASK", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "ANSWER", true), "WRITE", true), "READ", true), "DRAW", true), "PAINT", true), "COLOR", true), "SHADE", true), "LINE", true), "DOT", true), "SPOT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "MARK", true), "SIGN", true), "NOTE", true), "LIST", true), "PAGE", true), "BOOK", true), "CARD", true), "TILE", true), "GRID", true), "ROW", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "COL", true), "BOX", true), "CUBE", true), "BALL", true), "DISC", true), "COIN", true), "RING", true), "BAND", true), "BELT", true), "CHAIN", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "ROPE", true), "CORD", true), "WIRE", true), "TUBE", true), "PIPE", true), "POLE", true), "STICK", true), "ROD", true), "BAR", true), "PLATE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SHEET", true), "SLAB", true), "BLOCK", true), "BRICK", true), "STONE", true), "ROCK", true), "PEBBLE", true), "SAND", true), "CLAY", true), "DIRT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SOIL", true), "MUD", true), "DUST", true), "ASH", true), "SMOKE", true), "FIRE", true), "FLAME", true), "HEAT", true), "LIGHT", true), "DARK", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SHADE", true), "SHADOW", true), "SUN", true), "MOON", true), "STAR", true), "SKY", true), "CLOUD", true), "RAIN", true), "SNOW", true), "HAIL", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "WIND", true), "BREEZE", true), "GALE", true), "STORM", true), "FOG", true), "MIST", true), "DEW", true), "ICE", true), "FROST", true), "COLD", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "COOL", true), "WARM", true), "HOT", true), "FREEZE", true), "MELT", true), "BOIL", true), "STEAM", true), "GAS", true), "AIR", true), "BREATH", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "VOICE", true), "SOUND", true), "NOISE", true), "MUSIC", true), "SONG", true), "TUNE", true), "RHYME", true), "VERSE", true), "POEM", true), "TALE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "STORY", true), "FABLE", true), "MYTH", true), "LEGEND", true), "HERO", true), "VILLAIN", true), "KING", true), "QUEEN", true), "PRINCE", true), "PRINCESS", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "DUKE", true), "LORD", true), "LADY", true), "KNIGHT", true), "PAGE", true), "SQUIRE", true), "WIZARD", true), "MAGE", true), "SORCERER", true), "WITCH", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "FAIRY", true), "ELF", true), "GNOME", true), "DWARF", true), "GIANT", true), "OGRE", true), "TROLL", true), "DRAGON", true), "WYVERN", true), "GRIFFIN", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "UNICORN", true), "PHOENIX", true), "MERMAID", true), "SATYR", true), "CENTAUR", true), "MINOTAUR", true), "SPHINX", true), "HYDRA", true), "BASILISK", true), "CHIMERA", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "MANTICORE", true), "GOBLIN", true), "ORC", true), "IMP", true), "DEMON", true), "DEVIL", true), "ANGEL", true), "SPIRIT", true), "GHOST", true), "WRAITH", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "ZOMBIE", true), "VAMPIRE", true), "MUMMY", true), "SKELETON", true), "LICH", true), "GOLEM", true), "ELEMENTAL", true), "DJINN", true), "GENIE", true), "TITAN", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "NYMPH", true), "DRYAD", true), "NAIAD", true), "SIREN", true), "HARPY", true), "BANSHEE", true), "KRAKEN", true), "LEVIATHAN", true), "CYCLOPS", true), "MEDUSA", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "MINION", true), "MONSTER", true), "BEAST", true), "CREATURE", true), "ANIMAL", true), "PLANT", true), "TREE", true), "BUSH", true), "GRASS", true), "FLOWER", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "FRUIT", true), "VEG", true), "ROOT", true), "SEED", true), "NUT", true), "BERRY", true), "LEAF", true), "BARK", true), "BRANCH", true), "TWIG", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "VINE", true), "MOSS", true), "FERN", true), "PALM", true), "OAK", true), "PINE", true), "MAPLE", true), "BIRCH", true), "ELM", true), "ASH", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "YEW", true), "IVY", true), "ROSE", true), "LILY", true), "TULIP", true), "DAISY", true), "VIOLET", true), "ORCHID", true), "LOTUS", true), "PEONY", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "IRIS", true), "POPPY", true), "SUNFLOWER", true), "DAFFODIL", true), "MARIGOLD", true), "CHRYSANTHEMUM", true), "AZALEA", true), "CAMELLIA", true), "MAGNOLIA", true), "HIBISCUS", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "JASMINE", true), "LAVENDER", true), "MINT", true), "BASIL", true), "THYME", true), "SAGE", true), "DILL", true), "ROSEMARY", true), "GARLIC", true), "ONION", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "CHIVE", true), "PEPPER", true), "CHILI", true), "CURRY", true), "GINGER", true), "CLOVE", true), "NUTMEG", true), "CINNAMON", true), "VANILLA", true), "COCOA", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "COFFEE", true), "TEA", true), "JUICE", true), "WATER", true), "MILK", true), "CREAM", true), "CHEESE", true), "BREAD", true), "CAKE", true), "PIE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "TART", true), "ROLL", true), "BUN", true), "LOAF", true), "PASTA", true), "NOODLE", true), "SOUP", true), "STEW", true), "BROTH", true), "SAUCE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "GRAVY", true), "DRESSING", true), "SALAD", true), "FRUIT", true), "VEG", true), "MEAT", true), "FISH", true), "EGG", true), "YOLK", true), "WHITE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SHELL", true), "BONE", true), "SKIN", true), "FUR", true), "HAIR", true), "WOOL", true), "FEATHER", true), "SCALE", true), "FIN", true), "TAIL", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "HORN", true), "TUSK", true), "FANG", true), "CLAW", true), "PAW", true), "HOOF", true), "WING", true), "BEAK", true), "SNOUT", true), "JAW", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "TOOTH", true), "EYE", true), "EAR", true), "NOSE", true), "MOUTH", true), "LIP", true), "TONGUE", true), "THROAT", true), "NECK", true), "BACK", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "CHEST", true), "BELLY", true), "SIDE", true), "HIP", true), "LEG", true), "ARM", true), "HAND", true), "FOOT", true), "FINGER", true), "THUMB", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "NAIL", true), "KNEE", true), "ELBOW", true), "SHOULDER", true), "WRIST", true), "ANKLE", true), "SPINE", true), "RIB", true), "HEART", true), "LUNG", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "LIVER", true), "KIDNEY", true), "BRAIN", true), "BLOOD", true), "VEIN", true), "BONE", true), "MUSCLE", true), "FAT", true), "SKIN", true), "CELL", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "GENE", true), "CODE", true), "WORD", true), "GAME", true)); if (!validWords[wordKey]) { LK.effects.flashObject(wordInputText, 0xff0000, 400); return; } usedWords[wordKey] = true; score += 1; scoreText.setText(score); // Save score to persistent storage storage.score = 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 --- // Timer display (top right) and word input display (center, above grid) are handled below // Submit, Unselect, 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(); }; // Unselect Button var unselectBtn = new Container(); var unselectBtnBg = unselectBtn.attachAsset('reshuffleBtn', { anchorX: 0.5, anchorY: 0.5 }); unselectBtnBg.width = 320; unselectBtnBg.height = 120; var unselectBtnLabel = new Text2('Unselect', { size: 60, fill: "#fff" }); unselectBtnLabel.anchor.set(0.5, 0.5); unselectBtn.addChild(unselectBtnLabel); unselectBtn.down = function (x, y, obj) { clearSelection(); }; reshuffleBtn = new ReshuffleButton(); // Position all three buttons horizontally centered below the grid, with a gap between them var btnY = GRID_TOP + GRID_ROWS * (TILE_SIZE + TILE_GAP) + 60; var btnGap = 60; submitBtn.x = 2048 / 2 - 350 - btnGap; submitBtn.y = btnY; unselectBtn.x = 2048 / 2; unselectBtn.y = btnY; reshuffleBtn.x = 2048 / 2 + 350 + btnGap; reshuffleBtn.y = btnY; game.addChild(submitBtn); game.addChild(unselectBtn); game.addChild(reshuffleBtn); // Score caption and display (centered, two rows below the submit button) var scoreCaption = new Text2('Score', { size: 70, fill: "#fff" }); scoreCaption.anchor.set(0.5, 0); // Place score caption two rows below the submit button var scoreRowY = btnY + 2 * (submitBtnBg.height + 30); scoreCaption.x = 2048 / 2; scoreCaption.y = scoreRowY; game.addChild(scoreCaption); scoreText = new Text2('0', { size: 120, fill: "#fff" }); scoreText.anchor.set(0.5, 0); scoreText.x = 2048 / 2; scoreText.y = scoreCaption.y + 80; game.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 - 30; game.addChild(wordInputText); // Submit, Unselect, 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(); }; // Unselect Button var unselectBtn = new Container(); var unselectBtnBg = unselectBtn.attachAsset('reshuffleBtn', { anchorX: 0.5, anchorY: 0.5 }); unselectBtnBg.width = 320; unselectBtnBg.height = 120; var unselectBtnLabel = new Text2('Unselect', { size: 60, fill: "#fff" }); unselectBtnLabel.anchor.set(0.5, 0.5); unselectBtn.addChild(unselectBtnLabel); unselectBtn.down = function (x, y, obj) { clearSelection(); }; reshuffleBtn = new ReshuffleButton(); // Position all three buttons horizontally centered below the grid, with a gap between them var btnY = GRID_TOP + GRID_ROWS * (TILE_SIZE + TILE_GAP) + 60; var btnGap = 60; submitBtn.x = 2048 / 2 - 350 - btnGap; submitBtn.y = btnY; unselectBtn.x = 2048 / 2; unselectBtn.y = btnY; reshuffleBtn.x = 2048 / 2 + 350 + btnGap; reshuffleBtn.y = btnY; game.addChild(submitBtn); game.addChild(unselectBtn); game.addChild(reshuffleBtn); // --- Build Letter Grid with blue background and grid lines --- // Draw blue background behind the grid var gridBg = LK.getAsset('letterTile_A', { anchorX: 0, anchorY: 0, x: GRID_LEFT - TILE_GAP / 2, y: GRID_TOP - TILE_GAP / 2, width: GRID_COLS * TILE_SIZE + (GRID_COLS - 1) * TILE_GAP + TILE_GAP, height: GRID_ROWS * TILE_SIZE + (GRID_ROWS - 1) * TILE_GAP + TILE_GAP, color: 0x1e3a7a // blue color }); game.addChild(gridBg); letterTiles = []; 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; // Draw grid lines (vertical and horizontal) using thin box assets // Vertical line (except last column) if (c < GRID_COLS - 1) { var vLine = LK.getAsset('letterTile_A', { anchorX: 0.5, anchorY: 0.5, width: TILE_GAP, height: TILE_SIZE, color: 0xffffff, x: tile.x + (TILE_SIZE + TILE_GAP) / 2, y: tile.y }); vLine.alpha = 0.25; game.addChild(vLine); } // Horizontal line (except last row) if (r < GRID_ROWS - 1) { var hLine = LK.getAsset('letterTile_A', { anchorX: 0.5, anchorY: 0.5, width: TILE_SIZE, height: TILE_GAP, color: 0xffffff, x: tile.x, y: tile.y + (TILE_SIZE + TILE_GAP) / 2 }); hLine.alpha = 0.25; game.addChild(hLine); } } } fillGrid(); // Play background music (loops by default) LK.playMusic('bgmusic'); // --- 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); // Optionally reset score in storage for new game session storage.score = 0; };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.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.
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
for (var i = 0; i < 26; i++) {}
var GRID_ROWS = 8;
var GRID_COLS = 8;
var TILE_SIZE = 140;
var TILE_GAP = 18;
var GRID_TOP = 220;
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 = '';
// Load score from storage if available, otherwise 0
var score = typeof storage.score === "number" ? storage.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 _validWords;
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;
}
// Only give points if the word is correct (simple dictionary check)
var validWords = (_validWords = {
"CAT": true,
"DOG": true,
"TREE": true,
"WORD": true,
"GAME": true,
"CODE": true,
"BLUE": true,
"GRID": true,
"TILE": true,
"ALPHA": true,
"BETA": true,
"DELTA": true,
"OMEGA": true,
"APPLE": true,
"BANANA": true,
"ORANGE": true,
"PEAR": true,
"PEACH": true,
"PLUM": true,
"MANGO": true,
"BERRY": true,
"LEMON": true,
"LIME": true,
"GRAPE": true,
"CHERRY": true,
"MELON": true,
"KIWI": true,
"PINE": true,
"FISH": true,
"BIRD": true,
"LION": true,
"TIGER": true,
"BEAR": true,
"WOLF": true,
"FOX": true,
"DEER": true,
"MOUSE": true,
"HORSE": true,
"SHEEP": true,
"GOAT": true,
"DUCK": true,
"SWAN": true,
"CROW": true,
"HAWK": true,
"OWL": true,
"FROG": true,
"TOAD": true,
"SNAKE": true,
"SHARK": true,
"WHALE": true,
"CRAB": true,
"ANT": true,
"BEE": true,
"BUG": true,
"FLY": true,
"MOTH": true,
"WASP": true,
"SPARROW": true,
"ROBIN": true,
"EAGLE": true,
"DOVE": true,
"FINCH": true,
"COIN": true,
"GOLD": true,
"SILVER": true,
"IRON": true,
"STEEL": true,
"BRONZE": true,
"COPPER": true,
"STONE": true,
"ROCK": true,
"SAND": true,
"CLAY": true,
"DIRT": true,
"SOIL": true,
"GRASS": true,
"WEED": true,
"FERN": true,
"PALM": true,
"OAK": true
}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "PINE", true), "MAPLE", true), "BIRCH", true), "ELM", true), "ASH", true), "YEW", true), "IVY", true), "ROSE", true), "LILY", true), "TULIP", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "DAISY", true), "VINE", true), "MOSS", true), "ROOT", true), "STEM", true), "LEAF", true), "BARK", true), "SEED", true), "NUT", true), "CONE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "BUD", true), "POD", true), "PEA", true), "BEAN", true), "CORN", true), "RICE", true), "OATS", true), "WHEAT", true), "RYE", true), "BARLEY", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SALT", true), "SUGAR", true), "SPICE", true), "HERB", true), "MINT", true), "BASIL", true), "THYME", true), "SAGE", true), "DILL", true), "ROSEMARY", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "GARLIC", true), "ONION", true), "CHIVE", true), "PEPPER", true), "CHILI", true), "CURRY", true), "GINGER", true), "CLOVE", true), "NUTMEG", true), "CINNAMON", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "VANILLA", true), "COCOA", true), "COFFEE", true), "TEA", true), "JUICE", true), "WATER", true), "MILK", true), "CREAM", true), "CHEESE", true), "BREAD", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "CAKE", true), "PIE", true), "TART", true), "ROLL", true), "BUN", true), "LOAF", true), "PASTA", true), "NOODLE", true), "SOUP", true), "STEW", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "BROTH", true), "SAUCE", true), "GRAVY", true), "DRESSING", true), "SALAD", true), "FRUIT", true), "VEG", true), "MEAT", true), "FISH", true), "EGG", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "YOLK", true), "WHITE", true), "SHELL", true), "BONE", true), "SKIN", true), "FUR", true), "HAIR", true), "WOOL", true), "FEATHER", true), "SCALE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "FIN", true), "TAIL", true), "HORN", true), "TUSK", true), "FANG", true), "CLAW", true), "PAW", true), "HOOF", true), "WING", true), "BEAK", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SNOUT", true), "JAW", true), "TOOTH", true), "EYE", true), "EAR", true), "NOSE", true), "MOUTH", true), "LIP", true), "TONGUE", true), "THROAT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "NECK", true), "BACK", true), "CHEST", true), "BELLY", true), "SIDE", true), "HIP", true), "LEG", true), "ARM", true), "HAND", true), "FOOT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "FINGER", true), "THUMB", true), "NAIL", true), "KNEE", true), "ELBOW", true), "SHOULDER", true), "WRIST", true), "ANKLE", true), "SPINE", true), "RIB", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "HEART", true), "LUNG", true), "LIVER", true), "KIDNEY", true), "BRAIN", true), "BLOOD", true), "VEIN", true), "BONE", true), "MUSCLE", true), "FAT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SKIN", true), "CELL", true), "GENE", true), "CODE", true), "WORD", true), "GAME", true), "PLAY", true), "WIN", true), "LOSE", true), "DRAW", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "TURN", true), "MOVE", true), "STEP", true), "JUMP", true), "RUN", true), "WALK", true), "SIT", true), "STAND", true), "LIE", true), "REST", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SLEEP", true), "WAKE", true), "DREAM", true), "THINK", true), "FEEL", true), "SEE", true), "HEAR", true), "SAY", true), "TELL", true), "ASK", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "ANSWER", true), "WRITE", true), "READ", true), "DRAW", true), "PAINT", true), "COLOR", true), "SHADE", true), "LINE", true), "DOT", true), "SPOT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "MARK", true), "SIGN", true), "NOTE", true), "LIST", true), "PAGE", true), "BOOK", true), "CARD", true), "TILE", true), "GRID", true), "ROW", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "COL", true), "BOX", true), "CUBE", true), "BALL", true), "DISC", true), "COIN", true), "RING", true), "BAND", true), "BELT", true), "CHAIN", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "ROPE", true), "CORD", true), "WIRE", true), "TUBE", true), "PIPE", true), "POLE", true), "STICK", true), "ROD", true), "BAR", true), "PLATE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SHEET", true), "SLAB", true), "BLOCK", true), "BRICK", true), "STONE", true), "ROCK", true), "PEBBLE", true), "SAND", true), "CLAY", true), "DIRT", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SOIL", true), "MUD", true), "DUST", true), "ASH", true), "SMOKE", true), "FIRE", true), "FLAME", true), "HEAT", true), "LIGHT", true), "DARK", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SHADE", true), "SHADOW", true), "SUN", true), "MOON", true), "STAR", true), "SKY", true), "CLOUD", true), "RAIN", true), "SNOW", true), "HAIL", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "WIND", true), "BREEZE", true), "GALE", true), "STORM", true), "FOG", true), "MIST", true), "DEW", true), "ICE", true), "FROST", true), "COLD", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "COOL", true), "WARM", true), "HOT", true), "FREEZE", true), "MELT", true), "BOIL", true), "STEAM", true), "GAS", true), "AIR", true), "BREATH", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "VOICE", true), "SOUND", true), "NOISE", true), "MUSIC", true), "SONG", true), "TUNE", true), "RHYME", true), "VERSE", true), "POEM", true), "TALE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "STORY", true), "FABLE", true), "MYTH", true), "LEGEND", true), "HERO", true), "VILLAIN", true), "KING", true), "QUEEN", true), "PRINCE", true), "PRINCESS", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "DUKE", true), "LORD", true), "LADY", true), "KNIGHT", true), "PAGE", true), "SQUIRE", true), "WIZARD", true), "MAGE", true), "SORCERER", true), "WITCH", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "FAIRY", true), "ELF", true), "GNOME", true), "DWARF", true), "GIANT", true), "OGRE", true), "TROLL", true), "DRAGON", true), "WYVERN", true), "GRIFFIN", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "UNICORN", true), "PHOENIX", true), "MERMAID", true), "SATYR", true), "CENTAUR", true), "MINOTAUR", true), "SPHINX", true), "HYDRA", true), "BASILISK", true), "CHIMERA", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "MANTICORE", true), "GOBLIN", true), "ORC", true), "IMP", true), "DEMON", true), "DEVIL", true), "ANGEL", true), "SPIRIT", true), "GHOST", true), "WRAITH", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "ZOMBIE", true), "VAMPIRE", true), "MUMMY", true), "SKELETON", true), "LICH", true), "GOLEM", true), "ELEMENTAL", true), "DJINN", true), "GENIE", true), "TITAN", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "NYMPH", true), "DRYAD", true), "NAIAD", true), "SIREN", true), "HARPY", true), "BANSHEE", true), "KRAKEN", true), "LEVIATHAN", true), "CYCLOPS", true), "MEDUSA", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "MINION", true), "MONSTER", true), "BEAST", true), "CREATURE", true), "ANIMAL", true), "PLANT", true), "TREE", true), "BUSH", true), "GRASS", true), "FLOWER", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "FRUIT", true), "VEG", true), "ROOT", true), "SEED", true), "NUT", true), "BERRY", true), "LEAF", true), "BARK", true), "BRANCH", true), "TWIG", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "VINE", true), "MOSS", true), "FERN", true), "PALM", true), "OAK", true), "PINE", true), "MAPLE", true), "BIRCH", true), "ELM", true), "ASH", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "YEW", true), "IVY", true), "ROSE", true), "LILY", true), "TULIP", true), "DAISY", true), "VIOLET", true), "ORCHID", true), "LOTUS", true), "PEONY", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "IRIS", true), "POPPY", true), "SUNFLOWER", true), "DAFFODIL", true), "MARIGOLD", true), "CHRYSANTHEMUM", true), "AZALEA", true), "CAMELLIA", true), "MAGNOLIA", true), "HIBISCUS", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "JASMINE", true), "LAVENDER", true), "MINT", true), "BASIL", true), "THYME", true), "SAGE", true), "DILL", true), "ROSEMARY", true), "GARLIC", true), "ONION", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "CHIVE", true), "PEPPER", true), "CHILI", true), "CURRY", true), "GINGER", true), "CLOVE", true), "NUTMEG", true), "CINNAMON", true), "VANILLA", true), "COCOA", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "COFFEE", true), "TEA", true), "JUICE", true), "WATER", true), "MILK", true), "CREAM", true), "CHEESE", true), "BREAD", true), "CAKE", true), "PIE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "TART", true), "ROLL", true), "BUN", true), "LOAF", true), "PASTA", true), "NOODLE", true), "SOUP", true), "STEW", true), "BROTH", true), "SAUCE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "GRAVY", true), "DRESSING", true), "SALAD", true), "FRUIT", true), "VEG", true), "MEAT", true), "FISH", true), "EGG", true), "YOLK", true), "WHITE", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "SHELL", true), "BONE", true), "SKIN", true), "FUR", true), "HAIR", true), "WOOL", true), "FEATHER", true), "SCALE", true), "FIN", true), "TAIL", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "HORN", true), "TUSK", true), "FANG", true), "CLAW", true), "PAW", true), "HOOF", true), "WING", true), "BEAK", true), "SNOUT", true), "JAW", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "TOOTH", true), "EYE", true), "EAR", true), "NOSE", true), "MOUTH", true), "LIP", true), "TONGUE", true), "THROAT", true), "NECK", true), "BACK", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "CHEST", true), "BELLY", true), "SIDE", true), "HIP", true), "LEG", true), "ARM", true), "HAND", true), "FOOT", true), "FINGER", true), "THUMB", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "NAIL", true), "KNEE", true), "ELBOW", true), "SHOULDER", true), "WRIST", true), "ANKLE", true), "SPINE", true), "RIB", true), "HEART", true), "LUNG", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "LIVER", true), "KIDNEY", true), "BRAIN", true), "BLOOD", true), "VEIN", true), "BONE", true), "MUSCLE", true), "FAT", true), "SKIN", true), "CELL", true), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_validWords, "GENE", true), "CODE", true), "WORD", true), "GAME", true));
if (!validWords[wordKey]) {
LK.effects.flashObject(wordInputText, 0xff0000, 400);
return;
}
usedWords[wordKey] = true;
score += 1;
scoreText.setText(score);
// Save score to persistent storage
storage.score = 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 ---
// Timer display (top right) and word input display (center, above grid) are handled below
// Submit, Unselect, 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();
};
// Unselect Button
var unselectBtn = new Container();
var unselectBtnBg = unselectBtn.attachAsset('reshuffleBtn', {
anchorX: 0.5,
anchorY: 0.5
});
unselectBtnBg.width = 320;
unselectBtnBg.height = 120;
var unselectBtnLabel = new Text2('Unselect', {
size: 60,
fill: "#fff"
});
unselectBtnLabel.anchor.set(0.5, 0.5);
unselectBtn.addChild(unselectBtnLabel);
unselectBtn.down = function (x, y, obj) {
clearSelection();
};
reshuffleBtn = new ReshuffleButton();
// Position all three buttons horizontally centered below the grid, with a gap between them
var btnY = GRID_TOP + GRID_ROWS * (TILE_SIZE + TILE_GAP) + 60;
var btnGap = 60;
submitBtn.x = 2048 / 2 - 350 - btnGap;
submitBtn.y = btnY;
unselectBtn.x = 2048 / 2;
unselectBtn.y = btnY;
reshuffleBtn.x = 2048 / 2 + 350 + btnGap;
reshuffleBtn.y = btnY;
game.addChild(submitBtn);
game.addChild(unselectBtn);
game.addChild(reshuffleBtn);
// Score caption and display (centered, two rows below the submit button)
var scoreCaption = new Text2('Score', {
size: 70,
fill: "#fff"
});
scoreCaption.anchor.set(0.5, 0);
// Place score caption two rows below the submit button
var scoreRowY = btnY + 2 * (submitBtnBg.height + 30);
scoreCaption.x = 2048 / 2;
scoreCaption.y = scoreRowY;
game.addChild(scoreCaption);
scoreText = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreText.anchor.set(0.5, 0);
scoreText.x = 2048 / 2;
scoreText.y = scoreCaption.y + 80;
game.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 - 30;
game.addChild(wordInputText);
// Submit, Unselect, 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();
};
// Unselect Button
var unselectBtn = new Container();
var unselectBtnBg = unselectBtn.attachAsset('reshuffleBtn', {
anchorX: 0.5,
anchorY: 0.5
});
unselectBtnBg.width = 320;
unselectBtnBg.height = 120;
var unselectBtnLabel = new Text2('Unselect', {
size: 60,
fill: "#fff"
});
unselectBtnLabel.anchor.set(0.5, 0.5);
unselectBtn.addChild(unselectBtnLabel);
unselectBtn.down = function (x, y, obj) {
clearSelection();
};
reshuffleBtn = new ReshuffleButton();
// Position all three buttons horizontally centered below the grid, with a gap between them
var btnY = GRID_TOP + GRID_ROWS * (TILE_SIZE + TILE_GAP) + 60;
var btnGap = 60;
submitBtn.x = 2048 / 2 - 350 - btnGap;
submitBtn.y = btnY;
unselectBtn.x = 2048 / 2;
unselectBtn.y = btnY;
reshuffleBtn.x = 2048 / 2 + 350 + btnGap;
reshuffleBtn.y = btnY;
game.addChild(submitBtn);
game.addChild(unselectBtn);
game.addChild(reshuffleBtn);
// --- Build Letter Grid with blue background and grid lines ---
// Draw blue background behind the grid
var gridBg = LK.getAsset('letterTile_A', {
anchorX: 0,
anchorY: 0,
x: GRID_LEFT - TILE_GAP / 2,
y: GRID_TOP - TILE_GAP / 2,
width: GRID_COLS * TILE_SIZE + (GRID_COLS - 1) * TILE_GAP + TILE_GAP,
height: GRID_ROWS * TILE_SIZE + (GRID_ROWS - 1) * TILE_GAP + TILE_GAP,
color: 0x1e3a7a // blue color
});
game.addChild(gridBg);
letterTiles = [];
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;
// Draw grid lines (vertical and horizontal) using thin box assets
// Vertical line (except last column)
if (c < GRID_COLS - 1) {
var vLine = LK.getAsset('letterTile_A', {
anchorX: 0.5,
anchorY: 0.5,
width: TILE_GAP,
height: TILE_SIZE,
color: 0xffffff,
x: tile.x + (TILE_SIZE + TILE_GAP) / 2,
y: tile.y
});
vLine.alpha = 0.25;
game.addChild(vLine);
}
// Horizontal line (except last row)
if (r < GRID_ROWS - 1) {
var hLine = LK.getAsset('letterTile_A', {
anchorX: 0.5,
anchorY: 0.5,
width: TILE_SIZE,
height: TILE_GAP,
color: 0xffffff,
x: tile.x,
y: tile.y + (TILE_SIZE + TILE_GAP) / 2
});
hLine.alpha = 0.25;
game.addChild(hLine);
}
}
}
fillGrid();
// Play background music (loops by default)
LK.playMusic('bgmusic');
// --- 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);
// Optionally reset score in storage for new game session
storage.score = 0;
};