User prompt
Oyun bölümler halinde olmalı ve her bölümden önce ana sayfada olmalıyız
User prompt
Oyunda daha fazla kelime olsun
User prompt
Please fix the bug: 'storage.getItem is not a function' in or related to this line: 'var currentLevel = storage.getItem('currentLevel') || 1;' Line Number: 167 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Oyun bölüm bölüm olsun bir bölüm bitince ana sayfaya dönüp yeni bölüme geçelim
User prompt
Her doğruda 10 puan kazanıp her yanlışta 5 puan kaybedelim skor ekranda yazsin
Code edit (1 edits merged)
Please save this source code
User prompt
Word Match: English-Turkish
Initial prompt
> Project Title: Mobile Word Matching Game (English–Turkish) Project Description: I want to build a 2-column word matching game for mobile (Android and optionally iOS), similar to the layout in the attached image. The game should allow users to match English and Turkish words by tapping. When a correct match is made, both words are disabled or marked as matched. If the match is incorrect, the selection resets after a short delay. Visual Style: Cartoonish, colorful, fun interface Rounded buttons with shadows and simple animations Background like a night scene with soft light elements (similar to the image) Button layout: Words appear in a grid, English words and Turkish words are shuffled Game Logic: Words are presented as buttons in a shuffled order. The player taps two words (one after the other). If the words match (e.g., "SOCKS" = "çorap"), mark them as correct (disable or animate). If incorrect, reset both selections after a delay. There is a mistake counter (3 hearts or 3 tries). Game ends when mistakes run out or all matches are found. Score system optional but nice to have. Sample Word Pairs (can be stored in a JSON or scriptable object): "ALREADY" — "çoktan" "MUSICIAN" — "müzisyen" "PHOTOGRAPHER" — "fotoğrafçı" "SOCKS" — "çorap" "FEW" — "bir kaç" "LEARNT" — "öğrenilen" Extra Features (Optional but nice): Light background music and simple click sounds Hints (like revealing one match) Animated hearts or mistake counter Level system with increasing difficulty (more pairs)
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var HeartDisplay = Container.expand(function () { var self = Container.call(this); self.hearts = []; self.maxHearts = 3; self.currentHearts = 3; for (var i = 0; i < self.maxHearts; i++) { var heart = self.attachAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); heart.x = i * 80; self.hearts.push(heart); } self.loseHeart = function () { if (self.currentHearts > 0) { self.currentHearts--; var heartToRemove = self.hearts[self.currentHearts]; heartToRemove.tint = 0x666666; tween(heartToRemove, { scaleX: 0.5, scaleY: 0.5 }, { duration: 300 }); if (self.currentHearts === 0) { LK.setTimeout(function () { LK.showGameOver(); }, 1000); } } }; return self; }); var LevelButton = Container.expand(function (levelNumber) { var self = Container.call(this); self.levelNumber = levelNumber; var buttonShape = self.attachAsset('wordButton', { anchorX: 0.5, anchorY: 0.5 }); var levelText = new Text2("Level " + levelNumber, { size: 28, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0.5); self.addChild(levelText); // Check if level is unlocked var isUnlocked = levelNumber <= (storage.currentLevel || 1); if (!isUnlocked) { buttonShape.tint = 0x666666; levelText.tint = 0x666666; } self.down = function (x, y, obj) { if (isUnlocked) { startLevel(levelNumber); } }; return self; }); var WordButton = Container.expand(function (word, isEnglish) { var self = Container.call(this); self.word = word; self.isEnglish = isEnglish; self.isSelected = false; self.isMatched = false; var buttonShape = self.attachAsset('wordButton', { anchorX: 0.5, anchorY: 0.5 }); var wordText = new Text2(word, { size: 32, fill: 0xFFFFFF }); wordText.anchor.set(0.5, 0.5); self.addChild(wordText); self.setSelected = function (selected) { self.isSelected = selected; if (selected) { buttonShape.tint = 0x2196F3; } else { buttonShape.tint = 0x4CAF50; } }; self.setMatched = function () { self.isMatched = true; buttonShape.tint = 0x8BC34A; tween(self, { alpha: 0.7 }, { duration: 300 }); }; self.showIncorrect = function () { buttonShape.tint = 0xFF5722; tween(self, { scaleX: 1.1, scaleY: 1.1 }, { duration: 150, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 150 }); } }); }; self.down = function (x, y, obj) { if (!self.isMatched) { handleWordButtonPress(self); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ var allLevels = [ // Level 1 [{ english: "ALREADY", turkish: "çoktan" }, { english: "MUSICIAN", turkish: "müzisyen" }, { english: "SOCKS", turkish: "çorap" }, { english: "FEW", turkish: "bir kaç" }, { english: "BOOK", turkish: "kitap" }, { english: "HOUSE", turkish: "ev" }, { english: "CAR", turkish: "araba" }, { english: "DOG", turkish: "köpek" }], // Level 2 [{ english: "PHOTOGRAPHER", turkish: "fotoğrafçı" }, { english: "LEARNT", turkish: "öğrenilen" }, { english: "BEAUTIFUL", turkish: "güzel" }, { english: "KITCHEN", turkish: "mutfak" }, { english: "TEACHER", turkish: "öğretmen" }, { english: "DOCTOR", turkish: "doktor" }, { english: "STUDENT", turkish: "öğrenci" }, { english: "FAMILY", turkish: "aile" }], // Level 3 [{ english: "COMPUTER", turkish: "bilgisayar" }, { english: "SCHOOL", turkish: "okul" }, { english: "FRIEND", turkish: "arkadaş" }, { english: "WATER", turkish: "su" }, { english: "TELEPHONE", turkish: "telefon" }, { english: "HOSPITAL", turkish: "hastane" }, { english: "RESTAURANT", turkish: "restoran" }, { english: "AIRPLANE", turkish: "uçak" }]]; var currentLevel = storage.currentLevel || 1; var wordPairs = allLevels[currentLevel - 1] || allLevels[0]; var englishWords = []; var turkishWords = []; var selectedButton = null; var matchedPairs = 0; var heartDisplay; var isProcessing = false; var currentScore = 0; var scoreText; var gameState = "menu"; // "menu" or "playing" var menuElements = []; function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } } function showMainMenu() { gameState = "menu"; clearGameElements(); // Main title var mainTitle = new Text2("Word Match", { size: 64, fill: 0xFFFFFF }); mainTitle.anchor.set(0.5, 0.5); mainTitle.x = 2048 / 2; mainTitle.y = 500; game.addChild(mainTitle); menuElements.push(mainTitle); // Subtitle var subtitle = new Text2("English - Turkish", { size: 40, fill: 0x00BCD4 }); subtitle.anchor.set(0.5, 0.5); subtitle.x = 2048 / 2; subtitle.y = 600; game.addChild(subtitle); menuElements.push(subtitle); // Level selection var levelTitle = new Text2("Select Level:", { size: 48, fill: 0xFFFFFF }); levelTitle.anchor.set(0.5, 0.5); levelTitle.x = 2048 / 2; levelTitle.y = 800; game.addChild(levelTitle); menuElements.push(levelTitle); // Level buttons for (var i = 1; i <= allLevels.length; i++) { var levelButton = new LevelButton(i); levelButton.x = 2048 / 2 + (i - 2) * 200; levelButton.y = 1000; game.addChild(levelButton); menuElements.push(levelButton); } // Score display var totalScoreText = new Text2("Total Score: " + currentScore, { size: 36, fill: 0xFFD700 }); totalScoreText.anchor.set(0.5, 0.5); totalScoreText.x = 2048 / 2; totalScoreText.y = 1200; game.addChild(totalScoreText); menuElements.push(totalScoreText); } function clearGameElements() { // Clear menu elements for (var i = 0; i < menuElements.length; i++) { menuElements[i].destroy(); } menuElements = []; // Clear game elements for (var i = 0; i < englishWords.length; i++) { englishWords[i].destroy(); } for (var i = 0; i < turkishWords.length; i++) { turkishWords[i].destroy(); } englishWords = []; turkishWords = []; } function startLevel(level) { gameState = "playing"; currentLevel = level; storage.currentLevel = currentLevel; wordPairs = allLevels[currentLevel - 1]; clearGameElements(); initializeGameElements(); createWordButtons(); } function createWordButtons() { var englishList = []; var turkishList = []; for (var i = 0; i < wordPairs.length; i++) { englishList.push(wordPairs[i].english); turkishList.push(wordPairs[i].turkish); } shuffleArray(englishList); shuffleArray(turkishList); // Create English column for (var i = 0; i < englishList.length; i++) { var englishButton = new WordButton(englishList[i], true); englishButton.x = 2048 * 0.25; englishButton.y = 300 + i * 120; englishWords.push(englishButton); game.addChild(englishButton); } // Create Turkish column for (var i = 0; i < turkishList.length; i++) { var turkishButton = new WordButton(turkishList[i], false); turkishButton.x = 2048 * 0.75; turkishButton.y = 300 + i * 120; turkishWords.push(turkishButton); game.addChild(turkishButton); } } function findMatchingWord(word, isEnglish) { for (var i = 0; i < wordPairs.length; i++) { if (isEnglish && wordPairs[i].english === word) { return wordPairs[i].turkish; } else if (!isEnglish && wordPairs[i].turkish === word) { return wordPairs[i].english; } } return null; } function initializeGameElements() { // Initialize heart display if (heartDisplay) heartDisplay.destroy(); heartDisplay = new HeartDisplay(); heartDisplay.x = 2048 / 2 - 120; heartDisplay.y = 150; LK.gui.top.addChild(heartDisplay); // Add title var titleText = new Text2("Word Match: English-Turkish", { size: 48, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0); titleText.x = 2048 / 2; titleText.y = 50; game.addChild(titleText); // Add level display var levelText = new Text2("Level " + currentLevel, { size: 36, fill: 0x00BCD4 }); levelText.anchor.set(0.5, 0); levelText.x = 2048 / 2; levelText.y = 2000; game.addChild(levelText); // Add score display scoreText = new Text2("Score: " + currentScore, { size: 36, fill: 0xFFD700 }); scoreText.anchor.set(0.5, 0); scoreText.x = 2048 / 2; scoreText.y = 100; game.addChild(scoreText); // Reset game state selectedButton = null; matchedPairs = 0; isProcessing = false; heartDisplay.currentHearts = 3; // Reset hearts display for (var i = 0; i < heartDisplay.hearts.length; i++) { heartDisplay.hearts[i].tint = 0xff1744; heartDisplay.hearts[i].scaleX = 1; heartDisplay.hearts[i].scaleY = 1; } } function resetGameForNextLevel() { currentScore += 50; // Bonus for completing level // Return to main menu after level completion LK.setTimeout(function () { showMainMenu(); }, 1500); } function handleWordButtonPress(button) { if (isProcessing) return; if (selectedButton === null) { selectedButton = button; button.setSelected(true); } else if (selectedButton === button) { selectedButton.setSelected(false); selectedButton = null; } else { isProcessing = true; var firstWord = selectedButton.word; var secondWord = button.word; var isFirstEnglish = selectedButton.isEnglish; var matchingWord = findMatchingWord(firstWord, isFirstEnglish); if (matchingWord === secondWord) { // Correct match selectedButton.setMatched(); button.setMatched(); matchedPairs++; currentScore += 10; scoreText.setText("Score: " + currentScore); LK.getSound('correct').play(); if (matchedPairs === wordPairs.length) { LK.setTimeout(function () { // Unlock next level if (currentLevel < allLevels.length) { storage.currentLevel = Math.max(storage.currentLevel || 1, currentLevel + 1); } // Complete current level and return to menu resetGameForNextLevel(); if (currentLevel >= allLevels.length) { // All levels completed LK.setTimeout(function () { LK.showYouWin(); }, 2000); } }, 1000); } selectedButton = null; isProcessing = false; } else { // Incorrect match selectedButton.showIncorrect(); button.showIncorrect(); heartDisplay.loseHeart(); currentScore -= 5; if (currentScore < 0) currentScore = 0; scoreText.setText("Score: " + currentScore); LK.getSound('incorrect').play(); LK.getSound('heartLost').play(); LK.setTimeout(function () { selectedButton.setSelected(false); button.setSelected(false); selectedButton = null; isProcessing = false; }, 1000); } } } // Show main menu at start showMainMenu(); game.update = function () { // Game logic is handled by button presses and timers };
===================================================================
--- original.js
+++ change.js
@@ -39,8 +39,34 @@
}
};
return self;
});
+var LevelButton = Container.expand(function (levelNumber) {
+ var self = Container.call(this);
+ self.levelNumber = levelNumber;
+ var buttonShape = self.attachAsset('wordButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var levelText = new Text2("Level " + levelNumber, {
+ size: 28,
+ fill: 0xFFFFFF
+ });
+ levelText.anchor.set(0.5, 0.5);
+ self.addChild(levelText);
+ // Check if level is unlocked
+ var isUnlocked = levelNumber <= (storage.currentLevel || 1);
+ if (!isUnlocked) {
+ buttonShape.tint = 0x666666;
+ levelText.tint = 0x666666;
+ }
+ self.down = function (x, y, obj) {
+ if (isUnlocked) {
+ startLevel(levelNumber);
+ }
+ };
+ return self;
+});
var WordButton = Container.expand(function (word, isEnglish) {
var self = Container.call(this);
self.word = word;
self.isEnglish = isEnglish;
@@ -196,16 +222,95 @@
var heartDisplay;
var isProcessing = false;
var currentScore = 0;
var scoreText;
+var gameState = "menu"; // "menu" or "playing"
+var menuElements = [];
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
+function showMainMenu() {
+ gameState = "menu";
+ clearGameElements();
+ // Main title
+ var mainTitle = new Text2("Word Match", {
+ size: 64,
+ fill: 0xFFFFFF
+ });
+ mainTitle.anchor.set(0.5, 0.5);
+ mainTitle.x = 2048 / 2;
+ mainTitle.y = 500;
+ game.addChild(mainTitle);
+ menuElements.push(mainTitle);
+ // Subtitle
+ var subtitle = new Text2("English - Turkish", {
+ size: 40,
+ fill: 0x00BCD4
+ });
+ subtitle.anchor.set(0.5, 0.5);
+ subtitle.x = 2048 / 2;
+ subtitle.y = 600;
+ game.addChild(subtitle);
+ menuElements.push(subtitle);
+ // Level selection
+ var levelTitle = new Text2("Select Level:", {
+ size: 48,
+ fill: 0xFFFFFF
+ });
+ levelTitle.anchor.set(0.5, 0.5);
+ levelTitle.x = 2048 / 2;
+ levelTitle.y = 800;
+ game.addChild(levelTitle);
+ menuElements.push(levelTitle);
+ // Level buttons
+ for (var i = 1; i <= allLevels.length; i++) {
+ var levelButton = new LevelButton(i);
+ levelButton.x = 2048 / 2 + (i - 2) * 200;
+ levelButton.y = 1000;
+ game.addChild(levelButton);
+ menuElements.push(levelButton);
+ }
+ // Score display
+ var totalScoreText = new Text2("Total Score: " + currentScore, {
+ size: 36,
+ fill: 0xFFD700
+ });
+ totalScoreText.anchor.set(0.5, 0.5);
+ totalScoreText.x = 2048 / 2;
+ totalScoreText.y = 1200;
+ game.addChild(totalScoreText);
+ menuElements.push(totalScoreText);
+}
+function clearGameElements() {
+ // Clear menu elements
+ for (var i = 0; i < menuElements.length; i++) {
+ menuElements[i].destroy();
+ }
+ menuElements = [];
+ // Clear game elements
+ for (var i = 0; i < englishWords.length; i++) {
+ englishWords[i].destroy();
+ }
+ for (var i = 0; i < turkishWords.length; i++) {
+ turkishWords[i].destroy();
+ }
+ englishWords = [];
+ turkishWords = [];
+}
+function startLevel(level) {
+ gameState = "playing";
+ currentLevel = level;
+ storage.currentLevel = currentLevel;
+ wordPairs = allLevels[currentLevel - 1];
+ clearGameElements();
+ initializeGameElements();
+ createWordButtons();
+}
function createWordButtons() {
var englishList = [];
var turkishList = [];
for (var i = 0; i < wordPairs.length; i++) {
@@ -240,37 +345,61 @@
}
}
return null;
}
-function resetGameForNextLevel() {
- // Clear existing buttons
- for (var i = 0; i < englishWords.length; i++) {
- englishWords[i].destroy();
- }
- for (var i = 0; i < turkishWords.length; i++) {
- turkishWords[i].destroy();
- }
+function initializeGameElements() {
+ // Initialize heart display
+ if (heartDisplay) heartDisplay.destroy();
+ heartDisplay = new HeartDisplay();
+ heartDisplay.x = 2048 / 2 - 120;
+ heartDisplay.y = 150;
+ LK.gui.top.addChild(heartDisplay);
+ // Add title
+ var titleText = new Text2("Word Match: English-Turkish", {
+ size: 48,
+ fill: 0xFFFFFF
+ });
+ titleText.anchor.set(0.5, 0);
+ titleText.x = 2048 / 2;
+ titleText.y = 50;
+ game.addChild(titleText);
+ // Add level display
+ var levelText = new Text2("Level " + currentLevel, {
+ size: 36,
+ fill: 0x00BCD4
+ });
+ levelText.anchor.set(0.5, 0);
+ levelText.x = 2048 / 2;
+ levelText.y = 2000;
+ game.addChild(levelText);
+ // Add score display
+ scoreText = new Text2("Score: " + currentScore, {
+ size: 36,
+ fill: 0xFFD700
+ });
+ scoreText.anchor.set(0.5, 0);
+ scoreText.x = 2048 / 2;
+ scoreText.y = 100;
+ game.addChild(scoreText);
// Reset game state
- englishWords = [];
- turkishWords = [];
selectedButton = null;
matchedPairs = 0;
isProcessing = false;
- currentScore += 50; // Bonus for completing level
heartDisplay.currentHearts = 3;
// Reset hearts display
for (var i = 0; i < heartDisplay.hearts.length; i++) {
heartDisplay.hearts[i].tint = 0xff1744;
heartDisplay.hearts[i].scaleX = 1;
heartDisplay.hearts[i].scaleY = 1;
}
- // Update displays
- wordPairs = allLevels[currentLevel - 1];
- scoreText.setText("Score: " + currentScore);
- levelText.setText("Level " + currentLevel);
- // Create new word buttons for next level
- createWordButtons();
}
+function resetGameForNextLevel() {
+ currentScore += 50; // Bonus for completing level
+ // Return to main menu after level completion
+ LK.setTimeout(function () {
+ showMainMenu();
+ }, 1500);
+}
function handleWordButtonPress(button) {
if (isProcessing) return;
if (selectedButton === null) {
selectedButton = button;
@@ -293,17 +422,19 @@
scoreText.setText("Score: " + currentScore);
LK.getSound('correct').play();
if (matchedPairs === wordPairs.length) {
LK.setTimeout(function () {
+ // Unlock next level
if (currentLevel < allLevels.length) {
- // Advance to next level
- currentLevel++;
- storage.currentLevel = currentLevel;
- // Reset game for next level
- resetGameForNextLevel();
- } else {
+ storage.currentLevel = Math.max(storage.currentLevel || 1, currentLevel + 1);
+ }
+ // Complete current level and return to menu
+ resetGameForNextLevel();
+ if (currentLevel >= allLevels.length) {
// All levels completed
- LK.showYouWin();
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 2000);
}
}, 1000);
}
selectedButton = null;
@@ -326,41 +457,9 @@
}, 1000);
}
}
}
-// Initialize heart display
-heartDisplay = new HeartDisplay();
-heartDisplay.x = 2048 / 2 - 120;
-heartDisplay.y = 150;
-LK.gui.top.addChild(heartDisplay);
-// Add title
-var titleText = new Text2("Word Match: English-Turkish", {
- size: 48,
- fill: 0xFFFFFF
-});
-titleText.anchor.set(0.5, 0);
-titleText.x = 2048 / 2;
-titleText.y = 50;
-game.addChild(titleText);
-// Add level display
-var levelText = new Text2("Level " + currentLevel, {
- size: 36,
- fill: 0x00BCD4
-});
-levelText.anchor.set(0.5, 0);
-levelText.x = 2048 / 2;
-levelText.y = 2000;
-game.addChild(levelText);
-// Add score display
-scoreText = new Text2("Score: 0", {
- size: 36,
- fill: 0xFFD700
-});
-scoreText.anchor.set(0.5, 0);
-scoreText.x = 2048 / 2;
-scoreText.y = 100;
-game.addChild(scoreText);
-// Create word buttons
-createWordButtons();
+// Show main menu at start
+showMainMenu();
game.update = function () {
// Game logic is handled by button presses and timers
};
\ No newline at end of file