User prompt
Show a pop-up message " You're Dead " for 2 seconds with an explosion effetc when the game ends ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
create another menu to choose categories
User prompt
before the start of the game create a menu to choose difficulty "Easy" , "Medium" and "Hard". when "Easy" is clicked choose simple level words; when "Medium" is clicked choose elementary level words; and when "Hard" is clicked advanced level words are chosen. Easy words are 1 points , Medium words are 2 points and Hard words are 3 points.
User prompt
change the frame color with white
User prompt
remove brown back round and make a black frame add bomb effetcs when the game ends ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make the hang man backround white and center it
Code edit (1 edits merged)
Please save this source code
User prompt
Word Master Hangman
Initial prompt
hang man game words are chosen from 5 categories " animals" , "vegetables" , "fruits" , "names" , "films and movies"
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var CategoryButton = Container.expand(function (category, label) {
var self = Container.call(this);
self.category = category;
var buttonBg = self.attachAsset('letterButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 1.5
});
var buttonText = new Text2(label, {
size: 50,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
selectCategory(self.category);
};
return self;
});
// Don't start game until difficulty is selected
// startNewGame() will be called from selectDifficulty();
var DifficultyButton = Container.expand(function (difficulty, label) {
var self = Container.call(this);
self.difficulty = difficulty;
var buttonBg = self.attachAsset('letterButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 1.5
});
var buttonText = new Text2(label, {
size: 50,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
selectDifficulty(self.difficulty);
};
return self;
});
var HangmanDrawing = Container.expand(function () {
var self = Container.call(this);
self.wrongGuesses = 0;
self.bodyParts = [];
// White frame instead of brown gallows
var frame = self.attachAsset('wordSpace', {
anchorX: 0.5,
anchorY: 1,
scaleX: 40,
scaleY: 4
});
// Rope
var rope = self.attachAsset('rope', {
anchorX: 0.5,
anchorY: 0
});
rope.x = 50;
rope.y = -280;
// Body parts (initially hidden)
var head = self.attachAsset('head', {
anchorX: 0.5,
anchorY: 0.5
});
head.x = 50;
head.y = -220;
head.alpha = 0;
self.bodyParts.push(head);
var body = self.attachAsset('body', {
anchorX: 0.5,
anchorY: 0
});
body.x = 50;
body.y = -200;
body.alpha = 0;
self.bodyParts.push(body);
var leftArm = self.attachAsset('leftArm', {
anchorX: 1,
anchorY: 0.5
});
leftArm.x = 48;
leftArm.y = -170;
leftArm.alpha = 0;
self.bodyParts.push(leftArm);
var rightArm = self.attachAsset('rightArm', {
anchorX: 0,
anchorY: 0.5
});
rightArm.x = 52;
rightArm.y = -170;
rightArm.alpha = 0;
self.bodyParts.push(rightArm);
var leftLeg = self.attachAsset('leftLeg', {
anchorX: 0.5,
anchorY: 0
});
leftLeg.x = 42;
leftLeg.y = -120;
leftLeg.alpha = 0;
self.bodyParts.push(leftLeg);
var rightLeg = self.attachAsset('rightLeg', {
anchorX: 0.5,
anchorY: 0
});
rightLeg.x = 58;
rightLeg.y = -120;
rightLeg.alpha = 0;
self.bodyParts.push(rightLeg);
self.addBodyPart = function () {
if (self.wrongGuesses < self.bodyParts.length) {
var part = self.bodyParts[self.wrongGuesses];
part.alpha = 1;
tween(part, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(part, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
self.wrongGuesses++;
}
};
self.reset = function () {
self.wrongGuesses = 0;
self.scaleX = 1;
self.scaleY = 1;
self.alpha = 1;
for (var i = 0; i < self.bodyParts.length; i++) {
self.bodyParts[i].alpha = 0;
self.bodyParts[i].scaleX = 1;
self.bodyParts[i].scaleY = 1;
}
};
return self;
});
var LetterButton = Container.expand(function (letter) {
var self = Container.call(this);
self.letter = letter;
self.isPressed = false;
var buttonBg = self.attachAsset('letterButton', {
anchorX: 0.5,
anchorY: 0.5
});
var letterText = new Text2(letter, {
size: 40,
fill: 0xFFFFFF
});
letterText.anchor.set(0.5, 0.5);
self.addChild(letterText);
self.markPressed = function () {
if (self.isPressed) return;
self.isPressed = true;
buttonBg.tint = 0x666666;
letterText.tint = 0x999999;
};
self.down = function (x, y, obj) {
if (self.isPressed) return;
handleLetterGuess(self.letter);
self.markPressed();
};
return self;
});
var WordDisplay = Container.expand(function () {
var self = Container.call(this);
self.currentWord = "";
self.guessedLetters = [];
self.wordSpaces = [];
self.setWord = function (word) {
// Clear existing word spaces
for (var i = 0; i < self.wordSpaces.length; i++) {
self.wordSpaces[i].destroy();
}
self.wordSpaces = [];
self.guessedLetters = [];
self.currentWord = word.toUpperCase();
var totalWidth = self.currentWord.length * 70;
var startX = -totalWidth / 2;
for (var i = 0; i < self.currentWord.length; i++) {
var space = self.attachAsset('wordSpace', {
anchorX: 0.5,
anchorY: 0.5
});
space.x = startX + i * 70 + 35;
space.y = 0;
var letterText = new Text2("", {
size: 40,
fill: 0x000000
});
letterText.anchor.set(0.5, 0.5);
space.addChild(letterText);
space.letterText = letterText;
self.wordSpaces.push(space);
}
};
self.revealLetter = function (letter) {
letter = letter.toUpperCase();
var found = false;
for (var i = 0; i < self.currentWord.length; i++) {
if (self.currentWord[i] === letter) {
self.wordSpaces[i].letterText.setText(letter);
found = true;
}
}
if (found && self.guessedLetters.indexOf(letter) === -1) {
self.guessedLetters.push(letter);
}
return found;
};
self.isWordComplete = function () {
var uniqueLetters = [];
for (var i = 0; i < self.currentWord.length; i++) {
var letter = self.currentWord[i];
if (uniqueLetters.indexOf(letter) === -1) {
uniqueLetters.push(letter);
}
}
for (var i = 0; i < uniqueLetters.length; i++) {
if (self.guessedLetters.indexOf(uniqueLetters[i]) === -1) {
return false;
}
}
return true;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xF0F0F0
});
/****
* Game Code
****/
// Word categories by difficulty
var wordCategories = {
easy: {
animals: ["CAT", "DOG", "COW", "PIG", "BAT", "BEE", "ANT", "FOX", "OWL", "RAT"],
vegetables: ["PEA", "YAM", "CORN", "BEAN", "BEET", "KALE", "LEEK", "MINT", "OKRA", "SAGE"],
fruits: ["FIG", "PLUM", "LIME", "DATE", "PEAR", "KIWI", "MANGO", "GRAPE", "MELON", "LEMON"],
names: ["TOM", "SUE", "JIM", "ANN", "BOB", "EVE", "JOE", "AMY", "DAN", "IVY"],
movies: ["ELF", "UP", "TOY", "CARS", "WALL", "COCO", "FROZEN", "SHREK", "BRAVE", "MULAN"]
},
medium: {
animals: ["TIGER", "HORSE", "RABBIT", "TURTLE", "HAMSTER", "FALCON", "JAGUAR", "PYTHON", "DOLPHIN", "LEOPARD"],
vegetables: ["CARROT", "POTATO", "ONION", "TOMATO", "PEPPER", "CELERY", "TURNIP", "SQUASH", "GARLIC", "RADISH"],
fruits: ["APPLE", "BANANA", "ORANGE", "CHERRY", "PEACH", "GRAPES", "COCONUT", "APRICOT", "PAPAYA", "BERRIES"],
names: ["JOHN", "MARY", "DAVID", "SARAH", "ROBERT", "ANNA", "JAMES", "EMMA", "KEVIN", "LINDA"],
movies: ["AVATAR", "TITANIC", "BATMAN", "ROCKY", "JAWS", "ALIEN", "MATRIX", "SPIDER", "WONDER", "JOKER"]
},
hard: {
animals: ["RHINOCEROS", "CHIMPANZEE", "CROCODILE", "BUTTERFLY", "KANGAROO", "HIPPOPOTAMUS", "CHEETAH", "HEDGEHOG", "FLAMINGO", "CHAMELEON"],
vegetables: ["BROCCOLI", "CUCUMBER", "CAULIFLOWER", "ASPARAGUS", "ARTICHOKE", "BRUSSELS", "ZUCCHINI", "PARSNIP", "EGGPLANT", "WATERCRESS"],
fruits: ["STRAWBERRY", "PINEAPPLE", "WATERMELON", "BLUEBERRY", "BLACKBERRY", "CRANBERRY", "GRAPEFRUIT", "POMEGRANATE", "CANTALOUPE", "RASPBERRY"],
names: ["ALEXANDER", "ELIZABETH", "CHRISTOPHER", "STEPHANIE", "NATHANIEL", "KATHERINE", "BENJAMIN", "SAMANTHA", "FREDERICK", "CHARLOTTE"],
movies: ["INTERSTELLAR", "GLADIATOR", "GOODFELLAS", "CASABLANCA", "TERMINATOR", "GODFATHER", "PHILADELPHIA", "FORRESTGUMP", "SCHINDLER", "APOCALYPSE"]
}
};
var currentDifficulty = "";
var currentCategory = "";
var currentWord = "";
var difficultyPoints = {
easy: 1,
medium: 2,
hard: 3
};
var gameStarted = false;
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var letterButtons = [];
var gameState = "playing"; // "playing", "won", "lost"
// Category selection menu
var categoryMenu = game.addChild(new Container());
var categoryMenuTitle = new Text2("Choose Category", {
size: 80,
fill: 0x333333
});
categoryMenuTitle.anchor.set(0.5, 0.5);
categoryMenuTitle.x = 1024;
categoryMenuTitle.y = 600;
categoryMenu.addChild(categoryMenuTitle);
var animalsButton = categoryMenu.addChild(new CategoryButton("animals", "ANIMALS"));
animalsButton.x = 1024;
animalsButton.y = 800;
var vegetablesButton = categoryMenu.addChild(new CategoryButton("vegetables", "VEGETABLES"));
vegetablesButton.x = 1024;
vegetablesButton.y = 950;
var fruitsButton = categoryMenu.addChild(new CategoryButton("fruits", "FRUITS"));
fruitsButton.x = 1024;
fruitsButton.y = 1100;
var namesButton = categoryMenu.addChild(new CategoryButton("names", "NAMES"));
namesButton.x = 1024;
namesButton.y = 1250;
var moviesButton = categoryMenu.addChild(new CategoryButton("movies", "MOVIES"));
moviesButton.x = 1024;
moviesButton.y = 1400;
categoryMenu.alpha = 0;
// Difficulty selection menu
var difficultyMenu = game.addChild(new Container());
var menuTitle = new Text2("Choose Difficulty", {
size: 80,
fill: 0x333333
});
menuTitle.anchor.set(0.5, 0.5);
menuTitle.x = 1024;
menuTitle.y = 800;
difficultyMenu.addChild(menuTitle);
var easyButton = difficultyMenu.addChild(new DifficultyButton("easy", "EASY\n(1 point)"));
easyButton.x = 1024;
easyButton.y = 1100;
var mediumButton = difficultyMenu.addChild(new DifficultyButton("medium", "MEDIUM\n(2 points)"));
mediumButton.x = 1024;
mediumButton.y = 1300;
var hardButton = difficultyMenu.addChild(new DifficultyButton("hard", "HARD\n(3 points)"));
hardButton.x = 1024;
hardButton.y = 1500;
// Game elements (initially hidden)
var hangmanDrawing = game.addChild(new HangmanDrawing());
hangmanDrawing.x = 1024;
hangmanDrawing.y = 1000;
hangmanDrawing.alpha = 0;
var wordDisplay = game.addChild(new WordDisplay());
wordDisplay.x = 1024;
wordDisplay.y = 1200;
wordDisplay.alpha = 0;
// Category display
var categoryText = new Text2("", {
size: 60,
fill: 0x333333
});
categoryText.anchor.set(0.5, 0.5);
categoryText.x = 1024;
categoryText.y = 400;
categoryText.alpha = 0;
game.addChild(categoryText);
// Score display
var scoreText = new Text2("Score: 0", {
size: 50,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create alphabet buttons (initially hidden)
var buttonStartY = 1500;
var buttonsPerRow = 7;
var buttonSpacing = 90;
var rowSpacing = 90;
for (var i = 0; i < alphabet.length; i++) {
var letter = alphabet[i];
var button = game.addChild(new LetterButton(letter));
var row = Math.floor(i / buttonsPerRow);
var col = i % buttonsPerRow;
var rowWidth = Math.min(buttonsPerRow, alphabet.length - row * buttonsPerRow) * buttonSpacing;
var startX = 1024 - rowWidth / 2 + buttonSpacing / 2;
button.x = startX + col * buttonSpacing;
button.y = buttonStartY + row * rowSpacing;
button.alpha = 0;
letterButtons.push(button);
}
function selectDifficulty(difficulty) {
currentDifficulty = difficulty;
// Hide difficulty menu
difficultyMenu.alpha = 0;
// Show category menu
categoryMenu.alpha = 1;
}
function selectCategory(category) {
currentCategory = category;
gameStarted = true;
// Hide category menu
categoryMenu.alpha = 0;
// Show game elements
hangmanDrawing.alpha = 1;
wordDisplay.alpha = 1;
categoryText.alpha = 1;
for (var i = 0; i < letterButtons.length; i++) {
letterButtons[i].alpha = 1;
}
// Start first game
startNewGame();
}
function getRandomWord() {
if (!currentDifficulty || !currentCategory) return "";
var words = wordCategories[currentDifficulty][currentCategory];
currentWord = words[Math.floor(Math.random() * words.length)];
return currentWord;
}
function handleLetterGuess(letter) {
if (gameState !== "playing") return;
var isCorrect = wordDisplay.revealLetter(letter);
if (isCorrect) {
LK.getSound('correct').play();
if (wordDisplay.isWordComplete()) {
gameState = "won";
LK.getSound('win').play();
var points = difficultyPoints[currentDifficulty] || 1;
LK.setScore(LK.getScore() + points);
scoreText.setText("Score: " + LK.getScore());
LK.setTimeout(function () {
startNewGame();
}, 2000);
}
} else {
LK.getSound('wrong').play();
hangmanDrawing.addBodyPart();
if (hangmanDrawing.wrongGuesses >= 6) {
gameState = "lost";
LK.getSound('lose').play();
// Reveal the word
for (var i = 0; i < currentWord.length; i++) {
wordDisplay.revealLetter(currentWord[i]);
}
// Show "You're Dead" popup
var deathPopup = new Text2("You're Dead", {
size: 120,
fill: 0xFF0000
});
deathPopup.anchor.set(0.5, 0.5);
deathPopup.x = 1024;
deathPopup.y = 1366;
deathPopup.alpha = 0;
game.addChild(deathPopup);
// Animate popup appearance
tween(deathPopup, {
alpha: 1,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.easeOut
});
// Bomb explosion effect
tween(hangmanDrawing, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0.5
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(hangmanDrawing, {
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}, {
duration: 300,
easing: tween.easeIn
});
}
});
LK.setTimeout(function () {
deathPopup.destroy();
LK.showGameOver();
}, 2000);
}
}
}
function startNewGame() {
gameState = "playing";
// Reset hangman drawing
hangmanDrawing.reset();
// Get new word
var newWord = getRandomWord();
wordDisplay.setWord(newWord);
// Update category display
categoryText.setText("Category: " + currentCategory.toUpperCase());
// Reset letter buttons
for (var i = 0; i < letterButtons.length; i++) {
letterButtons[i].isPressed = false;
letterButtons[i].children[0].tint = 0xFFFFFF; // Reset button background
letterButtons[i].children[1].tint = 0xFFFFFF; // Reset letter text
}
} /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var CategoryButton = Container.expand(function (category, label) {
var self = Container.call(this);
self.category = category;
var buttonBg = self.attachAsset('letterButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 1.5
});
var buttonText = new Text2(label, {
size: 50,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
selectCategory(self.category);
};
return self;
});
// Don't start game until difficulty is selected
// startNewGame() will be called from selectDifficulty();
var DifficultyButton = Container.expand(function (difficulty, label) {
var self = Container.call(this);
self.difficulty = difficulty;
var buttonBg = self.attachAsset('letterButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 1.5
});
var buttonText = new Text2(label, {
size: 50,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
selectDifficulty(self.difficulty);
};
return self;
});
var HangmanDrawing = Container.expand(function () {
var self = Container.call(this);
self.wrongGuesses = 0;
self.bodyParts = [];
// White frame instead of brown gallows
var frame = self.attachAsset('wordSpace', {
anchorX: 0.5,
anchorY: 1,
scaleX: 40,
scaleY: 4
});
// Rope
var rope = self.attachAsset('rope', {
anchorX: 0.5,
anchorY: 0
});
rope.x = 50;
rope.y = -280;
// Body parts (initially hidden)
var head = self.attachAsset('head', {
anchorX: 0.5,
anchorY: 0.5
});
head.x = 50;
head.y = -220;
head.alpha = 0;
self.bodyParts.push(head);
var body = self.attachAsset('body', {
anchorX: 0.5,
anchorY: 0
});
body.x = 50;
body.y = -200;
body.alpha = 0;
self.bodyParts.push(body);
var leftArm = self.attachAsset('leftArm', {
anchorX: 1,
anchorY: 0.5
});
leftArm.x = 48;
leftArm.y = -170;
leftArm.alpha = 0;
self.bodyParts.push(leftArm);
var rightArm = self.attachAsset('rightArm', {
anchorX: 0,
anchorY: 0.5
});
rightArm.x = 52;
rightArm.y = -170;
rightArm.alpha = 0;
self.bodyParts.push(rightArm);
var leftLeg = self.attachAsset('leftLeg', {
anchorX: 0.5,
anchorY: 0
});
leftLeg.x = 42;
leftLeg.y = -120;
leftLeg.alpha = 0;
self.bodyParts.push(leftLeg);
var rightLeg = self.attachAsset('rightLeg', {
anchorX: 0.5,
anchorY: 0
});
rightLeg.x = 58;
rightLeg.y = -120;
rightLeg.alpha = 0;
self.bodyParts.push(rightLeg);
self.addBodyPart = function () {
if (self.wrongGuesses < self.bodyParts.length) {
var part = self.bodyParts[self.wrongGuesses];
part.alpha = 1;
tween(part, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(part, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
self.wrongGuesses++;
}
};
self.reset = function () {
self.wrongGuesses = 0;
self.scaleX = 1;
self.scaleY = 1;
self.alpha = 1;
for (var i = 0; i < self.bodyParts.length; i++) {
self.bodyParts[i].alpha = 0;
self.bodyParts[i].scaleX = 1;
self.bodyParts[i].scaleY = 1;
}
};
return self;
});
var LetterButton = Container.expand(function (letter) {
var self = Container.call(this);
self.letter = letter;
self.isPressed = false;
var buttonBg = self.attachAsset('letterButton', {
anchorX: 0.5,
anchorY: 0.5
});
var letterText = new Text2(letter, {
size: 40,
fill: 0xFFFFFF
});
letterText.anchor.set(0.5, 0.5);
self.addChild(letterText);
self.markPressed = function () {
if (self.isPressed) return;
self.isPressed = true;
buttonBg.tint = 0x666666;
letterText.tint = 0x999999;
};
self.down = function (x, y, obj) {
if (self.isPressed) return;
handleLetterGuess(self.letter);
self.markPressed();
};
return self;
});
var WordDisplay = Container.expand(function () {
var self = Container.call(this);
self.currentWord = "";
self.guessedLetters = [];
self.wordSpaces = [];
self.setWord = function (word) {
// Clear existing word spaces
for (var i = 0; i < self.wordSpaces.length; i++) {
self.wordSpaces[i].destroy();
}
self.wordSpaces = [];
self.guessedLetters = [];
self.currentWord = word.toUpperCase();
var totalWidth = self.currentWord.length * 70;
var startX = -totalWidth / 2;
for (var i = 0; i < self.currentWord.length; i++) {
var space = self.attachAsset('wordSpace', {
anchorX: 0.5,
anchorY: 0.5
});
space.x = startX + i * 70 + 35;
space.y = 0;
var letterText = new Text2("", {
size: 40,
fill: 0x000000
});
letterText.anchor.set(0.5, 0.5);
space.addChild(letterText);
space.letterText = letterText;
self.wordSpaces.push(space);
}
};
self.revealLetter = function (letter) {
letter = letter.toUpperCase();
var found = false;
for (var i = 0; i < self.currentWord.length; i++) {
if (self.currentWord[i] === letter) {
self.wordSpaces[i].letterText.setText(letter);
found = true;
}
}
if (found && self.guessedLetters.indexOf(letter) === -1) {
self.guessedLetters.push(letter);
}
return found;
};
self.isWordComplete = function () {
var uniqueLetters = [];
for (var i = 0; i < self.currentWord.length; i++) {
var letter = self.currentWord[i];
if (uniqueLetters.indexOf(letter) === -1) {
uniqueLetters.push(letter);
}
}
for (var i = 0; i < uniqueLetters.length; i++) {
if (self.guessedLetters.indexOf(uniqueLetters[i]) === -1) {
return false;
}
}
return true;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xF0F0F0
});
/****
* Game Code
****/
// Word categories by difficulty
var wordCategories = {
easy: {
animals: ["CAT", "DOG", "COW", "PIG", "BAT", "BEE", "ANT", "FOX", "OWL", "RAT"],
vegetables: ["PEA", "YAM", "CORN", "BEAN", "BEET", "KALE", "LEEK", "MINT", "OKRA", "SAGE"],
fruits: ["FIG", "PLUM", "LIME", "DATE", "PEAR", "KIWI", "MANGO", "GRAPE", "MELON", "LEMON"],
names: ["TOM", "SUE", "JIM", "ANN", "BOB", "EVE", "JOE", "AMY", "DAN", "IVY"],
movies: ["ELF", "UP", "TOY", "CARS", "WALL", "COCO", "FROZEN", "SHREK", "BRAVE", "MULAN"]
},
medium: {
animals: ["TIGER", "HORSE", "RABBIT", "TURTLE", "HAMSTER", "FALCON", "JAGUAR", "PYTHON", "DOLPHIN", "LEOPARD"],
vegetables: ["CARROT", "POTATO", "ONION", "TOMATO", "PEPPER", "CELERY", "TURNIP", "SQUASH", "GARLIC", "RADISH"],
fruits: ["APPLE", "BANANA", "ORANGE", "CHERRY", "PEACH", "GRAPES", "COCONUT", "APRICOT", "PAPAYA", "BERRIES"],
names: ["JOHN", "MARY", "DAVID", "SARAH", "ROBERT", "ANNA", "JAMES", "EMMA", "KEVIN", "LINDA"],
movies: ["AVATAR", "TITANIC", "BATMAN", "ROCKY", "JAWS", "ALIEN", "MATRIX", "SPIDER", "WONDER", "JOKER"]
},
hard: {
animals: ["RHINOCEROS", "CHIMPANZEE", "CROCODILE", "BUTTERFLY", "KANGAROO", "HIPPOPOTAMUS", "CHEETAH", "HEDGEHOG", "FLAMINGO", "CHAMELEON"],
vegetables: ["BROCCOLI", "CUCUMBER", "CAULIFLOWER", "ASPARAGUS", "ARTICHOKE", "BRUSSELS", "ZUCCHINI", "PARSNIP", "EGGPLANT", "WATERCRESS"],
fruits: ["STRAWBERRY", "PINEAPPLE", "WATERMELON", "BLUEBERRY", "BLACKBERRY", "CRANBERRY", "GRAPEFRUIT", "POMEGRANATE", "CANTALOUPE", "RASPBERRY"],
names: ["ALEXANDER", "ELIZABETH", "CHRISTOPHER", "STEPHANIE", "NATHANIEL", "KATHERINE", "BENJAMIN", "SAMANTHA", "FREDERICK", "CHARLOTTE"],
movies: ["INTERSTELLAR", "GLADIATOR", "GOODFELLAS", "CASABLANCA", "TERMINATOR", "GODFATHER", "PHILADELPHIA", "FORRESTGUMP", "SCHINDLER", "APOCALYPSE"]
}
};
var currentDifficulty = "";
var currentCategory = "";
var currentWord = "";
var difficultyPoints = {
easy: 1,
medium: 2,
hard: 3
};
var gameStarted = false;
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var letterButtons = [];
var gameState = "playing"; // "playing", "won", "lost"
// Category selection menu
var categoryMenu = game.addChild(new Container());
var categoryMenuTitle = new Text2("Choose Category", {
size: 80,
fill: 0x333333
});
categoryMenuTitle.anchor.set(0.5, 0.5);
categoryMenuTitle.x = 1024;
categoryMenuTitle.y = 600;
categoryMenu.addChild(categoryMenuTitle);
var animalsButton = categoryMenu.addChild(new CategoryButton("animals", "ANIMALS"));
animalsButton.x = 1024;
animalsButton.y = 800;
var vegetablesButton = categoryMenu.addChild(new CategoryButton("vegetables", "VEGETABLES"));
vegetablesButton.x = 1024;
vegetablesButton.y = 950;
var fruitsButton = categoryMenu.addChild(new CategoryButton("fruits", "FRUITS"));
fruitsButton.x = 1024;
fruitsButton.y = 1100;
var namesButton = categoryMenu.addChild(new CategoryButton("names", "NAMES"));
namesButton.x = 1024;
namesButton.y = 1250;
var moviesButton = categoryMenu.addChild(new CategoryButton("movies", "MOVIES"));
moviesButton.x = 1024;
moviesButton.y = 1400;
categoryMenu.alpha = 0;
// Difficulty selection menu
var difficultyMenu = game.addChild(new Container());
var menuTitle = new Text2("Choose Difficulty", {
size: 80,
fill: 0x333333
});
menuTitle.anchor.set(0.5, 0.5);
menuTitle.x = 1024;
menuTitle.y = 800;
difficultyMenu.addChild(menuTitle);
var easyButton = difficultyMenu.addChild(new DifficultyButton("easy", "EASY\n(1 point)"));
easyButton.x = 1024;
easyButton.y = 1100;
var mediumButton = difficultyMenu.addChild(new DifficultyButton("medium", "MEDIUM\n(2 points)"));
mediumButton.x = 1024;
mediumButton.y = 1300;
var hardButton = difficultyMenu.addChild(new DifficultyButton("hard", "HARD\n(3 points)"));
hardButton.x = 1024;
hardButton.y = 1500;
// Game elements (initially hidden)
var hangmanDrawing = game.addChild(new HangmanDrawing());
hangmanDrawing.x = 1024;
hangmanDrawing.y = 1000;
hangmanDrawing.alpha = 0;
var wordDisplay = game.addChild(new WordDisplay());
wordDisplay.x = 1024;
wordDisplay.y = 1200;
wordDisplay.alpha = 0;
// Category display
var categoryText = new Text2("", {
size: 60,
fill: 0x333333
});
categoryText.anchor.set(0.5, 0.5);
categoryText.x = 1024;
categoryText.y = 400;
categoryText.alpha = 0;
game.addChild(categoryText);
// Score display
var scoreText = new Text2("Score: 0", {
size: 50,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create alphabet buttons (initially hidden)
var buttonStartY = 1500;
var buttonsPerRow = 7;
var buttonSpacing = 90;
var rowSpacing = 90;
for (var i = 0; i < alphabet.length; i++) {
var letter = alphabet[i];
var button = game.addChild(new LetterButton(letter));
var row = Math.floor(i / buttonsPerRow);
var col = i % buttonsPerRow;
var rowWidth = Math.min(buttonsPerRow, alphabet.length - row * buttonsPerRow) * buttonSpacing;
var startX = 1024 - rowWidth / 2 + buttonSpacing / 2;
button.x = startX + col * buttonSpacing;
button.y = buttonStartY + row * rowSpacing;
button.alpha = 0;
letterButtons.push(button);
}
function selectDifficulty(difficulty) {
currentDifficulty = difficulty;
// Hide difficulty menu
difficultyMenu.alpha = 0;
// Show category menu
categoryMenu.alpha = 1;
}
function selectCategory(category) {
currentCategory = category;
gameStarted = true;
// Hide category menu
categoryMenu.alpha = 0;
// Show game elements
hangmanDrawing.alpha = 1;
wordDisplay.alpha = 1;
categoryText.alpha = 1;
for (var i = 0; i < letterButtons.length; i++) {
letterButtons[i].alpha = 1;
}
// Start first game
startNewGame();
}
function getRandomWord() {
if (!currentDifficulty || !currentCategory) return "";
var words = wordCategories[currentDifficulty][currentCategory];
currentWord = words[Math.floor(Math.random() * words.length)];
return currentWord;
}
function handleLetterGuess(letter) {
if (gameState !== "playing") return;
var isCorrect = wordDisplay.revealLetter(letter);
if (isCorrect) {
LK.getSound('correct').play();
if (wordDisplay.isWordComplete()) {
gameState = "won";
LK.getSound('win').play();
var points = difficultyPoints[currentDifficulty] || 1;
LK.setScore(LK.getScore() + points);
scoreText.setText("Score: " + LK.getScore());
LK.setTimeout(function () {
startNewGame();
}, 2000);
}
} else {
LK.getSound('wrong').play();
hangmanDrawing.addBodyPart();
if (hangmanDrawing.wrongGuesses >= 6) {
gameState = "lost";
LK.getSound('lose').play();
// Reveal the word
for (var i = 0; i < currentWord.length; i++) {
wordDisplay.revealLetter(currentWord[i]);
}
// Show "You're Dead" popup
var deathPopup = new Text2("You're Dead", {
size: 120,
fill: 0xFF0000
});
deathPopup.anchor.set(0.5, 0.5);
deathPopup.x = 1024;
deathPopup.y = 1366;
deathPopup.alpha = 0;
game.addChild(deathPopup);
// Animate popup appearance
tween(deathPopup, {
alpha: 1,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.easeOut
});
// Bomb explosion effect
tween(hangmanDrawing, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0.5
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(hangmanDrawing, {
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}, {
duration: 300,
easing: tween.easeIn
});
}
});
LK.setTimeout(function () {
deathPopup.destroy();
LK.showGameOver();
}, 2000);
}
}
}
function startNewGame() {
gameState = "playing";
// Reset hangman drawing
hangmanDrawing.reset();
// Get new word
var newWord = getRandomWord();
wordDisplay.setWord(newWord);
// Update category display
categoryText.setText("Category: " + currentCategory.toUpperCase());
// Reset letter buttons
for (var i = 0; i < letterButtons.length; i++) {
letterButtons[i].isPressed = false;
letterButtons[i].children[0].tint = 0xFFFFFF; // Reset button background
letterButtons[i].children[1].tint = 0xFFFFFF; // Reset letter text
}
}