/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Hangman drawing class var HangmanDrawing = Container.expand(function () { var self = Container.call(this); // Gallows var base = self.attachAsset('gallows_base', { anchorX: 0.5, anchorY: 1, x: 0, y: 0 }); var pole = self.attachAsset('gallows_pole', { anchorX: 0.5, anchorY: 1, x: 0, y: -base.height }); // Create beam first at a temporary position to access its dimensions var beam = self.attachAsset('gallows_beam', { anchorX: 0, anchorY: 1, x: 0, y: 0 }); // Now set the correct position using pole and base dimensions beam.x = pole.width / 2; beam.y = -base.height - pole.height + beam.height / 2; var rope = self.attachAsset('gallows_rope', { anchorX: 0.5, anchorY: 0, x: beam.x + beam.width - 40, y: beam.y - beam.height / 2 }); // Hangman parts (hidden initially) var head = self.attachAsset('hangman_head', { anchorX: 0.5, anchorY: 0, x: rope.x, y: rope.y + rope.height }); var body = self.attachAsset('hangman_body', { anchorX: 0.5, anchorY: 0, x: head.x, y: head.y + head.height }); var leftArm = self.attachAsset('hangman_arm', { anchorX: 1, anchorY: 0.5, x: body.x, y: body.y + body.height * 0.2, rotation: -Math.PI / 4 }); var rightArm = self.attachAsset('hangman_arm', { anchorX: 0, anchorY: 0.5, x: body.x, y: body.y + body.height * 0.2, rotation: Math.PI / 4 }); var leftLeg = self.attachAsset('hangman_leg', { anchorX: 1, anchorY: 0.5, x: body.x, y: body.y + body.height, rotation: -Math.PI / 4 }); var rightLeg = self.attachAsset('hangman_leg', { anchorX: 0, anchorY: 0.5, x: body.x, y: body.y + body.height, rotation: Math.PI / 4 }); // Store parts in order of appearance self.parts = [head, body, leftArm, rightArm, leftLeg, rightLeg]; // Hide all hangman parts initially for (var i = 0; i < self.parts.length; ++i) { self.parts[i].visible = false; } // Show up to n parts self.showParts = function (n) { for (var i = 0; i < self.parts.length; ++i) { self.parts[i].visible = i < n; } }; // Reset drawing self.reset = function () { self.showParts(0); }; return self; }); // Letter button class with beautiful layered design var LetterButton = Container.expand(function () { var self = Container.call(this); // Default: not used self.used = false; self.letter = ''; self.isPressed = false; // Create layered button appearance var btnBg = self.attachAsset('letter_btn_bg', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0 }); var btnMain = self.attachAsset('letter_btn_main', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -2 }); var btnHighlight = self.attachAsset('letter_btn_highlight', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -4 }); // Store original positions for animation self.originalY = self.y; btnMain.originalY = btnMain.y; btnHighlight.originalY = btnHighlight.y; // Letter text with shadow effect var txtShadow = new Text2('', { size: 68, fill: '#000044' }); txtShadow.anchor.set(0.5, 0.5); txtShadow.x = 2; txtShadow.y = 2; self.addChild(txtShadow); var txt = new Text2('', { size: 68, fill: '#ffffff' }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = -2; self.addChild(txt); // Set letter self.setLetter = function (letter) { self.letter = letter; txt.setText(letter); txtShadow.setText(letter); }; // Mark as used with smooth transition self.setUsed = function () { self.used = true; // Animate button press and fade tween(self, { y: self.y + 6 }, { duration: 150 }); tween(btnMain, { y: btnMain.y + 4 }, { duration: 150 }); tween(btnHighlight, { y: btnHighlight.y + 6 }, { duration: 150 }); tween(txt, { y: txt.y + 4 }, { duration: 150 }); tween(txtShadow, { y: txtShadow.y + 4 }, { duration: 150 }); // After animation, replace with used appearance LK.setTimeout(function () { btnBg.destroy(); btnMain.destroy(); btnHighlight.destroy(); var usedBg = self.attachAsset('letter_btn_used_bg', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 6 }); var usedMain = self.attachAsset('letter_btn_used_main', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 4 }); var usedHighlight = self.attachAsset('letter_btn_used_highlight', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 2 }); txt.fill = '#aaaaaa'; txtShadow.fill = '#333333'; }, 150); }; // Touch events with press animation self.down = function (x, y, obj) { if (self.used || self.isPressed) { return; } self.isPressed = true; // Play button press sound LK.getSound('button').play(); // Animate button press tween(self, { y: self.y + 4 }, { duration: 100 }); tween(btnMain, { y: btnMain.y + 2 }, { duration: 100 }); tween(btnHighlight, { y: btnHighlight.y + 4 }, { duration: 100 }); tween(txt, { y: txt.y + 2 }, { duration: 100 }); tween(txtShadow, { y: txtShadow.y + 2 }, { duration: 100 }); }; self.up = function (x, y, obj) { if (self.used || !self.isPressed) { return; } self.isPressed = false; // Animate button release tween(self, { y: self.originalY }, { duration: 100 }); tween(btnMain, { y: btnMain.originalY }, { duration: 100 }); tween(btnHighlight, { y: btnHighlight.originalY }, { duration: 100 }); tween(txt, { y: txt.y - 2 }, { duration: 100 }); tween(txtShadow, { y: txtShadow.y - 2 }, { duration: 100 }); if (typeof self.onSelect === 'function') { self.onSelect(self.letter, self); } }; return self; }); // Subject selection button class var SubjectButton = Container.expand(function () { var self = Container.call(this); self.subject = ''; self.isPressed = false; // Create layered button appearance var btnBg = self.attachAsset('letter_btn_bg', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, scaleX: 2.5, scaleY: 1.5 }); var btnMain = self.attachAsset('letter_btn_main', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -2, scaleX: 2.4, scaleY: 1.4 }); var btnHighlight = self.attachAsset('letter_btn_highlight', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -4, scaleX: 2.3, scaleY: 1.3 }); // Store original positions for animation self.originalY = self.y; btnMain.originalY = btnMain.y; btnHighlight.originalY = btnHighlight.y; // Subject text var txt = new Text2('', { size: 80, fill: '#ffffff' }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = -2; self.addChild(txt); // Set subject self.setSubject = function (subject) { self.subject = subject; txt.setText(subject); }; // Touch events self.down = function (x, y, obj) { if (self.isPressed) { return; } self.isPressed = true; // Play button press sound LK.getSound('button').play(); // Animate button press tween(self, { y: self.y + 4 }, { duration: 100 }); tween(btnMain, { y: btnMain.y + 2 }, { duration: 100 }); tween(btnHighlight, { y: btnHighlight.y + 4 }, { duration: 100 }); tween(txt, { y: txt.y + 2 }, { duration: 100 }); }; self.up = function (x, y, obj) { if (!self.isPressed) { return; } self.isPressed = false; // Animate button release tween(self, { y: self.originalY }, { duration: 100 }); tween(btnMain, { y: btnMain.originalY }, { duration: 100 }); tween(btnHighlight, { y: btnHighlight.originalY }, { duration: 100 }); tween(txt, { y: txt.y - 2 }, { duration: 100 }); if (typeof self.onSelect === 'function') { self.onSelect(self.subject); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222244 }); /**** * Game Code ****/ // Letter button asset // Hangman parts: head, body, left arm, right arm, left leg, right leg, gallows base, pole, beam, rope // Word lists organized by subjects var WORD_LISTS = { "FRUITS": ["APPLE", "BANANA", "ORANGE", "GRAPE", "MANGO", "PEACH", "BERRY", "LEMON", "MELON", "CHERRY"], "ANIMALS": ["ELEPHANT", "MONKEY", "ZEBRA", "KANGAROO", "FROG", "TIGER", "WHALE", "RABBIT", "HORSE", "DOLPHIN"], "OBJECTS": ["GUITAR", "ROCKET", "PLANET", "BICYCLE", "CIRCUS", "DIAMOND", "UMBRELLA", "CAMERA", "LAPTOP", "PHONE"], "COLORS": ["VIOLET", "PURPLE", "YELLOW", "ORANGE", "SILVER", "GOLDEN", "CRIMSON", "EMERALD", "AZURE", "CORAL"], "FOOD": ["HAMBURGER", "PIZZA", "SANDWICH", "COOKIE", "PASTA", "SALAD", "SOUP", "BREAD", "CHEESE", "BUTTER"], "NATURE": ["ISLAND", "MOUNTAIN", "FOREST", "OCEAN", "DESERT", "RIVER", "VALLEY", "VOLCANO", "MEADOW", "CANYON"] }; // Current selected subject and word list var selectedSubject = ''; var currentWordList = []; // Game state variables var currentWord = ''; var revealed = []; var wrongGuesses = 0; var maxWrong = 6; // 6 hangman parts var guessedLetters = []; var correctLetters = []; var wrongLetters = []; var letterButtons = []; var hangmanDrawing = null; var wordDisplay = null; var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(''); var wordY = 650; var hangmanX = 200; var hangmanY = 900; var letterGridY = 1800; var claudeHelpUsed = false; // Track if Claude help has been used this game var gameStarted = false; // Track if game has started var subjectButtons = []; // Array to hold subject selection buttons var subjectSelectionContainer = null; // Container for subject selection UI // Score display (win/loss count) var winCount = 0; var lossCount = 0; var winTxt = new Text2('Wins 0', { size: 100, fill: '#00ff88', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); winTxt.anchor.set(0, 0); LK.gui.top.addChild(winTxt); var lossTxt = new Text2('Losses 0', { size: 100, fill: '#ff4444', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); lossTxt.anchor.set(1, 0); LK.gui.topRight.addChild(lossTxt); // Helper: pick a random word from selected subject function pickWord() { var words = currentWordList.length > 0 ? currentWordList : WORD_LISTS["OBJECTS"]; var idx = Math.floor(Math.random() * words.length); return words[idx]; } // Helper: update word display function updateWordDisplay() { var s = ''; for (var i = 0; i < revealed.length; ++i) { s += revealed[i] ? currentWord[i] : '_'; if (i < revealed.length - 1) { s += ' '; } } wordDisplay.setText(s); } // Helper: update win/loss text function updateScoreDisplay() { winTxt.setText('Wins ' + winCount); lossTxt.setText('Losses ' + lossCount); } // Helper: update letter displays function updateLetterDisplays() { var correctText = ''; for (var i = 0; i < correctLetters.length; ++i) { correctText += correctLetters[i]; if (i < correctLetters.length - 1) { correctText += ' '; } } correctLettersText.setText(correctText || '---'); var wrongText = ''; for (var i = 0; i < wrongLetters.length; ++i) { wrongText += wrongLetters[i]; if (i < wrongLetters.length - 1) { wrongText += ' '; } } wrongLettersText.setText(wrongText || '---'); } // Create subject selection screen function showSubjectSelection() { gameStarted = false; // Hide game elements hangmanDrawing.visible = false; subjectDisplay.visible = false; wordDisplay.visible = false; correctLettersDisplay.visible = false; wrongLettersDisplay.visible = false; correctLettersText.visible = false; wrongLettersText.visible = false; claudeHelpBtn.visible = false; // Hide any existing letter buttons for (var i = 0; i < letterButtons.length; ++i) { letterButtons[i].visible = false; } // Create subject selection container if (subjectSelectionContainer) { subjectSelectionContainer.destroy(); } subjectSelectionContainer = new Container(); game.addChild(subjectSelectionContainer); // Title var titleText = new Text2('Choose a Subject', { size: 150, fill: '#ffff99' }); titleText.anchor.set(0.5, 0.5); titleText.x = 2048 / 2; titleText.y = 400; subjectSelectionContainer.addChild(titleText); // Add Random mode button first var randomBtn = new SubjectButton(); randomBtn.setSubject('RANDOM'); randomBtn.x = 2048 / 2; randomBtn.y = 700; randomBtn.originalY = randomBtn.y; randomBtn.onSelect = function (selectedSubjectName) { selectedSubject = 'RANDOM'; // Create combined word list from all subjects currentWordList = []; var allSubjects = Object.keys(WORD_LISTS); for (var s = 0; s < allSubjects.length; ++s) { var subjectWords = WORD_LISTS[allSubjects[s]]; for (var w = 0; w < subjectWords.length; ++w) { currentWordList.push(subjectWords[w]); } } hideSubjectSelection(); startGame(); }; subjectSelectionContainer.addChild(randomBtn); subjectButtons.push(randomBtn); // Create subject buttons var subjects = Object.keys(WORD_LISTS); var buttonsPerRow = 3; var buttonSpacingX = 350; var buttonSpacingY = 200; var startY = 900; for (var i = 0; i < subjects.length; ++i) { var subject = subjects[i]; var row = Math.floor(i / buttonsPerRow); var col = i % buttonsPerRow; var rowWidth = Math.min(buttonsPerRow, subjects.length - row * buttonsPerRow) * buttonSpacingX; var startX = (2048 - rowWidth) / 2 + buttonSpacingX / 2; var btn = new SubjectButton(); btn.setSubject(subject); btn.x = startX + col * buttonSpacingX; btn.y = startY + row * buttonSpacingY; btn.originalY = btn.y; btn.onSelect = function (selectedSubjectName) { selectedSubject = selectedSubjectName; currentWordList = WORD_LISTS[selectedSubjectName]; hideSubjectSelection(); startGame(); }; subjectSelectionContainer.addChild(btn); subjectButtons.push(btn); } } // Hide subject selection screen function hideSubjectSelection() { if (subjectSelectionContainer) { subjectSelectionContainer.destroy(); subjectSelectionContainer = null; } subjectButtons = []; // Show game elements hangmanDrawing.visible = true; subjectDisplay.visible = true; wordDisplay.visible = true; correctLettersDisplay.visible = true; wrongLettersDisplay.visible = true; correctLettersText.visible = true; wrongLettersText.visible = true; claudeHelpBtn.visible = true; gameStarted = true; } // Start a new game function startGame() { // Remove old letter buttons for (var i = 0; i < letterButtons.length; ++i) { letterButtons[i].destroy(); } letterButtons = []; guessedLetters = []; correctLetters = []; wrongLetters = []; wrongGuesses = 0; claudeHelpUsed = false; // Reset Claude help for new game // Pick word currentWord = pickWord(); revealed = []; for (var i = 0; i < currentWord.length; ++i) { revealed.push(false); } // Set subject/category text based on selected subject var subject = selectedSubject || "OBJECTS"; if (selectedSubject === 'RANDOM') { // In random mode, find which subject the current word belongs to var actualSubject = "UNKNOWN"; var allSubjects = Object.keys(WORD_LISTS); for (var s = 0; s < allSubjects.length; ++s) { var subjectWords = WORD_LISTS[allSubjects[s]]; if (subjectWords.indexOf(currentWord) !== -1) { actualSubject = allSubjects[s]; break; } } subjectDisplay.setText("Subject: " + actualSubject + " (Random Mode)"); } else { subjectDisplay.setText("Subject: " + subject); } // Update word display updateWordDisplay(); // Reset hangman hangmanDrawing.reset(); // Create beautiful keyboard layout (A-Z, optimized rows) var keyboardRows = [['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'], ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'], ['Z', 'X', 'C', 'V', 'B', 'N', 'M']]; var btnSize = 140; var spacingX = 20; var spacingY = 25; var startY = letterGridY; for (var row = 0; row < keyboardRows.length; ++row) { var rowLetters = keyboardRows[row]; var rowWidth = rowLetters.length * btnSize + (rowLetters.length - 1) * spacingX; var startX = (2048 - rowWidth) / 2 + btnSize / 2; // Offset middle and bottom rows slightly for natural keyboard feel if (row === 1) { startX += btnSize / 4; } if (row === 2) { startX += btnSize / 2; } for (var col = 0; col < rowLetters.length; ++col) { var btn = new LetterButton(); btn.setLetter(rowLetters[col]); btn.x = startX + col * (btnSize + spacingX); btn.y = startY + row * (btnSize + spacingY); btn.originalY = btn.y; // Letter select handler btn.onSelect = onLetterSelected; game.addChild(btn); letterButtons.push(btn); } } } // Letter selected handler function onLetterSelected(letter, btn) { // Mark as used btn.setUsed(); guessedLetters.push(letter); // Check if letter is in word var found = false; for (var i = 0; i < currentWord.length; ++i) { if (currentWord[i] === letter) { revealed[i] = true; found = true; } } updateWordDisplay(); if (found) { // Add to correct letters correctLetters.push(letter); // Play correct letter sound LK.getSound('correct').play(); // Check win var allRevealed = true; for (var i = 0; i < revealed.length; ++i) { if (!revealed[i]) { allRevealed = false; break; } } if (allRevealed) { winCount += 1; updateScoreDisplay(); LK.effects.flashScreen(0x00ff00, 800); // Play win sound LK.getSound('win').play(); LK.showYouWin(); } } else { // Wrong guess wrongLetters.push(letter); wrongGuesses += 1; // Play wrong letter sound LK.getSound('wrong').play(); hangmanDrawing.showParts(wrongGuesses); if (wrongGuesses >= maxWrong) { lossCount += 1; updateScoreDisplay(); LK.effects.flashScreen(0xff0000, 800); // Play game over sound LK.getSound('gameover').play(); // Reveal word for (var i = 0; i < revealed.length; ++i) { revealed[i] = true; } updateWordDisplay(); // Death animation for hangman // Animate the head tilting (death pose) tween(hangmanDrawing.parts[0], { rotation: Math.PI / 6 // Tilt head to the right }, { duration: 800, easing: tween.easeOut }); // Animate the body swaying slightly tween(hangmanDrawing.parts[1], { rotation: Math.PI / 12 // Slight body rotation }, { duration: 1000, easing: tween.easeInOut }); // Animate arms dropping down tween(hangmanDrawing.parts[2], { rotation: -Math.PI / 2 // Left arm drops down }, { duration: 600, easing: tween.easeOut }); tween(hangmanDrawing.parts[3], { rotation: Math.PI / 2 // Right arm drops down }, { duration: 650, easing: tween.easeOut }); // Fade out the entire hangman slightly to show death tween(hangmanDrawing, { alpha: 0.7 }, { duration: 1200, easing: tween.easeOut, onFinish: function onFinish() { // Show game over after animation completes LK.showGameOver(); } }); } } // Update letter displays updateLetterDisplays(); // Reset Claude help button resetClaudeButton(); } // Create hangman drawing hangmanDrawing = new HangmanDrawing(); hangmanDrawing.x = hangmanX; hangmanDrawing.y = hangmanY; game.addChild(hangmanDrawing); // Create subject/category display var subjectDisplay = new Text2('', { size: 90, fill: '#ffff99' }); subjectDisplay.anchor.set(0.5, 0.5); subjectDisplay.x = 2048 / 2 + 120; subjectDisplay.y = wordY - 120; game.addChild(subjectDisplay); // Create word display wordDisplay = new Text2('', { size: 140, fill: '#ffffff' }); wordDisplay.anchor.set(0.5, 0.5); wordDisplay.x = 2048 / 2 + 120; wordDisplay.y = wordY; game.addChild(wordDisplay); // Create correct letters display with better styling var correctLettersDisplay = new Text2('✓ Correct Letters', { size: 90, fill: '#00ff88', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); correctLettersDisplay.anchor.set(0.5, 0.5); correctLettersDisplay.x = 2048 / 4; correctLettersDisplay.y = 1400; game.addChild(correctLettersDisplay); // Create wrong letters display with better styling var wrongLettersDisplay = new Text2('✗ Wrong Letters', { size: 90, fill: '#ff4444', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); wrongLettersDisplay.anchor.set(0.5, 0.5); wrongLettersDisplay.x = 2048 / 4 * 3; wrongLettersDisplay.y = 1400; game.addChild(wrongLettersDisplay); // Create actual letter display areas var correctLettersText = new Text2('', { size: 70, fill: '#88ffaa' }); correctLettersText.anchor.set(0.5, 0); correctLettersText.x = 2048 / 4; correctLettersText.y = 1460; game.addChild(correctLettersText); var wrongLettersText = new Text2('', { size: 70, fill: '#ffaaaa' }); wrongLettersText.anchor.set(0.5, 0); wrongLettersText.x = 2048 / 4 * 3; wrongLettersText.y = 1460; game.addChild(wrongLettersText); // Create Claude AI help button var claudeHelpBtn = new Container(); var claudeBg = claudeHelpBtn.attachAsset('letter_btn_bg', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, scaleX: 2.5, scaleY: 1.2 }); var claudeMain = claudeHelpBtn.attachAsset('letter_btn_main', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -2, scaleX: 2.4, scaleY: 1.1 }); var claudeHighlight = claudeHelpBtn.attachAsset('letter_btn_highlight', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -4, scaleX: 2.3, scaleY: 1.0 }); var claudeText = new Text2('Glaud', { size: 75, fill: '#00ddff' }); claudeText.anchor.set(0.5, 0.5); claudeText.x = 0; claudeText.y = -2; claudeHelpBtn.addChild(claudeText); // Position Claude button below keyboard claudeHelpBtn.x = 2048 / 2; claudeHelpBtn.y = letterGridY + 500; game.addChild(claudeHelpBtn); // Claude button functionality claudeHelpBtn.down = function (x, y, obj) { // Play button press sound LK.getSound('button').play(); // Animate button press tween(claudeHelpBtn, { y: claudeHelpBtn.y + 4 }, { duration: 100 }); tween(claudeMain, { y: claudeMain.y + 2 }, { duration: 100 }); tween(claudeHighlight, { y: claudeHighlight.y + 4 }, { duration: 100 }); tween(claudeText, { y: claudeText.y + 2 }, { duration: 100 }); }; claudeHelpBtn.up = function (x, y, obj) { // Check if help has already been used this game if (claudeHelpUsed) { // Flash red to indicate help already used LK.effects.flashScreen(0x440000, 300); return; } // Animate button release tween(claudeHelpBtn, { y: claudeHelpBtn.y - 4 }, { duration: 100 }); tween(claudeMain, { y: claudeMain.y - 2 }, { duration: 100 }); tween(claudeHighlight, { y: claudeHighlight.y - 4 }, { duration: 100 }); tween(claudeText, { y: claudeText.y - 2 }, { duration: 100 }); // Find a correct letter that hasn't been guessed yet var availableCorrectLetters = []; for (var i = 0; i < currentWord.length; ++i) { var letter = currentWord[i]; if (guessedLetters.indexOf(letter) === -1) { availableCorrectLetters.push(letter); } } if (availableCorrectLetters.length > 0) { // Mark help as used claudeHelpUsed = true; // Play help sound LK.getSound('help').play(); // Change button appearance to indicate it's been used claudeText.setText('Perfect'); claudeText.fill = '#666666'; tween(claudeHelpBtn, { alpha: 0.5 }, { duration: 300 }); // Pick a random correct letter var randomIndex = Math.floor(Math.random() * availableCorrectLetters.length); var suggestedLetter = availableCorrectLetters[randomIndex]; // Find and activate the corresponding button for (var i = 0; i < letterButtons.length; ++i) { var btn = letterButtons[i]; if (btn.letter === suggestedLetter && !btn.used) { // Flash the button to highlight it LK.effects.flashObject(btn, 0x00ff00, 500); // Auto-select the letter after a short delay LK.setTimeout(function () { onLetterSelected(suggestedLetter, btn); }, 600); break; } } // Flash screen green to indicate help LK.effects.flashScreen(0x004400, 300); } }; // Function to reset Claude button appearance function resetClaudeButton() { claudeText.setText('Close'); claudeText.fill = '#00ddff'; claudeHelpBtn.alpha = 1; } // Play background music LK.playMusic('background_music'); // Show subject selection first showSubjectSelection(); // On game reset, show subject selection again game.on('reset', function () { showSubjectSelection(); });
===================================================================
--- original.js
+++ change.js
@@ -521,14 +521,36 @@
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 400;
subjectSelectionContainer.addChild(titleText);
+ // Add Random mode button first
+ var randomBtn = new SubjectButton();
+ randomBtn.setSubject('RANDOM');
+ randomBtn.x = 2048 / 2;
+ randomBtn.y = 700;
+ randomBtn.originalY = randomBtn.y;
+ randomBtn.onSelect = function (selectedSubjectName) {
+ selectedSubject = 'RANDOM';
+ // Create combined word list from all subjects
+ currentWordList = [];
+ var allSubjects = Object.keys(WORD_LISTS);
+ for (var s = 0; s < allSubjects.length; ++s) {
+ var subjectWords = WORD_LISTS[allSubjects[s]];
+ for (var w = 0; w < subjectWords.length; ++w) {
+ currentWordList.push(subjectWords[w]);
+ }
+ }
+ hideSubjectSelection();
+ startGame();
+ };
+ subjectSelectionContainer.addChild(randomBtn);
+ subjectButtons.push(randomBtn);
// Create subject buttons
var subjects = Object.keys(WORD_LISTS);
var buttonsPerRow = 3;
var buttonSpacingX = 350;
var buttonSpacingY = 200;
- var startY = 800;
+ var startY = 900;
for (var i = 0; i < subjects.length; ++i) {
var subject = subjects[i];
var row = Math.floor(i / buttonsPerRow);
var col = i % buttonsPerRow;
@@ -586,9 +608,23 @@
revealed.push(false);
}
// Set subject/category text based on selected subject
var subject = selectedSubject || "OBJECTS";
- subjectDisplay.setText("Subject: " + subject);
+ if (selectedSubject === 'RANDOM') {
+ // In random mode, find which subject the current word belongs to
+ var actualSubject = "UNKNOWN";
+ var allSubjects = Object.keys(WORD_LISTS);
+ for (var s = 0; s < allSubjects.length; ++s) {
+ var subjectWords = WORD_LISTS[allSubjects[s]];
+ if (subjectWords.indexOf(currentWord) !== -1) {
+ actualSubject = allSubjects[s];
+ break;
+ }
+ }
+ subjectDisplay.setText("Subject: " + actualSubject + " (Random Mode)");
+ } else {
+ subjectDisplay.setText("Subject: " + subject);
+ }
// Update word display
updateWordDisplay();
// Reset hangman
hangmanDrawing.reset();