User prompt
the game cannot reload me pls fix
User prompt
remove old entirys
User prompt
to reload . see that have in game entiry or not. then reload the game
User prompt
when we reset do not rest the leader bord
User prompt
Please fix the bug: 'can't access property "length", keyboardChars is undefined' in or related to this line: 'for (var i = 0; i < keyboardChars.length; i++) {' Line Number: 718
User prompt
Please fix the bug: 'can't access property "length", keyboardChars is undefined' in or related to this line: 'for (var i = 0; i < keyboardChars.length; i++) {' Line Number: 718
User prompt
Please fix the bug: 'can't access property "length", keyboardChars is undefined' in or related to this line: 'for (var i = 0; i < keyboardChars.length; i++) {' Line Number: 718
User prompt
add keybord in reload button to write name
User prompt
Please fix the bug: 'can't access property "length", numberChars is undefined' in or related to this line: 'for (var i = 0; i < numberChars.length; i++) {' Line Number: 717
User prompt
shift reload button below of reset. add one more type thing that set passwrodwith number only.
User prompt
i cannot write name and password to reload the game. when new player play. player set password also. to reload. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
when we click on reload button hide another things ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
do add reload button when we reset .we can back idea with passward and name ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
when the player take name do not same name another ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
when we enter name remove the name change thing ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
do reset me in my game. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
start new game of my
User prompt
remove old enetiry inleaderbord ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
do upadte the old socer not new add in leaderbord ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'can't access property 0, storage.leaderboardDates is undefined' in or related to this line: 'leaderboard.push({' Line Number: 167
User prompt
Please fix the bug: 'Error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.leaderboard = leaderboard;' Line Number: 736 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
do remove leaderbord enetriy. do new ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Fix the problem in leaderboard that no does fix name. Do not mulity name. Only one name that enter when new player come. do not do same name scores only when we give answer do when game over then our socer in leaderbord. total ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
do fix leaderbord tell total score and stars.
User prompt
add 5 more logo
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var OptionButton = Container.expand(function (text, isCorrect, index) {
var self = Container.call(this);
self.isCorrect = isCorrect;
self.isSelected = false;
self.buttonIndex = index;
var buttonBg = self.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 48,
fill: 0x000000
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.setText = function (newText) {
buttonText.setText(newText);
};
self.showCorrect = function () {
buttonBg.destroy();
buttonBg = self.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeOut
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeOut
});
};
self.showWrong = function () {
buttonBg.destroy();
buttonBg = self.attachAsset('optionButtonWrong', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
tween(self, {
x: self.x + 10
}, {
duration: 50
});
tween(self, {
x: self.x - 10
}, {
duration: 50
});
tween(self, {
x: self.x
}, {
duration: 50
});
};
self.reset = function () {
self.isSelected = false;
buttonBg.destroy();
buttonBg = self.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChildAt(buttonBg, 0);
self.scaleX = 1.0;
self.scaleY = 1.0;
};
self.down = function (x, y, obj) {
if (gameState !== 'playing') return;
if (self.isCorrect) {
self.showCorrect();
handleCorrectAnswer();
} else {
self.showWrong();
handleWrongAnswer();
}
};
return self;
});
var StarDisplay = Container.expand(function () {
var self = Container.call(this);
var starBg = self.attachAsset('starIcon', {
anchorX: 0.5,
anchorY: 0.5
});
var starText = new Text2('0', {
size: 72,
fill: 0x000000
});
starText.anchor.set(0.5, 0.5);
self.addChild(starText);
self.updateStars = function (count) {
starText.setText(count.toString());
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFF8E1
});
/****
* Game Code
****/
// Game state variables
// Brand Logo Assets
var gameState = 'playing';
var currentLevel = 1;
var currentQuestion = 0;
var score = 0;
var stars = storage.stars || 0;
var highScore = storage.highScore || 0;
// New leaderboard entry structure
var leaderboard = storage.leaderboard || [];
var usedQuestions = [];
var lives = 3; // Initialize player lives
var playerName = storage.playerName || ''; // Store player name - empty string for new players
// Logo database
var logoDatabase = [
// Level 1 - Indian Brands
{
name: 'टाटा',
options: ['टाटा', 'रिलायंस', 'अडानी', 'बिड़ला'],
correct: 0,
fact: 'टाटा ग्रुप की स्थापना 1868 में जमशेदजी टाटा ने की थी।',
level: 1,
logoColor: 0x0066CC,
logoAssetId: 'tataLogo'
}, {
name: 'रिलायंस',
options: ['टाटा', 'रिलायंस', 'अडानी', 'बिड़ला'],
correct: 1,
fact: 'रिलायंस इंडस्ट्रीज भारत की सबसे बड़ी निजी कंपनी है।',
level: 1,
logoColor: 0xFF0000,
logoAssetId: 'relianceLogo'
}, {
name: 'बजाज',
options: ['हीरो', 'बजाज', 'टीवीएस', 'महिंद्रा'],
correct: 1,
fact: 'बजाज ऑटो भारत की प्रमुख मोटरसाइकिल निर्माता कंपनी है।',
level: 1,
logoColor: 0x0066FF,
logoAssetId: 'bajajLogo'
},
// Level 2 - International Brands
{
name: 'कोका-कोला',
options: ['पेप्सी', 'कोका-कोला', 'स्प्राइट', 'फैंटा'],
correct: 1,
fact: 'कोका-कोला दुनिया का सबसे प्रसिद्ध पेय पदार्थ ब्रांड है।',
level: 2,
logoColor: 0xDC143C,
logoAssetId: 'cocaColaLogo'
}, {
name: 'मैकडॉनल्ड्स',
options: ['केएफसी', 'मैकडॉनल्ड्स', 'बर्गर किंग', 'सबवे'],
correct: 1,
fact: 'मैकडॉनल्ड्स दुनिया की सबसे बड़ी फास्ट फूड चेन है।',
level: 2,
logoColor: 0xFFD700,
logoAssetId: 'mcdonaldsLogo'
}, {
name: 'गूगल',
options: ['माइक्रोसॉफ्ट', 'गूगल', 'एप्पल', 'अमेज़न'],
correct: 1,
fact: 'गूगल दुनिया का सबसे बड़ा सर्च इंजन है।',
level: 2,
logoColor: 0x4285f4,
logoAssetId: 'googleLogo'
}, {
name: 'अमेज़न',
options: ['ईबे', 'अमेज़न', 'अलीबाबा', 'शॉपिफाई'],
correct: 1,
fact: 'अमेज़न दुनिया की सबसे बड़ी ई-कॉमर्स कंपनी है।',
level: 2,
logoColor: 0xFF9900,
logoAssetId: 'amazonLogo'
}, {
name: 'इंफोसिस',
options: ['टीसीएस', 'इंफोसिस', 'विप्रो', 'एचसीएल'],
correct: 1,
fact: 'इंफोसिस भारत की प्रमुख आईटी कंपनी है।',
level: 1,
logoColor: 0x0066CC,
logoAssetId: 'infosysLogo'
}, {
name: 'फ्लिपकार्ट',
options: ['अमेज़न', 'फ्लिपकार्ट', 'स्नैपडील', 'मिंत्रा'],
correct: 1,
fact: 'फ्लिपकार्ट भारत की सबसे बड़ी ई-कॉमर्स कंपनी है।',
level: 1,
logoColor: 0xF7971E,
logoAssetId: 'flipkartLogo'
}, {
name: 'ज़ोमैटो',
options: ['स्विगी', 'ज़ोमैटो', 'उबर ईट्स', 'फूडपांडा'],
correct: 1,
fact: 'ज़ोमैटो भारत की प्रमुख फूड डिलीवरी कंपनी है।',
level: 1,
logoColor: 0xE23744,
logoAssetId: 'zomatoLogo'
}, {
name: 'ओला',
options: ['उबर', 'ओला', 'मेरु', 'लिफ्ट'],
correct: 1,
fact: 'ओला भारत की सबसे बड़ी राइड-शेयरिंग कंपनी है।',
level: 1,
logoColor: 0x000000,
logoAssetId: 'olaLogo'
}, {
name: 'पेटीएम',
options: ['गूगल पे', 'पेटीएम', 'फोनपे', 'भीम'],
correct: 1,
fact: 'पेटीएम भारत की सबसे बड़ी डिजिटल पेमेंट कंपनी है।',
level: 1,
logoColor: 0x00BAF2,
logoAssetId: 'paytmLogo'
}, {
name: 'जियो',
options: ['एयरटेल', 'जियो', 'वोडाफोन', 'बीएसएनएल'],
correct: 1,
fact: 'रिलायंस जियो भारत की सबसे बड़ी 4G नेटवर्क कंपनी है।',
level: 1,
logoColor: 0x0066FF,
logoAssetId: 'jioLogo'
}, {
name: 'एयरटेल',
options: ['जियो', 'एयरटेल', 'वोडाफोन', 'आइडिया'],
correct: 1,
fact: 'भारती एयरटेल भारत की दूसरी सबसे बड़ी टेलीकॉम कंपनी है।',
level: 1,
logoColor: 0xFF0000,
logoAssetId: 'airtelLogo'
}, {
name: 'बायजूस',
options: ['अनएकेडमी', 'बायजूस', 'वेदांतु', 'व्हाइट हैट जूनियर'],
correct: 1,
fact: 'बायजूस भारत की सबसे बड़ी ऑनलाइन शिक्षा कंपनी है।',
level: 2,
logoColor: 0x6C63FF,
logoAssetId: 'byjusLogo'
}, {
name: 'पतंजलि',
options: ['हिमालया', 'पतंजलि', 'डाबर', 'झंडू'],
correct: 1,
fact: 'पतंजलि आयुर्वेद भारत की प्रमुख आयुर्वेदिक उत्पाद कंपनी है।',
level: 1,
logoColor: 0x00A86B,
logoAssetId: 'patanjaliLogo'
}];
// UI Elements
var logoContainer;
var logoDisplay;
var optionButtons = [];
var starDisplay;
var scoreText;
var levelText;
var questionText;
var factText;
// Background
var background = game.attachAsset('backgroundPattern', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Logo container
logoContainer = game.attachAsset('logoContainer', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 400
});
// Logo display will be created dynamically in loadQuestion()
logoDisplay = null;
// Score display
scoreText = new Text2('स्कोर: ' + score, {
size: 48,
fill: 0xFF6B6B
});
scoreText.anchor.set(0.5, 0);
scoreText.x = 2048 / 2;
scoreText.y = 50;
game.addChild(scoreText);
// Fullscreen leaderboard overlay
var leaderboardOverlay = new Container();
leaderboardOverlay.visible = false; // Start hidden
game.addChild(leaderboardOverlay);
// Semi-transparent background
var leaderboardBg = LK.getAsset('optionButton', {
anchorX: 0,
anchorY: 0,
scaleX: 20.48,
scaleY: 27.32,
x: 0,
y: 0
});
leaderboardBg.alpha = 0.95;
leaderboardBg.tint = 0x1a1a1a;
leaderboardOverlay.addChild(leaderboardBg);
// Leaderboard display container
var leaderboardContainer = new Container();
leaderboardContainer.x = 2048 / 2;
leaderboardContainer.y = 400;
leaderboardOverlay.addChild(leaderboardContainer);
var leaderboardTitle = new Text2('🏆 लीडरबोर्ड 🏆', {
size: 72,
fill: 0xFFD700
});
leaderboardTitle.anchor.set(0.5, 0);
leaderboardContainer.addChild(leaderboardTitle);
// Create header
var headerBg = LK.getAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 0.8,
y: 100
});
headerBg.tint = 0x2c3e50;
leaderboardContainer.addChild(headerBg);
var headerText = new Text2('रैंक नाम स्कोर स्टार', {
size: 42,
fill: 0xFFFFFF
});
headerText.anchor.set(0.5, 0.5);
headerText.y = 100;
leaderboardContainer.addChild(headerText);
var leaderboardTexts = [];
for (var i = 0; i < 10; i++) {
// Entry background
var entryBg = LK.getAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 0.8,
y: 180 + i * 80
});
entryBg.tint = i % 2 === 0 ? 0x34495e : 0x2c3e50;
entryBg.alpha = 0.8;
leaderboardContainer.addChild(entryBg);
var entryText = new Text2('', {
size: 38,
fill: 0xFFFFFF
});
entryText.anchor.set(0.5, 0.5);
entryText.y = 180 + i * 80;
leaderboardTexts.push(entryText);
leaderboardContainer.addChild(entryText);
}
// Close button
var closeBtn = new Container();
closeBtn.x = 0;
closeBtn.y = 1100;
var closeBtnBg = closeBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1
});
closeBtnBg.tint = 0xe74c3c;
var closeBtnText = new Text2('बंद करें', {
size: 42,
fill: 0xFFFFFF
});
closeBtnText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeBtnText);
leaderboardContainer.addChild(closeBtn);
closeBtn.down = function () {
leaderboardOverlay.visible = false;
// Show game elements again
if (logoDisplay) logoDisplay.visible = true;
questionText.visible = true;
for (var i = 0; i < optionButtons.length; i++) {
optionButtons[i].visible = true;
}
factText.visible = true;
feedbackText.visible = true;
};
function updateLeaderboardDisplay() {
for (var i = 0; i < 10; i++) {
if (i < leaderboard.length) {
var rank = i + 1;
var medal = '';
if (rank === 1) medal = '🥇';else if (rank === 2) medal = '🥈';else if (rank === 3) medal = '🥉';else medal = rank + '.';
var entry = leaderboard[i];
leaderboardTexts[i].setText(medal + ' ' + entry.name + ' ' + entry.score + ' ' + entry.stars + '⭐');
} else {
leaderboardTexts[i].setText('');
}
}
}
updateLeaderboardDisplay();
// Add leaderboard toggle button
var leaderboardBtn = new Container();
leaderboardBtn.x = 2048 - 300;
leaderboardBtn.y = 180;
var leaderboardBtnBg = leaderboardBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.1,
scaleY: 1
});
var leaderboardBtnText = new Text2('लीडरबोर्ड देखें', {
size: 36,
fill: 0x000000
});
leaderboardBtnText.anchor.set(0.5, 0.5);
leaderboardBtn.addChild(leaderboardBtnText);
game.addChild(leaderboardBtn);
leaderboardBtn.down = function () {
leaderboardOverlay.visible = true;
updateLeaderboardDisplay();
// Hide game elements
if (logoDisplay) logoDisplay.visible = false;
questionText.visible = false;
for (var i = 0; i < optionButtons.length; i++) {
optionButtons[i].visible = false;
}
factText.visible = false;
feedbackText.visible = false;
};
// Level display
levelText = new Text2('स्तर: ' + currentLevel, {
size: 42,
fill: 0x4ECDC4
});
levelText.anchor.set(0, 0);
levelText.x = 150;
levelText.y = 50;
game.addChild(levelText);
// Stars display
starDisplay = new StarDisplay();
starDisplay.x = 2048 - 150;
starDisplay.y = 80;
starDisplay.updateStars(stars);
game.addChild(starDisplay);
// Lives display
var livesText = new Text2('जीवन: ' + lives, {
size: 42,
fill: 0xFF0000
});
livesText.anchor.set(0.5, 0);
livesText.x = 2048 / 2;
livesText.y = 120;
game.addChild(livesText);
// Question text
questionText = new Text2('लोगो पहचानें:', {
size: 72,
fill: 0x000000
});
questionText.anchor.set(0.5, 0);
questionText.x = 2048 / 2;
questionText.y = 700;
game.addChild(questionText);
// Create option buttons
for (var i = 0; i < 4; i++) {
var button = new OptionButton('विकल्प ' + (i + 1), false, i);
button.x = 2048 / 2;
button.y = 900 + i * 120;
optionButtons.push(button);
game.addChild(button);
}
// Fact display text
factText = new Text2('', {
size: 36,
fill: 0x7B68EE
});
factText.anchor.set(0.5, 0);
factText.x = 2048 / 2;
factText.y = 1500;
game.addChild(factText);
// Name input display
var nameInputContainer = new Container();
nameInputContainer.x = 2048 / 2;
nameInputContainer.y = 1366; // Center of screen
nameInputContainer.visible = false;
game.addChild(nameInputContainer);
var nameInputBg = LK.getAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 2
});
nameInputContainer.addChild(nameInputBg);
var nameInputTitle = new Text2('अपना नाम दर्ज करें:', {
size: 48,
fill: 0x000000
});
nameInputTitle.anchor.set(0.5, 0.5);
nameInputTitle.y = -60;
nameInputContainer.addChild(nameInputTitle);
var nameInputText = new Text2(playerName || 'टैप करके नाम दर्ज करें', {
size: 42,
fill: playerName ? 0x000000 : 0x666666
});
nameInputText.anchor.set(0.5, 0.5);
nameInputContainer.addChild(nameInputText);
var nameInputSaveBtn = new Container();
nameInputSaveBtn.y = 80;
var saveBtn = nameInputSaveBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
var saveBtnText = new Text2('सहेजें', {
size: 36,
fill: 0x000000
});
saveBtnText.anchor.set(0.5, 0.5);
nameInputSaveBtn.addChild(saveBtnText);
nameInputContainer.addChild(nameInputSaveBtn);
// Virtual keyboard for name input
var virtualKeyboard = new Container();
virtualKeyboard.y = 150;
virtualKeyboard.visible = false;
nameInputContainer.addChild(virtualKeyboard);
var keyboardChars = ['अ', 'आ', 'इ', 'ई', 'उ', 'ऊ', 'ए', 'ऐ', 'ओ', 'औ', 'क', 'ख', 'ग', 'घ', 'च', 'छ', 'ज', 'झ', 'ट', 'ठ', 'ड', 'ढ', 'त', 'थ', 'द', 'ध', 'न', 'प', 'फ', 'ब', 'भ', 'म', 'य', 'र', 'ल', 'व', 'श', 'ष', 'स', 'ह', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '⌫'];
var keyButtons = [];
for (var i = 0; i < keyboardChars.length; i++) {
var keyBtn = new Container();
var row = Math.floor(i / 10);
var col = i % 10;
keyBtn.x = (col - 4.5) * 80;
keyBtn.y = row * 60;
var keyBg = keyBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.15,
scaleY: 0.6
});
var keyText = new Text2(keyboardChars[i], {
size: 30,
fill: 0x000000
});
keyText.anchor.set(0.5, 0.5);
keyBtn.addChild(keyText);
keyBtn.charValue = keyboardChars[i];
keyButtons.push(keyBtn);
virtualKeyboard.addChild(keyBtn);
}
// Feedback text
var feedbackText = new Text2('', {
size: 60,
fill: 0x00D300
});
feedbackText.anchor.set(0.5, 0.5);
feedbackText.x = 2048 / 2;
feedbackText.y = 1700;
game.addChild(feedbackText);
// Utility function to shuffle array
function shuffleArray(array) {
var shuffled = array.slice(); // Create a copy
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;
}
// Game functions
function loadQuestion() {
if (usedQuestions.length >= logoDatabase.length) {
// Game completed
showGameComplete();
return;
}
// Get available questions (not used yet)
var availableQuestions = [];
for (var i = 0; i < logoDatabase.length; i++) {
if (usedQuestions.indexOf(i) === -1) {
availableQuestions.push(i);
}
}
// Select random question from available ones
var randomIndex = Math.floor(Math.random() * availableQuestions.length);
currentQuestion = availableQuestions[randomIndex];
usedQuestions.push(currentQuestion);
var question = logoDatabase[currentQuestion];
// Remove old logo display
if (logoDisplay) {
logoDisplay.destroy();
}
// Create new logo display with actual brand logo
logoDisplay = LK.getAsset(question.logoAssetId, {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 400
});
game.addChild(logoDisplay);
// Update question text
questionText.setText('यह कौन सा ब्रांड है?');
questionText.tint = 0x000000;
questionText.y = 700;
// Shuffle options while keeping track of correct answer
var originalOptions = question.options.slice(); // Create copy
var correctAnswer = originalOptions[question.correct];
var shuffledOptions = shuffleArray(originalOptions);
var newCorrectIndex = shuffledOptions.indexOf(correctAnswer);
// Update option buttons
for (var i = 0; i < 4; i++) {
optionButtons[i].setText(shuffledOptions[i]);
optionButtons[i].isCorrect = i === newCorrectIndex;
optionButtons[i].reset();
}
// Clear fact text
factText.setText('');
feedbackText.setText('');
// Update level if needed
if (question.level !== currentLevel) {
currentLevel = question.level;
levelText.setText('स्तर: ' + currentLevel);
}
gameState = 'playing';
}
function handleCorrectAnswer() {
gameState = 'answered';
// Play correct sound
LK.getSound('correctSound').play();
// Update score
score += 10;
LK.setScore(score);
scoreText.setText('स्कोर: ' + score);
// Award stars
stars += 1;
storage.stars = stars;
starDisplay.updateStars(stars);
// Show feedback
var praises = ['सही जवाब!', 'बहुत बढ़िया!', 'शाबाश!', 'उत्कृष्ट!'];
var randomPraise = praises[Math.floor(Math.random() * praises.length)];
feedbackText.setText(randomPraise);
feedbackText.tint = 0x4CAF50;
// Show fact
var question = logoDatabase[currentQuestion];
factText.setText(question.fact);
// Create confetti effect
createConfetti();
// Move to next question after delay
LK.setTimeout(function () {
loadQuestion();
}, 3000);
}
function updateLeaderboardWithScore(finalScore) {
if (!playerName || playerName === '') return;
// Create new entry
var newEntry = {
name: playerName,
score: finalScore,
stars: stars,
date: Date.now()
};
// Add to leaderboard
leaderboard.push(newEntry);
// Sort by score (highest first)
leaderboard.sort(function (a, b) {
return b.score - a.score;
});
// Keep only top 10 entries
if (leaderboard.length > 10) {
leaderboard = leaderboard.slice(0, 10);
}
// Update high score
if (leaderboard.length > 0) {
highScore = leaderboard[0].score;
storage.highScore = highScore;
}
// Save leaderboard
storage.leaderboard = leaderboard;
// Update display
updateLeaderboardDisplay();
}
function handleWrongAnswer() {
// Play wrong sound
LK.getSound('wrongSound').play();
// Show feedback
feedbackText.setText('फिर से कोशिश करें!');
feedbackText.tint = 0xf44336;
// Decrease life
lives -= 1;
livesText.setText('जीवन: ' + lives);
// Check for game over
if (lives <= 0) {
gameState = 'gameover';
// Update leaderboard before showing game over
updateLeaderboardWithScore(score);
LK.showGameOver();
return;
}
// Clear feedback after delay
LK.setTimeout(function () {
feedbackText.setText('');
}, 1500);
}
function createConfetti() {
// Simple confetti effect using colored rectangles
for (var i = 0; i < 10; i++) {
var confetti = LK.getAsset('starIcon', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2 + (Math.random() - 0.5) * 400,
y: 400,
scaleX: 0.3,
scaleY: 0.3
});
var colors = [0xFF6B6B, 0x4ECDC4, 0x45B7D1, 0xFFA07A, 0x98D8C8];
confetti.tint = colors[Math.floor(Math.random() * colors.length)];
game.addChild(confetti);
// Animate confetti
tween(confetti, {
y: 800 + Math.random() * 200,
x: confetti.x + (Math.random() - 0.5) * 300,
rotation: Math.random() * Math.PI * 2,
alpha: 0
}, {
duration: 1500,
easing: tween.easeOut,
onFinish: function onFinish() {
confetti.destroy();
}
});
}
}
function showGameComplete() {
gameState = 'complete';
// Update leaderboard with final score
updateLeaderboardWithScore(score);
// Show completion message
var completionText = new Text2('बधाई हो! आपने सभी लोगो पहचान लिए!', {
size: 56,
fill: 0x00C853
});
completionText.anchor.set(0.5, 0.5);
completionText.x = 2048 / 2;
completionText.y = 1200;
game.addChild(completionText);
// Show final score
var finalScoreText = new Text2('अंतिम स्कोर: ' + score, {
size: 48,
fill: 0xFF1744
});
finalScoreText.anchor.set(0.5, 0.5);
finalScoreText.x = 2048 / 2;
finalScoreText.y = 1300;
game.addChild(finalScoreText);
// Reset lives
lives = 3;
livesText.setText('जीवन: ' + lives);
// Show you win after delay
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
// Name input handlers
nameInputBg.down = function () {
virtualKeyboard.visible = true;
if (nameInputText.text === 'टैप करके नाम दर्ज करें') {
playerName = '';
nameInputText.setText('');
nameInputText.tint = 0x000000;
}
};
nameInputSaveBtn.down = function () {
if (playerName && playerName.length > 0) {
storage.playerName = playerName;
nameInputContainer.visible = false;
loadQuestion();
}
};
for (var i = 0; i < keyButtons.length; i++) {
(function (index) {
keyButtons[index].down = function () {
var _char = keyButtons[index].charValue;
if (_char === '⌫') {
if (playerName.length > 0) {
playerName = playerName.substring(0, playerName.length - 1);
nameInputText.setText(playerName || 'टैप करके नाम दर्ज करें');
nameInputText.tint = playerName ? 0x000000 : 0x666666;
}
} else if (playerName.length < 20) {
playerName += _char;
nameInputText.setText(playerName);
nameInputText.tint = 0x000000;
}
};
})(i);
}
// Check if player has entered name - ensure new players can enter name
if (!playerName || playerName === '') {
nameInputContainer.visible = true;
} else {
// Initialize first question
loadQuestion();
}
// Play background music
LK.playMusic('backgroundMusic');
// Game update loop
game.update = function () {
// Update any animations or game logic here
if (gameState === 'playing') {
// Game is active, handle any continuous updates
}
}; ===================================================================
--- original.js
+++ change.js
@@ -128,11 +128,10 @@
var currentQuestion = 0;
var score = 0;
var stars = storage.stars || 0;
var highScore = storage.highScore || 0;
-var leaderboardNames = storage.leaderboardNames || [];
-var leaderboardScores = storage.leaderboardScores || [];
-var leaderboardStars = storage.leaderboardStars || [];
+// New leaderboard entry structure
+var leaderboard = storage.leaderboard || [];
var usedQuestions = [];
var lives = 3; // Initialize player lives
var playerName = storage.playerName || ''; // Store player name - empty string for new players
// Logo database
@@ -399,13 +398,14 @@
feedbackText.visible = true;
};
function updateLeaderboardDisplay() {
for (var i = 0; i < 10; i++) {
- if (i < leaderboardNames.length) {
+ if (i < leaderboard.length) {
var rank = i + 1;
var medal = '';
if (rank === 1) medal = '🥇';else if (rank === 2) medal = '🥈';else if (rank === 3) medal = '🥉';else medal = rank + '.';
- leaderboardTexts[i].setText(medal + ' ' + leaderboardNames[i] + ' ' + leaderboardScores[i] + ' ' + leaderboardStars[i] + '⭐');
+ var entry = leaderboard[i];
+ leaderboardTexts[i].setText(medal + ' ' + entry.name + ' ' + entry.score + ' ' + entry.stars + '⭐');
} else {
leaderboardTexts[i].setText('');
}
}
@@ -664,64 +664,32 @@
}, 3000);
}
function updateLeaderboardWithScore(finalScore) {
if (!playerName || playerName === '') return;
- // Check if player already exists in leaderboard
- var playerIndex = -1;
- for (var i = 0; i < leaderboardNames.length; i++) {
- if (leaderboardNames[i] === playerName) {
- playerIndex = i;
- break;
- }
- }
- // Update existing entry or add new one
- if (playerIndex !== -1) {
- // Update only if new score is higher
- if (finalScore > leaderboardScores[playerIndex]) {
- leaderboardScores[playerIndex] = finalScore;
- leaderboardStars[playerIndex] = stars;
- }
- } else {
- // Add new entry
- leaderboardNames.push(playerName);
- leaderboardScores.push(finalScore);
- leaderboardStars.push(stars);
- }
- // Sort by score (highest first) - create indices array for sorting
- var indices = [];
- for (var i = 0; i < leaderboardScores.length; i++) {
- indices.push(i);
- }
- indices.sort(function (a, b) {
- return leaderboardScores[b] - leaderboardScores[a];
+ // Create new entry
+ var newEntry = {
+ name: playerName,
+ score: finalScore,
+ stars: stars,
+ date: Date.now()
+ };
+ // Add to leaderboard
+ leaderboard.push(newEntry);
+ // Sort by score (highest first)
+ leaderboard.sort(function (a, b) {
+ return b.score - a.score;
});
- // Reorder arrays based on sorted indices
- var sortedNames = [];
- var sortedScores = [];
- var sortedStars = [];
- for (var i = 0; i < indices.length; i++) {
- sortedNames.push(leaderboardNames[indices[i]]);
- sortedScores.push(leaderboardScores[indices[i]]);
- sortedStars.push(leaderboardStars[indices[i]]);
- }
- leaderboardNames = sortedNames;
- leaderboardScores = sortedScores;
- leaderboardStars = sortedStars;
// Keep only top 10 entries
- if (leaderboardNames.length > 10) {
- leaderboardNames = leaderboardNames.slice(0, 10);
- leaderboardScores = leaderboardScores.slice(0, 10);
- leaderboardStars = leaderboardStars.slice(0, 10);
+ if (leaderboard.length > 10) {
+ leaderboard = leaderboard.slice(0, 10);
}
- // Update high score for compatibility
- if (leaderboardScores.length > 0) {
- highScore = leaderboardScores[0];
+ // Update high score
+ if (leaderboard.length > 0) {
+ highScore = leaderboard[0].score;
storage.highScore = highScore;
}
- // Save leaderboard arrays
- storage.leaderboardNames = leaderboardNames;
- storage.leaderboardScores = leaderboardScores;
- storage.leaderboardStars = leaderboardStars;
+ // Save leaderboard
+ storage.leaderboard = leaderboard;
// Update display
updateLeaderboardDisplay();
}
function handleWrongAnswer() {