User prompt
Mix all questions when we start
User prompt
No timeout of button when we win
User prompt
Give opinion button pay next or play again
User prompt
When one level finish then win or next level opinion.
User prompt
The life not get less . Do less when we worng answer
User prompt
Defeat system
User prompt
Drop zone were see what word we dropped
User prompt
Win system. Level get hard then the level was correct
Code edit (1 edits merged)
Please save this source code
User prompt
Hindi Word Builder
Initial prompt
A game that ask english into hindi meaning. We arrange the correct order the word. The game is hindi education base.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var DropZone = Container.expand(function (index) { var self = Container.call(this); self.index = index; self.occupiedTile = null; self.background = self.attachAsset('dropZone', { anchorX: 0.5, anchorY: 0.5 }); // Add text display for showing placed letter self.placedLetterText = new Text2('', { size: 40, fill: 0x333333 }); self.placedLetterText.anchor.set(0.5, 0.5); self.placedLetterText.y = -80; // Position above the drop zone self.addChild(self.placedLetterText); self.isEmpty = function () { return self.occupiedTile === null; }; self.placeTile = function (tile) { if (self.occupiedTile) { self.occupiedTile.isPlaced = false; } self.occupiedTile = tile; tile.isPlaced = true; tile.x = self.x; tile.y = self.y; // Update the text display to show the placed letter self.placedLetterText.setText(tile.letter); }; self.removeTile = function () { if (self.occupiedTile) { self.occupiedTile.isPlaced = false; self.occupiedTile = null; } // Clear the text display when tile is removed self.placedLetterText.setText(''); }; return self; }); var LetterTile = Container.expand(function (letter, isCorrect) { var self = Container.call(this); self.letter = letter; self.isCorrect = isCorrect || false; self.isPlaced = false; self.originalX = 0; self.originalY = 0; self.isDragging = false; self.background = self.attachAsset('letterTile', { anchorX: 0.5, anchorY: 0.5 }); self.letterText = new Text2(letter, { size: 60, fill: 0x000000 }); self.letterText.anchor.set(0.5, 0.5); self.addChild(self.letterText); self.setCorrect = function () { self.removeChild(self.background); self.background = self.attachAsset('correctTile', { anchorX: 0.5, anchorY: 0.5 }); self.addChildAt(self.background, 0); self.isCorrect = true; }; self.setWrong = function () { self.removeChild(self.background); self.background = self.attachAsset('wrongTile', { anchorX: 0.5, anchorY: 0.5 }); self.addChildAt(self.background, 0); tween(self.background, { tint: 0xffffff }, { duration: 1000 }); }; self.resetTile = function () { self.removeChild(self.background); self.background = self.attachAsset('letterTile', { anchorX: 0.5, anchorY: 0.5 }); self.addChildAt(self.background, 0); self.isCorrect = false; self.isPlaced = false; }; self.down = function (x, y, obj) { if (!self.isCorrect) { self.isDragging = true; draggedTile = self; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xf5f5f5 }); /**** * Game Code ****/ var words = [{ english: "CAT", hindi: "बिल्ली", letters: ["बि", "ल्ली"] }, { english: "DOG", hindi: "कुत्ता", letters: ["कु", "त्ता"] }, { english: "BOOK", hindi: "किताब", letters: ["कि", "ता", "ब"] }, { english: "WATER", hindi: "पानी", letters: ["पा", "नी"] }, { english: "HOUSE", hindi: "घर", letters: ["घ", "र"] }, { english: "FLOWER", hindi: "फूल", letters: ["फू", "ल"] }, { english: "TREE", hindi: "पेड़", letters: ["पे", "ड़"] }, { english: "BIRD", hindi: "पक्षी", letters: ["प", "क्षी"] }, { english: "FISH", hindi: "मछली", letters: ["म", "छ", "ली"] }, { english: "STAR", hindi: "तारा", letters: ["ता", "रा"] }]; // Shuffle all words at game start words = shuffleArray(words); var currentWordIndex = 0; var currentWord = words[currentWordIndex]; var letterTiles = []; var dropZones = []; var draggedTile = null; var gameCompleted = false; var currentLevel = 1; var wordsPerLevel = 3; var totalLevels = Math.ceil(words.length / wordsPerLevel); var wordsCompletedInLevel = 0; var levelScore = 0; var maxLives = 3; var currentLives = maxLives; var wrongAttempts = 0; var maxWrongAttempts = 2; // Allow 2 wrong attempts per word before losing a life // UI Elements var englishWordText = new Text2('', { size: 80, fill: 0x333333 }); englishWordText.anchor.set(0.5, 0.5); englishWordText.x = 1024; englishWordText.y = 300; game.addChild(englishWordText); var hindiWordText = new Text2('', { size: 60, fill: 0x666666 }); hindiWordText.anchor.set(0.5, 0.5); hindiWordText.x = 1024; hindiWordText.y = 380; game.addChild(hindiWordText); var instructionText = new Text2('Drag the Hindi letters to form the word:', { size: 40, fill: 0x888888 }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 1024; instructionText.y = 500; game.addChild(instructionText); // Score display var scoreText = new Text2('Score: 0', { size: 50, fill: 0x333333 }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Level display var levelText = new Text2('Level: 1', { size: 50, fill: 0x333333 }); levelText.anchor.set(0.5, 0); levelText.x = 300; LK.gui.top.addChild(levelText); // Lives display var livesText = new Text2('Lives: ♥♥♥', { size: 50, fill: 0xff0000 }); livesText.anchor.set(0.5, 0); livesText.x = -300; LK.gui.top.addChild(livesText); function updateLivesDisplay() { var heartsText = ''; for (var i = 0; i < currentLives; i++) { heartsText += '♥'; } for (var i = currentLives; i < maxLives; i++) { heartsText += '♡'; } livesText.setText('Lives: ' + heartsText); } function shuffleArray(array) { var shuffled = array.slice(); for (var i = shuffled.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = shuffled[i]; shuffled[i] = shuffled[j]; shuffled[j] = temp; } return shuffled; } function createLetterTiles() { // Clear existing tiles for (var i = 0; i < letterTiles.length; i++) { letterTiles[i].destroy(); } letterTiles = []; var shuffledLetters = shuffleArray(currentWord.letters); var startX = 1024 - (shuffledLetters.length - 1) * 140 / 2; for (var i = 0; i < shuffledLetters.length; i++) { var tile = new LetterTile(shuffledLetters[i]); tile.x = startX + i * 140; tile.y = 2000; tile.originalX = tile.x; tile.originalY = tile.y; letterTiles.push(tile); game.addChild(tile); } } function createDropZones() { // Clear existing zones for (var i = 0; i < dropZones.length; i++) { dropZones[i].destroy(); } dropZones = []; var startX = 1024 - (currentWord.letters.length - 1) * 140 / 2; for (var i = 0; i < currentWord.letters.length; i++) { var zone = new DropZone(i); zone.x = startX + i * 140; zone.y = 1200; dropZones.push(zone); game.addChild(zone); } } function checkWord() { var formedWord = ""; var allPlaced = true; for (var i = 0; i < dropZones.length; i++) { if (dropZones[i].occupiedTile) { formedWord += dropZones[i].occupiedTile.letter; } else { allPlaced = false; break; } } if (allPlaced) { if (formedWord === currentWord.hindi) { // Correct word LK.getSound('correct').play(); var pointsAwarded = 10 * currentLevel; // More points for higher levels LK.setScore(LK.getScore() + pointsAwarded); scoreText.setText('Score: ' + LK.getScore()); // Mark tiles as correct for (var i = 0; i < dropZones.length; i++) { if (dropZones[i].occupiedTile) { dropZones[i].occupiedTile.setCorrect(); } } // Show correct Hindi word hindiWordText.setText('✓ ' + currentWord.hindi); hindiWordText.tint = 0x00aa00; // Move to next word after delay - less time for higher levels var delayTime = Math.max(1000, 2500 - currentLevel * 200); LK.setTimeout(function () { nextWord(); }, delayTime); } else { // Wrong word LK.getSound('wrong').play(); wrongAttempts++; // Reduce life immediately for wrong answer currentLives--; updateLivesDisplay(); // Show wrong feedback for (var i = 0; i < dropZones.length; i++) { if (dropZones[i].occupiedTile) { dropZones[i].occupiedTile.setWrong(); } } // Check for game over if (currentLives <= 0) { LK.setTimeout(function () { LK.showGameOver(); }, 1500); return; } // Show life lost message var lifeLostText = new Text2('Life Lost!', { size: 60, fill: 0xff0000 }); lifeLostText.anchor.set(0.5, 0.5); lifeLostText.x = 1024; lifeLostText.y = 900; game.addChild(lifeLostText); LK.setTimeout(function () { lifeLostText.destroy(); }, 1500); // Reset after delay LK.setTimeout(function () { resetCurrentWord(); }, 1500); } } } function nextLevel() { currentLevel++; wordsCompletedInLevel = 0; levelScore = 0; // Update level display levelText.setText('Level: ' + currentLevel); // Show level complete message var levelCompleteText = new Text2('Level ' + (currentLevel - 1) + ' Complete!', { size: 60, fill: 0x00aa00 }); levelCompleteText.anchor.set(0.5, 0.5); levelCompleteText.x = 1024; levelCompleteText.y = 800; game.addChild(levelCompleteText); // Create options for player var winOptionText = new Text2('You Won This Level!', { size: 50, fill: 0x00aa00 }); winOptionText.anchor.set(0.5, 0.5); winOptionText.x = 1024; winOptionText.y = 900; game.addChild(winOptionText); var playNextButton = new Text2('Play Next', { size: 40, fill: 0x0066cc }); playNextButton.anchor.set(0.5, 0.5); playNextButton.x = 1024; playNextButton.y = 1000; game.addChild(playNextButton); var playAgainButton = new Text2('Play Again', { size: 40, fill: 0xcc6600 }); playAgainButton.anchor.set(0.5, 0.5); playAgainButton.x = 1024; playAgainButton.y = 1100; game.addChild(playAgainButton); // Add button functionality playNextButton.down = function () { levelCompleteText.destroy(); winOptionText.destroy(); playNextButton.destroy(); playAgainButton.destroy(); }; playAgainButton.down = function () { // Reset to current level beginning currentWordIndex = (currentLevel - 1) * wordsPerLevel; wordsCompletedInLevel = 0; currentWord = words[currentWordIndex]; levelCompleteText.destroy(); winOptionText.destroy(); playNextButton.destroy(); playAgainButton.destroy(); setupWord(); }; // Flash effect for visual feedback LK.effects.flashObject(levelCompleteText, 0x00aa00, 2000); } function nextWord() { currentWordIndex++; wordsCompletedInLevel++; levelScore += 10; wrongAttempts = 0; // Reset wrong attempts for new word // Check if level is complete if (wordsCompletedInLevel >= wordsPerLevel) { // Level completed if (currentLevel >= totalLevels) { // Game completed - all levels finished gameCompleted = true; LK.getSound('complete').play(); LK.showYouWin(); return; } else { // Move to next level nextLevel(); } } if (currentWordIndex >= words.length) { // All words completed gameCompleted = true; LK.getSound('complete').play(); LK.showYouWin(); return; } currentWord = words[currentWordIndex]; setupWord(); } function resetCurrentWord() { for (var i = 0; i < letterTiles.length; i++) { letterTiles[i].resetTile(); letterTiles[i].x = letterTiles[i].originalX; letterTiles[i].y = letterTiles[i].originalY; } for (var i = 0; i < dropZones.length; i++) { dropZones[i].removeTile(); } hindiWordText.setText(''); hindiWordText.tint = 0x666666; } function setupWord() { englishWordText.setText(currentWord.english); hindiWordText.setText(''); hindiWordText.tint = 0x666666; createLetterTiles(); createDropZones(); } function findNearestDropZone(x, y) { var nearest = null; var minDistance = Infinity; for (var i = 0; i < dropZones.length; i++) { var dx = x - dropZones[i].x; var dy = y - dropZones[i].y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < minDistance && distance < 100) { minDistance = distance; nearest = dropZones[i]; } } return nearest; } // Initialize lives display updateLivesDisplay(); // Initialize first word setupWord(); // Game controls game.move = function (x, y, obj) { if (draggedTile && draggedTile.isDragging) { draggedTile.x = x; draggedTile.y = y; } }; game.up = function (x, y, obj) { if (draggedTile && draggedTile.isDragging) { draggedTile.isDragging = false; var nearestZone = findNearestDropZone(x, y); if (nearestZone) { // Remove tile from previous zone if it was placed for (var i = 0; i < dropZones.length; i++) { if (dropZones[i].occupiedTile === draggedTile) { dropZones[i].removeTile(); break; } } // Place tile in new zone nearestZone.placeTile(draggedTile); // Check if word is complete LK.setTimeout(function () { checkWord(); }, 100); } else { // Return to original position if (draggedTile.isPlaced) { // Find and remove from current zone for (var i = 0; i < dropZones.length; i++) { if (dropZones[i].occupiedTile === draggedTile) { dropZones[i].removeTile(); break; } } } tween(draggedTile, { x: draggedTile.originalX, y: draggedTile.originalY }, { duration: 300, easing: tween.easeOut }); } draggedTile = null; } }; game.update = function () { // Update score display scoreText.setText('Score: ' + LK.getScore()); // Update level display levelText.setText('Level: ' + currentLevel + ' (' + wordsCompletedInLevel + '/' + wordsPerLevel + ')'); // Update lives display updateLivesDisplay(); };
===================================================================
--- original.js
+++ change.js
@@ -156,8 +156,10 @@
english: "STAR",
hindi: "तारा",
letters: ["ता", "रा"]
}];
+// Shuffle all words at game start
+words = shuffleArray(words);
var currentWordIndex = 0;
var currentWord = words[currentWordIndex];
var letterTiles = [];
var dropZones = [];