Code edit (1 edits merged)
Please save this source code
User prompt
submitAnswer içindeki if (usedSecondChance) ... else ... blokları Aşağıdaki kod parçasına dikkat et: js Kopyala Düzenle if (correct) { // ... doğru cevabın işlemleri ... } else { // yanlış cevaptaki işlemler if (usedSecondChance) { LK.setTimeout(function () { endGame(false); }, 2000); } else { LK.setTimeout(function () { endGame(false); }, 2000); } } usedSecondChance değeri ne olursa olsun her iki kol da endGame(false) çağırıyor. Yani ilk yanlışta, jokeri kullanmış olsanız da kullanmasanız da sonuçta endGame planlanıyor ve oyun bitiyor. useSecondChance’ın tetiklenme şartı js Kopyala Düzenle function useSecondChance() { // Yalnızca answerLocked === true ve daha önce kullanılmadıysa izin veriliyor if (usedSecondChance || !answerLocked) { return; } usedSecondChance = true; // butonları ve karakteri resetliyor... answerLocked = false; character.showNeutral(); } Burada “ikinci şans” jokerini ancak answerLocked === true yani yanlış bir cevabı seçtikten sonra kullanabiliyorsunuz. Fakat yanlış cevabı seçtiğiniz anda submitAnswer içinde zaten hemen (2 saniye içinde) endGame planlanıyor; bu yüzden jokerin bir etkisi olmuyor. Çözüm önerisi submitAnswer’ı doğru akışa göre değiştirin js Kopyala Düzenle function submitAnswer(index) { if (answerLocked) return; answerLocked = true; var correct = index === currentCorrectIndex; if (correct) { // ... olduğu gibi } else { // yanlış cevabın animasyonları vs. if (!usedSecondChance) { // eğer henüz joker kullanılmadıysa direkt oyunu bitirme, // kullanıcıya ikinci şans hakkı tanı useSecondChance(); } else { // ikinci şans zaten kullanıldı, o zaman bitir LK.setTimeout(function () { endGame(false); }, 2000); } } } useSecondChance’ın şartlarını yumuşatın Jokeri cevabı seçmeden önce de aktif edebilmek isterseniz !answerLocked kontrolünü kaldırabilirsiniz. Örneğin: js Kopyala Düzenle function useSecondChance() { if (usedSecondChance) return; usedSecondChance = true; // butonları ve karakteri resetle answerLocked = false; character.showNeutral(); } Bu iki değişiklikle: İlk yanlış cevaptan sonra (eğer joker kullanılmamışsa) oyun bitmeyecek, kullanıcıya ikinci şans hakkı tanınacak. İkinci yanlış cevaptan sonra (veya joker zaten kullanıldıysa) oyunun bittiği endGame(false) çağrısı devreye girecek.
User prompt
second chance jokeri sadece kullanıldığı soru da aktif olur bir daha asla aktif olmaz second chance jokerini kullandıktan sonra ilk yanlış cevabı oyuncuyu game overa götürmez ve second chance jokeri asla otomatikk aktifleşmez ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
second chance jokerini kullandıktan sonra ilk yanlış cevabı oyuncuyu game overa götürmez
User prompt
second chance jokeri asla otomatik şekilde aktifleşmesin sadece oyuncu kullanırsa aktif olsun ve second chance jokeri sadece kullanıldığı soruda işe yarar kullandıktan sonra diğer sorulara bir etkisi olmaz
User prompt
second chance jokerinin mekaniğini değiştirelim,artık second chance jokeri aktifleştiğinde o soru içinde ikinci bir kalbi olur oyuncunun,eğer ikinci kalp varken yanlış şıkkı seçerse game over olmaz,eğer ikinci kalbi kaybettikten sonra doğru şıkkı seçerse second chance bir daha kullanılamaz olur , eğer ikinci kalbi kaybettikten sonra ilk kalbi de kaybederse game over olur
User prompt
if second chance activated player gains a second heart in that question
User prompt
eğer second chance jokeri aktifse ve yanlış bir şık seçilirse bir şansı daha olur doğru bilirse devam eder yanlış şıkka tıklarsa kaybeder
User prompt
second chance jokeri sadece tıklandığında aktif olsun onun dışında eğer oyuncu yanlış seçeneği seçerse kaybetsin elinde bir second chance jokeri olsada aktifleşmesi lazım çalışması için
User prompt
score texti sil
User prompt
move the set 10 pixel right
User prompt
move the set 30 pixel left
User prompt
move the set 100 pixel down
User prompt
move the set 100 pixel down
User prompt
move the set 400 pixel down
User prompt
move the set 200 pixel up
User prompt
move the set 400 pixel up
User prompt
place theset middle of the screen
User prompt
Move the question text 30 pixels up
User prompt
move the question text 50 pixel down ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Move the question text 400 pixels down
User prompt
soru textini sadece text kısmını 500 pixel aşağı götür
User prompt
soru textini 700 pixel aşağı götür
User prompt
a b c ve d şıklarını daha yuvarlağımsı yap doğru ve yanlış için görünen şeylerini
User prompt
a b c ve d şıklarının dokunulabilen kısımlarındaki köşeleri yok edebilir misin daha yuvarlak bir görünüm için
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0,
totalPlayed: 0
});
/****
* Classes
****/
var Character = Container.expand(function () {
var self = Container.call(this);
var happyFace = self.attachAsset('characterHappy', {
anchorX: 0.5,
anchorY: 0.5
});
happyFace.visible = false;
var sadFace = self.attachAsset('characterSad', {
anchorX: 0.5,
anchorY: 0.5
});
sadFace.visible = false;
var excitedFace = self.attachAsset('characterExcited', {
anchorX: 0.5,
anchorY: 0.5
});
excitedFace.visible = false;
var neutralFace = self.attachAsset('characterNeutral', {
anchorX: 0.5,
anchorY: 0.5
});
neutralFace.visible = true;
self.showHappy = function () {
happyFace.visible = true;
sadFace.visible = false;
excitedFace.visible = false;
neutralFace.visible = false;
};
self.showSad = function () {
happyFace.visible = false;
sadFace.visible = true;
excitedFace.visible = false;
neutralFace.visible = false;
};
self.showExcited = function () {
happyFace.visible = false;
sadFace.visible = false;
excitedFace.visible = true;
neutralFace.visible = false;
};
self.showNeutral = function () {
happyFace.visible = false;
sadFace.visible = false;
excitedFace.visible = false;
neutralFace.visible = true;
};
return self;
});
var Joker = Container.expand(function (type, icon) {
var self = Container.call(this);
self.type = type;
self.used = false;
var background = self.attachAsset('jokerButton', {
anchorX: 0.5,
anchorY: 0.5
});
var text = new Text2(icon, {
size: 50,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 3
});
text.anchor.set(0.5, 0.5);
self.addChild(text);
self.use = function () {
if (self.used) {
return false;
}
self.used = true;
tween(self, {
alpha: 0.4
}, {
duration: 300
});
return true;
};
self.reset = function () {
self.used = false;
self.alpha = 1;
};
self.down = function (x, y, obj) {
if (!self.used && !gameOver && !answerLocked) {
activateJoker(self.type);
}
};
return self;
});
var PhoneFriendPopup = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('questionCard', {
anchorX: 0.5,
anchorY: 0.5,
width: 1200,
height: 800
});
background.tint = 0xF5F5F5;
var titleText = new Text2("Phone a Friend", {
size: 80,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 4
});
titleText.anchor.set(0.5, 0);
titleText.position.set(0, -320);
self.addChild(titleText);
var friends = [];
var friendNames = ["Professor", "Scientist", "Artist", "Engineer"];
for (var i = 0; i < 4; i++) {
var friendButton = new Container();
var buttonBg = LK.getAsset('buttonBackground', {
anchorX: 0.5,
anchorY: 0.5,
width: 500,
height: 100
});
friendButton.addChild(buttonBg);
var nameText = new Text2(friendNames[i], {
size: 50,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 3
});
nameText.anchor.set(0.5, 0.5);
friendButton.addChild(nameText);
friendButton.position.set(0, -150 + i * 150);
friendButton.index = i;
friendButton.interactive = true;
friendButton.down = function (x, y, obj) {
self.selectFriend(obj.parent.index);
};
self.addChild(friendButton);
friends.push(friendButton);
}
self.visible = false;
self.show = function () {
self.visible = true;
};
self.hide = function () {
self.visible = false;
};
self.selectFriend = function (index) {
self.hide();
phoneFriendCallback(index);
};
return self;
});
var QuestionButton = Container.expand(function (index, text) {
var self = Container.call(this);
self.index = index;
self.isCorrect = false;
self.isSelected = false;
self.isEliminated = false;
// Apply additional 7% height increase while keeping width the same
var background = self.attachAsset('buttonBackground', {
anchorX: 0.5,
anchorY: 0.5,
width: 944,
// 924 + 20 = 944 (adding 10px on each side)
// Extended by 10 pixels on left and right
height: 234,
// 224 + 10 = 234 (adding 5px on top and 5px on bottom)
shape: 'ellipse' // More rounded shape
});
var buttonText = new Text2(text, {
size: 60,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 4
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
var overlay = self.attachAsset('correctAnswerOverlay', {
anchorX: 0.5,
anchorY: 0.5,
width: 944,
// 924 + 20 = 944 (adding 10px on each side)
// Extended by 10 pixels on left and right
height: 234,
// 224 + 10 = 234 (adding 5px on top and 5px on bottom)
shape: 'ellipse' // More rounded shape for overlay
});
overlay.alpha = 0;
self.setText = function (newText) {
buttonText.setText(newText);
};
self.setCorrect = function (correct) {
self.isCorrect = correct;
};
self.markAsCorrect = function () {
overlay.tint = 0x00FF00;
tween(overlay, {
alpha: 0.5
}, {
duration: 500
});
};
self.markAsIncorrect = function () {
overlay.tint = 0xFF0000;
tween(overlay, {
alpha: 0.5
}, {
duration: 500
});
};
self.reset = function () {
overlay.alpha = 0;
self.isSelected = false;
self.isEliminated = false;
};
self.eliminate = function () {
if (self.isCorrect) {
return false;
}
self.isEliminated = true;
tween(self, {
alpha: 0.3
}, {
duration: 300
});
return true;
};
self.down = function (x, y, obj) {
if (!self.isEliminated && !gameOver && !answerLocked) {
self.isSelected = true;
submitAnswer(self.index);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Character images for different emotions/states
// Game constants
var TOTAL_QUESTIONS = 10;
var TIME_PER_QUESTION = 30; // seconds
var BUTTON_SPACING = 180;
// Game state variables
var currentQuestion = 0;
var score = 0;
var timeLeft = TIME_PER_QUESTION;
var gameOver = false;
var answerLocked = false;
var secondChanceActive = false; // Track if second chance is active for current question
var currentCorrectIndex = 0;
// Quiz questions
var questions = [{
question: "What is the capital of France?",
answers: ["Paris", "London", "Berlin", "Madrid"],
correctIndex: 0
}, {
question: "Which planet is known as the Red Planet?",
answers: ["Venus", "Mars", "Jupiter", "Saturn"],
correctIndex: 1
}, {
question: "What is the largest mammal on Earth?",
answers: ["Elephant", "Giraffe", "Blue Whale", "Polar Bear"],
correctIndex: 2
}, {
question: "Which of these is not a programming language?",
answers: ["Java", "Python", "Banana", "Ruby"],
correctIndex: 2
}, {
question: "What year did the Titanic sink?",
answers: ["1912", "1905", "1920", "1931"],
correctIndex: 0
}, {
question: "Which element has the chemical symbol 'O'?",
answers: ["Gold", "Oxygen", "Osmium", "Oganesson"],
correctIndex: 1
}, {
question: "Who painted the Mona Lisa?",
answers: ["Van Gogh", "Picasso", "Michelangelo", "Leonardo da Vinci"],
correctIndex: 3
}, {
question: "What is the smallest prime number?",
answers: ["0", "1", "2", "3"],
correctIndex: 2
}, {
question: "Which country is home to the kangaroo?",
answers: ["New Zealand", "South Africa", "Australia", "Brazil"],
correctIndex: 2
}, {
question: "How many sides does a hexagon have?",
answers: ["5", "6", "7", "8"],
correctIndex: 1
}];
// Background colors for different questions
var backgroundColors = [0x87CEEB,
// Sky blue
0x98FB98,
// Pale green
0xFFB6C1,
// Light pink
0xFFD700,
// Gold
0xE6E6FA,
// Lavender
0xFFA07A,
// Light salmon
0xADD8E6,
// Light blue
0xF0E68C,
// Khaki
0xD8BFD8,
// Thistle
0xAFEEEE // Pale turquoise
];
// Create UI elements
var theset = game.addChild(LK.getAsset('theset', {
anchorX: 0.5,
anchorY: 0.5
}));
theset.position.set(2048 / 2 - 30 + 10, 2732 / 2 - 600 + 400 + 100);
var mainQuestionBoard = game.addChild(LK.getAsset('mainquestionboard', {
anchorX: 0.5,
anchorY: 0.5
}));
mainQuestionBoard.position.set(2048 / 2 + 135, 2732 / 2 + 430);
var questionCard = game.addChild(LK.getAsset('questionCard', {
anchorX: 0.5,
anchorY: -0.8
}));
questionCard.position.set(2048 / 2, 2732 / 2 - 500);
var questionText = new Text2("", {
size: 70,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 4
});
questionText.anchor.set(0.5, 0.5);
questionText.position.set(0, 920);
questionCard.addChild(questionText);
var answerButtons = [];
for (var i = 0; i < 4; i++) {
var button = new QuestionButton(i, "");
if (i === 0) {
// Move button A 500 pixels down and 215 pixels left
button.position.set(2048 / 2 - 515, 2732 / 2 - 100 + i * BUTTON_SPACING + 970);
} else if (i === 1) {
// Move button B 970 pixels down and 400 pixels right, then 20 pixels left
button.position.set(2048 / 2 + 510, 2732 / 2 - 100 + i * BUTTON_SPACING + 790);
} else if (i === 2) {
// Move button C 950 pixels down and 510 pixels left
button.position.set(2048 / 2 - 510, 2732 / 2 - 200 + i * BUTTON_SPACING + 1010);
} else {
button.position.set(2048 / 2 + 515, 2732 / 2 - 200 + i * BUTTON_SPACING + 830);
}
answerButtons.push(button);
game.addChild(button);
}
// Create jokers
var jokers = [];
var jokerTypes = ["fifty", "audience", "phone", "second"];
var jokerIcons = ["50/50", "👥", "📞", "🔄"];
for (var i = 0; i < 4; i++) {
var joker = new Joker(jokerTypes[i], jokerIcons[i]);
joker.position.set(250 + i * 150, 200);
jokers.push(joker);
game.addChild(joker);
}
// Create character
var character = new Character();
character.position.set(2048 / 2, 2732 - 300);
game.addChild(character);
// Create timer UI
var timerText = new Text2("", {
size: 100,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 5
});
timerText.anchor.set(0.5, 0.5);
timerText.position.set(2048 / 2, 150);
game.addChild(timerText);
// Create score display
var scoreText = new Text2("Score: 0", {
size: 70,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 4
});
scoreText.anchor.set(1, 0);
scoreText.position.set(2048 - 50, 50);
game.addChild(scoreText);
// Create question counter
var counterText = new Text2("Question: 1/" + TOTAL_QUESTIONS, {
size: 70,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 4
});
counterText.anchor.set(0, 0);
counterText.position.set(150, 50);
game.addChild(counterText);
// Second chance indicator text
var secondChanceText = new Text2("", {
size: 60,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 3
});
secondChanceText.anchor.set(0.5, 0.5);
secondChanceText.position.set(2048 / 2, 250);
game.addChild(secondChanceText);
// Create phone a friend popup
var phoneFriendPopup = new PhoneFriendPopup();
phoneFriendPopup.position.set(2048 / 2, 2732 / 2);
game.addChild(phoneFriendPopup);
// Game timer
var gameTimer = LK.setInterval(function () {
if (gameOver || answerLocked) {
return;
}
timeLeft--;
timerText.setText(timeLeft);
// Change character expression when time is running low
if (timeLeft <= 5) {
character.showExcited();
}
if (timeLeft <= 0) {
timeExpired();
}
}, 1000);
// Game functions
function loadQuestion(index) {
if (index >= questions.length) {
endGame(true);
return;
}
// Change background color
game.setBackgroundColor(backgroundColors[index]);
var question = questions[index];
questionText.setText(question.question);
currentCorrectIndex = question.correctIndex;
for (var i = 0; i < 4; i++) {
answerButtons[i].setText(question.answers[i]);
answerButtons[i].setCorrect(i === question.correctIndex);
answerButtons[i].reset();
}
timeLeft = TIME_PER_QUESTION;
timerText.setText(timeLeft);
currentQuestion = index;
counterText.setText("Question: " + (currentQuestion + 1) + "/" + TOTAL_QUESTIONS);
character.showNeutral();
secondChanceActive = false; // Reset second chance status for new question
secondChanceText.setText(""); // Clear second chance indicator
answerLocked = false;
}
function submitAnswer(index) {
if (answerLocked) {
return;
}
answerLocked = true;
var correct = index === currentCorrectIndex;
if (correct) {
LK.getSound('correctSound').play();
answerButtons[index].markAsCorrect();
character.showHappy();
score++;
scoreText.setText("Score: " + score);
LK.setTimeout(function () {
loadQuestion(currentQuestion + 1);
}, 1500);
} else {
LK.getSound('incorrectSound').play();
answerButtons[index].markAsIncorrect();
character.showSad();
// Check if second chance is active (already activated for this question)
if (secondChanceActive) {
// Second chance was already used and failed, so show correct answer and end game
answerButtons[currentCorrectIndex].markAsCorrect();
LK.setTimeout(function () {
endGame(false);
}, 2000);
} else {
// If second chance joker hasn't been used up (not active for this question)
var secondChanceJoker = findJokerByType("second");
if (!secondChanceJoker.used) {
// If the joker is available, automatically use it
LK.setTimeout(function () {
activateJoker("second");
}, 2000);
} else {
// If joker was used in a previous question, show correct answer and end game
answerButtons[currentCorrectIndex].markAsCorrect();
LK.setTimeout(function () {
endGame(false);
}, 2000);
}
}
}
}
function timeExpired() {
answerLocked = true;
character.showSad();
// Highlight correct answer
answerButtons[currentCorrectIndex].markAsCorrect();
LK.setTimeout(function () {
endGame(false);
}, 2000);
}
function activateJoker(type) {
var joker = findJokerByType(type);
if (!joker || joker.used) {
return;
}
LK.getSound('jokerSound').play();
switch (type) {
case "fifty":
useFiftyFifty();
break;
case "audience":
useAudienceHelp();
break;
case "phone":
usePhoneFriend();
break;
case "second":
useSecondChance();
break;
}
joker.use();
}
function findJokerByType(type) {
for (var i = 0; i < jokers.length; i++) {
if (jokers[i].type === type) {
return jokers[i];
}
}
return null;
}
function useFiftyFifty() {
var eliminated = 0;
var attempts = 0;
// Try to eliminate two wrong answers
while (eliminated < 2 && attempts < 10) {
attempts++;
var randomIndex = Math.floor(Math.random() * 4);
if (answerButtons[randomIndex].eliminate()) {
eliminated++;
}
}
}
function useAudienceHelp() {
// Calculate audience accuracy based on question number
// Accuracy decreases as questions get harder
var baseAccuracy = 0.99 - currentQuestion * 0.05;
for (var i = 0; i < 4; i++) {
var percentage;
if (i === currentCorrectIndex) {
// Correct answer gets higher percentage based on accuracy
percentage = Math.floor(baseAccuracy * 100);
} else {
// Distribute remaining percentage among wrong answers
percentage = Math.floor((1 - baseAccuracy) * 33);
}
// Update button text to show percentage
var originalText = questions[currentQuestion].answers[i];
answerButtons[i].setText(originalText + " (" + percentage + "%)");
}
// Reset the text after 5 seconds
LK.setTimeout(function () {
for (var i = 0; i < 4; i++) {
answerButtons[i].setText(questions[currentQuestion].answers[i]);
}
}, 5000);
}
function usePhoneFriend() {
phoneFriendPopup.show();
}
function useSecondChance() {
// Mark second chance as active for the current question
secondChanceActive = true;
// Display second chance status
secondChanceText.setText("Second Chance Active ❤️");
secondChanceText.visible = true;
// Reset all buttons
for (var i = 0; i < 4; i++) {
answerButtons[i].reset();
}
// Unlock answer selection
answerLocked = false;
// Reset character
character.showNeutral();
}
function phoneFriendCallback(friendIndex) {
var friendKnowledge;
// Different friends have different knowledge areas
switch (friendIndex) {
case 0:
// Professor - 80% chance of being correct
friendKnowledge = 0.8;
break;
case 1:
// Scientist - 70% chance of being correct
friendKnowledge = 0.7;
break;
case 2:
// Artist - 60% chance of being correct
friendKnowledge = 0.6;
break;
case 3:
// Engineer - 75% chance of being correct
friendKnowledge = 0.75;
break;
}
var answerIndex;
// Determine if friend gives correct answer based on knowledge
if (Math.random() < friendKnowledge) {
answerIndex = currentCorrectIndex;
} else {
// Select a random wrong answer
do {
answerIndex = Math.floor(Math.random() * 4);
} while (answerIndex === currentCorrectIndex);
}
// Highlight the friend's suggestion
var originalColor = answerButtons[answerIndex].children[0].tint;
answerButtons[answerIndex].children[0].tint = 0x00FFFF;
// Reset the highlight after 5 seconds
LK.setTimeout(function () {
answerButtons[answerIndex].children[0].tint = originalColor;
}, 5000);
}
function endGame(completed) {
gameOver = true;
// Update high score
if (score > storage.highScore) {
storage.highScore = score;
}
// Update total games played
storage.totalPlayed = (storage.totalPlayed || 0) + 1;
// Show game over screen
if (completed) {
LK.showYouWin();
} else {
LK.showGameOver();
}
}
// Initialize game
function initGame() {
score = 0;
gameOver = false;
currentQuestion = 0;
secondChanceActive = false;
// Reset jokers
for (var i = 0; i < jokers.length; i++) {
jokers[i].reset();
}
// Update score text
scoreText.setText("Score: " + score);
// Clear second chance text
secondChanceText.setText("");
// Start with first question
loadQuestion(0);
// Play background music
LK.playMusic('backgroundMusic');
}
// Start the game
initGame(); ===================================================================
--- original.js
+++ change.js
@@ -137,9 +137,9 @@
friendButton.position.set(0, -150 + i * 150);
friendButton.index = i;
friendButton.interactive = true;
friendButton.down = function (x, y, obj) {
- self.selectFriend(i); // Use the value of i from the loop instead of obj.parent.index
+ self.selectFriend(obj.parent.index);
};
self.addChild(friendButton);
friends.push(friendButton);
}
@@ -260,9 +260,9 @@
var score = 0;
var timeLeft = TIME_PER_QUESTION;
var gameOver = false;
var answerLocked = false;
-var usedSecondChance = false;
+var secondChanceActive = false; // Track if second chance is active for current question
var currentCorrectIndex = 0;
// Quiz questions
var questions = [{
question: "What is the capital of France?",
@@ -412,8 +412,18 @@
});
counterText.anchor.set(0, 0);
counterText.position.set(150, 50);
game.addChild(counterText);
+// Second chance indicator text
+var secondChanceText = new Text2("", {
+ size: 60,
+ fill: 0xFFFFFF,
+ stroke: 0x000000,
+ strokeThickness: 3
+});
+secondChanceText.anchor.set(0.5, 0.5);
+secondChanceText.position.set(2048 / 2, 250);
+game.addChild(secondChanceText);
// Create phone a friend popup
var phoneFriendPopup = new PhoneFriendPopup();
phoneFriendPopup.position.set(2048 / 2, 2732 / 2);
game.addChild(phoneFriendPopup);
@@ -452,9 +462,10 @@
timerText.setText(timeLeft);
currentQuestion = index;
counterText.setText("Question: " + (currentQuestion + 1) + "/" + TOTAL_QUESTIONS);
character.showNeutral();
- usedSecondChance = false;
+ secondChanceActive = false; // Reset second chance status for new question
+ secondChanceText.setText(""); // Clear second chance indicator
answerLocked = false;
}
function submitAnswer(index) {
if (answerLocked) {
@@ -473,21 +484,31 @@
}, 1500);
} else {
LK.getSound('incorrectSound').play();
answerButtons[index].markAsIncorrect();
- answerButtons[currentCorrectIndex].markAsCorrect();
character.showSad();
- // Check if second chance joker was used for this question
- if (usedSecondChance) {
+ // Check if second chance is active (already activated for this question)
+ if (secondChanceActive) {
+ // Second chance was already used and failed, so show correct answer and end game
+ answerButtons[currentCorrectIndex].markAsCorrect();
LK.setTimeout(function () {
endGame(false);
}, 2000);
} else {
- // If second chance joker hasn't been used, don't end game
- // Instead automatically activate second chance joker
- LK.setTimeout(function () {
- useSecondChance();
- }, 2000);
+ // If second chance joker hasn't been used up (not active for this question)
+ var secondChanceJoker = findJokerByType("second");
+ if (!secondChanceJoker.used) {
+ // If the joker is available, automatically use it
+ LK.setTimeout(function () {
+ activateJoker("second");
+ }, 2000);
+ } else {
+ // If joker was used in a previous question, show correct answer and end game
+ answerButtons[currentCorrectIndex].markAsCorrect();
+ LK.setTimeout(function () {
+ endGame(false);
+ }, 2000);
+ }
}
}
}
function timeExpired() {
@@ -568,13 +589,13 @@
function usePhoneFriend() {
phoneFriendPopup.show();
}
function useSecondChance() {
- // Only allow using if not already used
- if (usedSecondChance) {
- return;
- }
- usedSecondChance = true;
+ // Mark second chance as active for the current question
+ secondChanceActive = true;
+ // Display second chance status
+ secondChanceText.setText("Second Chance Active ❤️");
+ secondChanceText.visible = true;
// Reset all buttons
for (var i = 0; i < 4; i++) {
answerButtons[i].reset();
}
@@ -641,14 +662,17 @@
function initGame() {
score = 0;
gameOver = false;
currentQuestion = 0;
+ secondChanceActive = false;
// Reset jokers
for (var i = 0; i < jokers.length; i++) {
jokers[i].reset();
}
// Update score text
scoreText.setText("Score: " + score);
+ // Clear second chance text
+ secondChanceText.setText("");
// Start with first question
loadQuestion(0);
// Play background music
LK.playMusic('backgroundMusic');