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
****/
// Brand Logo Assets
// Game state variables
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 - load from flat arrays
var leaderboard = [];
if (storage.leaderboardNames && storage.leaderboardNames.length > 0 && storage.leaderboardScores && storage.leaderboardStars && storage.leaderboardDates) {
var thirtyDaysAgo = Date.now() - 30 * 24 * 60 * 60 * 1000;
for (var i = 0; i < storage.leaderboardNames.length; i++) {
// Only add entries that are less than 30 days old
if (storage.leaderboardDates[i] && storage.leaderboardDates[i] > thirtyDaysAgo) {
leaderboard.push({
name: storage.leaderboardNames[i],
score: storage.leaderboardScores[i],
stars: storage.leaderboardStars[i],
date: storage.leaderboardDates[i]
});
}
}
// Sort by score and keep only top 10
leaderboard.sort(function (a, b) {
return b.score - a.score;
});
if (leaderboard.length > 10) {
leaderboard = leaderboard.slice(0, 10);
}
// Update storage with cleaned data
storage.leaderboardNames = [];
storage.leaderboardScores = [];
storage.leaderboardStars = [];
storage.leaderboardDates = [];
for (var i = 0; i < leaderboard.length; i++) {
storage.leaderboardNames[i] = leaderboard[i].name;
storage.leaderboardScores[i] = leaderboard[i].score;
storage.leaderboardStars[i] = leaderboard[i].stars;
storage.leaderboardDates[i] = leaderboard[i].date;
}
}
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);
// Reload overlay
var reloadOverlay = new Container();
reloadOverlay.visible = false;
game.addChild(reloadOverlay);
// Semi-transparent background for reload overlay
var reloadBg = LK.getAsset('optionButton', {
anchorX: 0,
anchorY: 0,
scaleX: 20.48,
scaleY: 27.32,
x: 0,
y: 0
});
reloadBg.alpha = 0.95;
reloadBg.tint = 0x1a1a1a;
reloadOverlay.addChild(reloadBg);
// Reload container
var reloadContainer = new Container();
reloadContainer.x = 2048 / 2;
reloadContainer.y = 1366 / 2;
reloadOverlay.addChild(reloadContainer);
var reloadTitle = new Text2('डेटा रीलोड करें', {
size: 72,
fill: 0xFFD700
});
reloadTitle.anchor.set(0.5, 0.5);
reloadTitle.y = -300;
reloadContainer.addChild(reloadTitle);
// Password input
var passwordInputBg = LK.getAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 1
});
passwordInputBg.y = -150;
reloadContainer.addChild(passwordInputBg);
var passwordInputText = new Text2('पासवर्ड दर्ज करें', {
size: 42,
fill: 0x666666
});
passwordInputText.anchor.set(0.5, 0.5);
passwordInputText.y = -150;
reloadContainer.addChild(passwordInputText);
// Name input for reload
var nameInputReloadBg = LK.getAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 1
});
nameInputReloadBg.y = -50;
reloadContainer.addChild(nameInputReloadBg);
var nameInputReloadText = new Text2('नाम दर्ज करें', {
size: 42,
fill: 0x666666
});
nameInputReloadText.anchor.set(0.5, 0.5);
nameInputReloadText.y = -50;
reloadContainer.addChild(nameInputReloadText);
// Reload confirm button
var reloadConfirmBtn = new Container();
reloadConfirmBtn.y = 50;
var reloadConfirmBg = reloadConfirmBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1
});
reloadConfirmBg.tint = 0x4CAF50;
var reloadConfirmText = new Text2('रीलोड करें', {
size: 42,
fill: 0xFFFFFF
});
reloadConfirmText.anchor.set(0.5, 0.5);
reloadConfirmBtn.addChild(reloadConfirmText);
reloadContainer.addChild(reloadConfirmBtn);
// Reload cancel button
var reloadCancelBtn = new Container();
reloadCancelBtn.y = 150;
var reloadCancelBg = reloadCancelBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1
});
reloadCancelBg.tint = 0xf44336;
var reloadCancelText = new Text2('रद्द करें', {
size: 42,
fill: 0xFFFFFF
});
reloadCancelText.anchor.set(0.5, 0.5);
reloadCancelBtn.addChild(reloadCancelText);
reloadContainer.addChild(reloadCancelBtn);
// Reload state variables
var reloadPassword = '';
var reloadName = '';
var isPasswordInput = false;
var isNameInput = false;
var reloadKeyboardVisible = false;
// 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);
// Add reset button
var resetBtn = new Container();
resetBtn.x = 300;
resetBtn.y = 180;
var resetBtnBg = resetBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.1,
scaleY: 1
});
resetBtnBg.tint = 0xFF5722;
var resetBtnText = new Text2('रीसेट करें', {
size: 36,
fill: 0xFFFFFF
});
resetBtnText.anchor.set(0.5, 0.5);
resetBtn.addChild(resetBtnText);
game.addChild(resetBtn);
// Add reload button
var reloadBtn = new Container();
reloadBtn.x = 300;
reloadBtn.y = 280;
var reloadBtnBg = reloadBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.1,
scaleY: 1
});
reloadBtnBg.tint = 0x2196F3;
var reloadBtnText = new Text2('रीलोड करें', {
size: 36,
fill: 0xFFFFFF
});
reloadBtnText.anchor.set(0.5, 0.5);
reloadBtn.addChild(reloadBtnText);
game.addChild(reloadBtn);
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;
};
// Reset game function
function resetGame() {
// Reset game state variables
gameState = 'playing';
currentLevel = 1;
currentQuestion = 0;
score = 0;
stars = 0;
lives = 3;
usedQuestions = [];
playerName = '';
playerPassword = '';
isSettingPassword = false;
// Reset storage (except leaderboard data)
storage.stars = 0;
storage.playerName = '';
storage.playerPassword = '';
// Do not reset leaderboard data - keep it preserved
// storage.highScore = 0;
// storage.leaderboardNames = [];
// storage.leaderboardScores = [];
// storage.leaderboardStars = [];
// storage.leaderboardDates = [];
// Do not reset leaderboard array
// leaderboard = [];
// Update UI displays
scoreText.setText('स्कोर: ' + score);
levelText.setText('स्तर: ' + currentLevel);
starDisplay.updateStars(stars);
livesText.setText('जीवन: ' + lives);
factText.setText('');
feedbackText.setText('');
// Update leaderboard display
updateLeaderboardDisplay();
// Hide any overlays
leaderboardOverlay.visible = false;
nameInputContainer.visible = true;
// Reset name input
nameInputText.setText('टैप करके नाम दर्ज करें');
nameInputText.tint = 0x666666;
virtualKeyboard.visible = false;
// Remove logo display if exists
if (logoDisplay) {
logoDisplay.destroy();
logoDisplay = null;
}
// Reset option buttons
for (var i = 0; i < optionButtons.length; i++) {
optionButtons[i].reset();
}
// Set score to 0 in LK system
LK.setScore(0);
}
// Reset button click handler
resetBtn.down = function () {
resetGame();
};
// Reload button click handler
reloadBtn.down = function () {
reloadOverlay.visible = true;
reloadPassword = '';
reloadName = '';
isPasswordInput = false;
isNameInput = false;
passwordInputText.setText('पासवर्ड दर्ज करें');
passwordInputText.tint = 0x666666;
nameInputReloadText.setText('नाम दर्ज करें');
nameInputReloadText.tint = 0x666666;
// 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;
nameInputContainer.visible = false;
};
// Create reload keyboard container (buttons will be created after keyboardChars is defined)
var reloadKeyboard = new Container();
reloadKeyboard.y = 250;
reloadKeyboard.visible = false;
reloadContainer.addChild(reloadKeyboard);
var reloadKeyButtons = [];
// Create number keyboard for reload overlay
var reloadNumberKeyboard = new Container();
reloadNumberKeyboard.y = 250;
reloadNumberKeyboard.visible = false;
reloadContainer.addChild(reloadNumberKeyboard);
// Placeholder for reload number keyboard buttons - will be created after numberChars is defined
var reloadNumberKeyButtons = [];
// Password input handler
passwordInputBg.down = function () {
isPasswordInput = true;
isNameInput = false;
reloadNumberKeyboard.visible = true;
reloadKeyboard.visible = false;
reloadKeyboardVisible = false;
if (passwordInputText.text === 'पासवर्ड दर्ज करें') {
reloadPassword = '';
passwordInputText.setText('');
passwordInputText.tint = 0x000000;
}
};
// Name input handler for reload
nameInputReloadBg.down = function () {
isNameInput = true;
isPasswordInput = false;
reloadNumberKeyboard.visible = false;
reloadKeyboard.visible = true;
reloadKeyboardVisible = true;
if (nameInputReloadText.text === 'नाम दर्ज करें') {
reloadName = '';
nameInputReloadText.setText('');
nameInputReloadText.tint = 0x000000;
}
};
// Reload confirm handler
reloadConfirmBtn.down = function () {
if (reloadName && reloadName.length > 0 && reloadPassword && reloadPassword.length > 0) {
// First check if player exists in game storage
var playerExistsInStorage = storage.playerName === reloadName;
// Find player in leaderboard
var foundPlayer = null;
for (var i = 0; i < leaderboard.length; i++) {
if (leaderboard[i].name === reloadName) {
foundPlayer = leaderboard[i];
break;
}
}
// Check if player exists in game (either in storage or leaderboard)
if (!playerExistsInStorage && !foundPlayer) {
// Player does not exist in the game
feedbackText.setText('यह खिलाड़ी गेम में नहीं है!');
feedbackText.tint = 0xFF0000;
feedbackText.visible = true;
LK.setTimeout(function () {
feedbackText.setText('');
}, 3000);
return;
}
// Check password if player exists in storage
if (playerExistsInStorage) {
var passwordMatches = storage.playerPassword === reloadPassword;
if (passwordMatches && foundPlayer) {
// Restore player data from leaderboard
playerName = foundPlayer.name;
score = foundPlayer.score;
stars = foundPlayer.stars;
playerPassword = storage.playerPassword;
storage.playerName = playerName;
storage.stars = stars;
// Update UI
scoreText.setText('स्कोर: ' + score);
starDisplay.updateStars(stars);
LK.setScore(score);
// Reset game state
gameState = 'playing';
currentLevel = 1;
currentQuestion = 0;
lives = 3;
usedQuestions = [];
livesText.setText('जीवन: ' + lives);
levelText.setText('स्तर: ' + currentLevel);
// Show success message
feedbackText.setText('डेटा सफलतापूर्वक रीलोड किया गया!');
feedbackText.tint = 0x4CAF50;
feedbackText.visible = true;
// Hide reload overlay
reloadOverlay.visible = false;
reloadKeyboard.visible = false;
reloadNumberKeyboard.visible = false;
reloadKeyboardVisible = false;
nameInputContainer.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;
loadQuestion();
// Clear success message after 3 seconds
LK.setTimeout(function () {
feedbackText.setText('');
}, 3000);
} else {
// Wrong password
feedbackText.setText('गलत पासवर्ड!');
feedbackText.tint = 0xFF0000;
feedbackText.visible = true;
LK.setTimeout(function () {
feedbackText.setText('');
}, 3000);
}
} else {
// Player exists in leaderboard but not in storage (shouldn't happen)
feedbackText.setText('कृपया पहले लॉगिन करें!');
feedbackText.tint = 0xFF0000;
feedbackText.visible = true;
LK.setTimeout(function () {
feedbackText.setText('');
}, 3000);
}
} else {
// Empty name or password
feedbackText.setText('कृपया नाम और पासवर्ड दोनों दर्ज करें!');
feedbackText.tint = 0xFF0000;
feedbackText.visible = true;
LK.setTimeout(function () {
feedbackText.setText('');
}, 3000);
}
};
// Reload cancel handler
reloadCancelBtn.down = function () {
reloadOverlay.visible = false;
reloadNumberKeyboard.visible = false;
reloadKeyboard.visible = false;
reloadKeyboardVisible = 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;
if (!playerName || playerName === '') {
nameInputContainer.visible = true;
}
};
// 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);
nameInputText.y = -20;
nameInputContainer.addChild(nameInputText);
// Add password input field for new players
var passwordInputFieldBg = LK.getAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2.5,
scaleY: 0.8,
y: 40
});
passwordInputFieldBg.tint = 0xE0E0E0;
nameInputContainer.addChild(passwordInputFieldBg);
var passwordInputFieldText = new Text2('पासवर्ड सेट करें', {
size: 36,
fill: 0x666666
});
passwordInputFieldText.anchor.set(0.5, 0.5);
passwordInputFieldText.y = 40;
nameInputContainer.addChild(passwordInputFieldText);
// Add password variable for new player registration
var playerPassword = '';
var isSettingPassword = false;
var nameInputSaveBtn = new Container();
nameInputSaveBtn.y = 120;
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 = 200;
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', ' ', '⌫'];
// Create reload keyboard buttons now that keyboardChars is defined
for (var i = 0; i < keyboardChars.length; i++) {
var reloadKeyBtn = new Container();
var row = Math.floor(i / 10);
var col = i % 10;
reloadKeyBtn.x = (col - 4.5) * 80;
reloadKeyBtn.y = row * 60;
var reloadKeyBg = reloadKeyBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.15,
scaleY: 0.6
});
var reloadKeyText = new Text2(keyboardChars[i], {
size: 30,
fill: 0x000000
});
reloadKeyText.anchor.set(0.5, 0.5);
reloadKeyBtn.addChild(reloadKeyText);
reloadKeyBtn.charValue = keyboardChars[i];
reloadKeyButtons.push(reloadKeyBtn);
reloadKeyboard.addChild(reloadKeyBtn);
}
// Number keyboard for password input
var numberKeyboard = new Container();
numberKeyboard.y = 200;
numberKeyboard.visible = false;
nameInputContainer.addChild(numberKeyboard);
var numberChars = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '⌫'];
var numberKeyButtons = [];
// Now create reload number keyboard buttons after numberChars is defined
for (var i = 0; i < numberChars.length; i++) {
var reloadNumKeyBtn = new Container();
var row = Math.floor(i / 4);
var col = i % 4;
reloadNumKeyBtn.x = (col - 1.5) * 100;
reloadNumKeyBtn.y = row * 70;
var reloadNumKeyBg = reloadNumKeyBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.7
});
var reloadNumKeyText = new Text2(numberChars[i], {
size: 36,
fill: 0x000000
});
reloadNumKeyText.anchor.set(0.5, 0.5);
reloadNumKeyBtn.addChild(reloadNumKeyText);
reloadNumKeyBtn.charValue = numberChars[i];
reloadNumberKeyButtons.push(reloadNumKeyBtn);
reloadNumberKeyboard.addChild(reloadNumKeyBtn);
}
// Add handlers for reload keyboard buttons
for (var i = 0; i < reloadKeyButtons.length; i++) {
(function (index) {
reloadKeyButtons[index].down = function () {
var _char = reloadKeyButtons[index].charValue;
if (isNameInput) {
if (_char === '⌫') {
if (reloadName.length > 0) {
reloadName = reloadName.substring(0, reloadName.length - 1);
nameInputReloadText.setText(reloadName || 'नाम दर्ज करें');
nameInputReloadText.tint = reloadName ? 0x000000 : 0x666666;
}
} else if (reloadName.length < 20) {
reloadName += _char;
nameInputReloadText.setText(reloadName);
nameInputReloadText.tint = 0x000000;
}
}
};
})(i);
}
// Add handlers for reload number keyboard
for (var i = 0; i < reloadNumberKeyButtons.length; i++) {
(function (index) {
reloadNumberKeyButtons[index].down = function () {
var _char = reloadNumberKeyButtons[index].charValue;
if (isPasswordInput) {
if (_char === '⌫') {
if (reloadPassword.length > 0) {
reloadPassword = reloadPassword.substring(0, reloadPassword.length - 1);
passwordInputText.setText(reloadPassword || 'पासवर्ड दर्ज करें');
passwordInputText.tint = reloadPassword ? 0x000000 : 0x666666;
}
} else if (reloadPassword.length < 20) {
reloadPassword += _char;
passwordInputText.setText(reloadPassword);
passwordInputText.tint = 0x000000;
}
}
};
})(i);
}
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);
}
// Create number keyboard buttons
for (var i = 0; i < numberChars.length; i++) {
var numKeyBtn = new Container();
var row = Math.floor(i / 4);
var col = i % 4;
numKeyBtn.x = (col - 1.5) * 100;
numKeyBtn.y = row * 70;
var numKeyBg = numKeyBtn.attachAsset('optionButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.7
});
var numKeyText = new Text2(numberChars[i], {
size: 36,
fill: 0x000000
});
numKeyText.anchor.set(0.5, 0.5);
numKeyBtn.addChild(numKeyText);
numKeyBtn.charValue = numberChars[i];
numberKeyButtons.push(numKeyBtn);
numberKeyboard.addChild(numKeyBtn);
}
// 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;
// Remove entries older than 30 days
var thirtyDaysAgo = Date.now() - 30 * 24 * 60 * 60 * 1000;
var filteredLeaderboard = [];
for (var i = 0; i < leaderboard.length; i++) {
if (leaderboard[i].date && leaderboard[i].date > thirtyDaysAgo) {
filteredLeaderboard.push(leaderboard[i]);
}
}
leaderboard = filteredLeaderboard;
// Always add new entry without checking for existing players
var newEntry = {
name: playerName,
score: finalScore,
stars: stars,
date: Date.now()
};
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 using separate arrays for each property
storage.leaderboardNames = [];
storage.leaderboardScores = [];
storage.leaderboardStars = [];
storage.leaderboardDates = [];
for (var i = 0; i < leaderboard.length; i++) {
storage.leaderboardNames[i] = leaderboard[i].name;
storage.leaderboardScores[i] = leaderboard[i].score;
storage.leaderboardStars[i] = leaderboard[i].stars;
storage.leaderboardDates[i] = leaderboard[i].date;
}
// 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;
numberKeyboard.visible = false;
isSettingPassword = false;
if (nameInputText.text === 'टैप करके नाम दर्ज करें') {
playerName = '';
nameInputText.setText('');
nameInputText.tint = 0x000000;
}
};
// Password field click handler
passwordInputFieldBg.down = function () {
virtualKeyboard.visible = false;
numberKeyboard.visible = true;
isSettingPassword = true;
if (passwordInputFieldText.text === 'पासवर्ड सेट करें') {
playerPassword = '';
passwordInputFieldText.setText('');
passwordInputFieldText.tint = 0x000000;
}
};
nameInputSaveBtn.down = function () {
if (playerName && playerName.length > 0 && playerPassword && playerPassword.length > 0) {
// Check if name already exists in leaderboard
var nameExists = false;
for (var i = 0; i < leaderboard.length; i++) {
if (leaderboard[i].name === playerName) {
nameExists = true;
break;
}
}
if (nameExists) {
// Show error message for duplicate name
feedbackText.setText('यह नाम पहले से मौजूद है! कृपया दूसरा नाम चुनें।');
feedbackText.tint = 0xFF0000;
feedbackText.visible = true;
// Clear error message after 3 seconds
LK.setTimeout(function () {
feedbackText.setText('');
}, 3000);
return;
}
storage.playerName = playerName;
storage.playerPassword = playerPassword; // Save password
nameInputContainer.visible = false;
virtualKeyboard.visible = false;
numberKeyboard.visible = false;
loadQuestion();
} else {
// Show error if name or password is empty
feedbackText.setText('कृपया नाम और पासवर्ड दोनों दर्ज करें!');
feedbackText.tint = 0xFF0000;
feedbackText.visible = true;
LK.setTimeout(function () {
feedbackText.setText('');
}, 3000);
}
};
for (var i = 0; i < keyButtons.length; i++) {
(function (index) {
keyButtons[index].down = function () {
var _char = keyButtons[index].charValue;
// Handle reload overlay inputs
if (reloadOverlay.visible) {
if (isPasswordInput) {
if (_char === '⌫') {
if (reloadPassword.length > 0) {
reloadPassword = reloadPassword.substring(0, reloadPassword.length - 1);
passwordInputText.setText(reloadPassword || 'पासवर्ड दर्ज करें');
passwordInputText.tint = reloadPassword ? 0x000000 : 0x666666;
}
} else if (reloadPassword.length < 20) {
reloadPassword += _char;
passwordInputText.setText(reloadPassword);
passwordInputText.tint = 0x000000;
}
} else if (isNameInput) {
if (_char === '⌫') {
if (reloadName.length > 0) {
reloadName = reloadName.substring(0, reloadName.length - 1);
nameInputReloadText.setText(reloadName || 'नाम दर्ज करें');
nameInputReloadText.tint = reloadName ? 0x000000 : 0x666666;
}
} else if (reloadName.length < 20) {
reloadName += _char;
nameInputReloadText.setText(reloadName);
nameInputReloadText.tint = 0x000000;
}
}
} else {
// Handle regular name input
if (nameInputContainer.visible) {
if (isSettingPassword) {
if (_char === '⌫') {
if (playerPassword.length > 0) {
playerPassword = playerPassword.substring(0, playerPassword.length - 1);
passwordInputFieldText.setText(playerPassword || 'पासवर्ड सेट करें');
passwordInputFieldText.tint = playerPassword ? 0x000000 : 0x666666;
}
} else if (playerPassword.length < 20) {
playerPassword += _char;
passwordInputFieldText.setText(playerPassword);
passwordInputFieldText.tint = 0x000000;
}
} else {
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);
}
// Number keyboard button handlers
for (var i = 0; i < numberKeyButtons.length; i++) {
(function (index) {
numberKeyButtons[index].down = function () {
var _char = numberKeyButtons[index].charValue;
if (isSettingPassword) {
if (_char === '⌫') {
if (playerPassword.length > 0) {
playerPassword = playerPassword.substring(0, playerPassword.length - 1);
passwordInputFieldText.setText(playerPassword || 'पासवर्ड सेट करें');
passwordInputFieldText.tint = playerPassword ? 0x000000 : 0x666666;
}
} else if (playerPassword.length < 20) {
playerPassword += _char;
passwordInputFieldText.setText(playerPassword);
passwordInputFieldText.tint = 0x000000;
}
}
};
})(i);
}
// Check if player has entered name - ensure new players can enter name
if (!playerName || playerName === '') {
nameInputContainer.visible = true;
} else {
// Hide name input container once name is entered
nameInputContainer.visible = false;
// 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
@@ -131,16 +131,38 @@
var highScore = storage.highScore || 0;
// New leaderboard entry structure - load from flat arrays
var leaderboard = [];
if (storage.leaderboardNames && storage.leaderboardNames.length > 0 && storage.leaderboardScores && storage.leaderboardStars && storage.leaderboardDates) {
+ var thirtyDaysAgo = Date.now() - 30 * 24 * 60 * 60 * 1000;
for (var i = 0; i < storage.leaderboardNames.length; i++) {
- leaderboard.push({
- name: storage.leaderboardNames[i],
- score: storage.leaderboardScores[i],
- stars: storage.leaderboardStars[i],
- date: storage.leaderboardDates[i]
- });
+ // Only add entries that are less than 30 days old
+ if (storage.leaderboardDates[i] && storage.leaderboardDates[i] > thirtyDaysAgo) {
+ leaderboard.push({
+ name: storage.leaderboardNames[i],
+ score: storage.leaderboardScores[i],
+ stars: storage.leaderboardStars[i],
+ date: storage.leaderboardDates[i]
+ });
+ }
}
+ // Sort by score and keep only top 10
+ leaderboard.sort(function (a, b) {
+ return b.score - a.score;
+ });
+ if (leaderboard.length > 10) {
+ leaderboard = leaderboard.slice(0, 10);
+ }
+ // Update storage with cleaned data
+ storage.leaderboardNames = [];
+ storage.leaderboardScores = [];
+ storage.leaderboardStars = [];
+ storage.leaderboardDates = [];
+ for (var i = 0; i < leaderboard.length; i++) {
+ storage.leaderboardNames[i] = leaderboard[i].name;
+ storage.leaderboardScores[i] = leaderboard[i].score;
+ storage.leaderboardStars[i] = leaderboard[i].stars;
+ storage.leaderboardDates[i] = leaderboard[i].date;
+ }
}
var usedQuestions = [];
var lives = 3; // Initialize player lives
var playerName = storage.playerName || ''; // Store player name - empty string for new players
@@ -1182,8 +1204,17 @@
}, 3000);
}
function updateLeaderboardWithScore(finalScore) {
if (!playerName || playerName === '') return;
+ // Remove entries older than 30 days
+ var thirtyDaysAgo = Date.now() - 30 * 24 * 60 * 60 * 1000;
+ var filteredLeaderboard = [];
+ for (var i = 0; i < leaderboard.length; i++) {
+ if (leaderboard[i].date && leaderboard[i].date > thirtyDaysAgo) {
+ filteredLeaderboard.push(leaderboard[i]);
+ }
+ }
+ leaderboard = filteredLeaderboard;
// Always add new entry without checking for existing players
var newEntry = {
name: playerName,
score: finalScore,