Code edit (1 edits merged)
Please save this source code
User prompt
Which One is a Lie?
Initial prompt
I want to make a game called “Which one is a lie?” The player is shown 3 sentences in each round. Let 2 of these sentences be true and 1 be a lie. The player tries to guess which one is a lie. If he guesses correctly, he gets 1 point. The game consists of 10 rounds in total. Questions can be from different topics, such as animals, space, history, etc. The interface should be simple and mobile friendly.
/****
* Classes
****/
// No plugins needed for MVP
// AnswerButton: A selectable answer option
var AnswerButton = Container.expand(function () {
var self = Container.call(this);
// Default state
self.state = 'default'; // 'default', 'selected', 'correct', 'wrong'
self.index = 0; // 0,1,2
// Attach default button asset
var btn = self.attachAsset('answerBtn', {
anchorX: 0.5,
anchorY: 0.5
});
// Attach answer text
self.txt = new Text2('', {
size: 80,
fill: 0xFFFFFF,
wordWrap: true,
wordWrapWidth: 1500,
align: 'center'
});
self.txt.anchor.set(0.5, 0.5);
self.txt.x = 0;
self.txt.y = 0;
self.addChild(self.txt);
// Set answer text
self.setText = function (str) {
self.txt.setText(str);
};
// Set state: 'default', 'selected', 'correct', 'wrong'
self.setState = function (state) {
self.state = state;
if (state === 'default') {
btn.assetId = 'answerBtn';
} else if (state === 'selected') {
btn.assetId = 'answerBtnSelected';
} else if (state === 'correct') {
btn.assetId = 'answerBtnCorrect';
} else if (state === 'wrong') {
btn.assetId = 'answerBtnWrong';
}
// Swap asset
self.removeChild(btn);
btn = self.attachAsset(btn.assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.setChildIndex(btn, 0);
};
// Down event (touch/click)
self.down = function (x, y, obj) {
if (typeof self.onSelect === 'function') {
self.onSelect(self.index);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181c24
});
/****
* Game Code
****/
// Shapes for answer buttons
// --- DATA: 10 rounds, each with 3 statements (2 true, 1 lie) ---
// Each round: { statements: [str, str, str], lie: index }
var rounds = [{
statements: ["The heart of a shrimp is located in its head.", "Venus is the closest planet to the Sun.", "Bananas grow on plants that are technically herbs."],
lie: 1
}, {
statements: ["Honey never spoils and can last thousands of years.", "The Great Wall of China is visible from the Moon.", "Octopuses have three hearts."],
lie: 1
}, {
statements: ["A group of crows is called a murder.", "Humans and dinosaurs coexisted.", "The Eiffel Tower can be 15 cm taller during hot days."],
lie: 1
}, {
statements: ["Lightning can strike the same place twice.", "Goldfish only have a memory of three seconds.", "The unicorn is the national animal of Scotland."],
lie: 1
}, {
statements: ["There are more stars in the universe than grains of sand on Earth.", "Bats are blind.", "Some turtles can breathe through their butts."],
lie: 1
}, {
statements: ["The human nose can detect over 1 trillion smells.", "Mount Everest is the tallest mountain above sea level.", "Penguins can fly short distances."],
lie: 2
}, {
statements: ["The inventor of the lightbulb was Thomas Edison.", "A snail can sleep for three years.", "The Statue of Liberty was a gift from France."],
lie: 0
}, {
statements: ["The Amazon is the longest river in the world.", "Some metals are so reactive that they explode on contact with water.", "The fingerprints of a koala are so similar to humans that they can taint crime scenes."],
lie: 0
}, {
statements: ["The human body has four lungs.", "The Mona Lisa has no eyebrows.", "The speed of light is faster than the speed of sound."],
lie: 0
}, {
statements: ["The largest desert in the world is the Sahara.", "The tongue is the strongest muscle in the human body.", "A bolt of lightning contains enough energy to toast 100,000 slices of bread."],
lie: 1
}];
// Shuffle rounds for replayability
function shuffleArray(arr) {
for (var i = arr.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
shuffleArray(rounds);
// --- GAME STATE ---
var currentRound = 0;
var score = 0;
var selectedIndex = -1;
var locked = false; // Prevent multiple answers
var answerButtons = [];
var questionText = null;
var roundText = null;
var scoreText = null;
// --- GUI SETUP ---
// Score display (top right, away from top left menu)
scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0);
scoreText.x = LK.gui.top.width - 60;
scoreText.y = 30;
LK.gui.top.addChild(scoreText);
// Round display (top center)
roundText = new Text2('Round 1/10', {
size: 80,
fill: 0xFFFFFF
});
roundText.anchor.set(0.5, 0);
roundText.x = LK.gui.top.width / 2;
roundText.y = 30;
LK.gui.top.addChild(roundText);
// Question text (centered, above answers)
questionText = new Text2('', {
size: 90,
fill: 0xFFFBE6,
wordWrap: true,
wordWrapWidth: 1800,
align: 'center'
});
questionText.anchor.set(0.5, 0);
questionText.x = 2048 / 2;
questionText.y = 350;
game.addChild(questionText);
// --- ANSWER BUTTONS SETUP ---
var btnSpacing = 320;
var btnStartY = 800;
for (var i = 0; i < 3; i++) {
var btn = new AnswerButton();
btn.index = i;
btn.x = 2048 / 2;
btn.y = btnStartY + i * btnSpacing;
// Assign select handler
btn.onSelect = function (idx) {
handleAnswer(idx);
};
answerButtons.push(btn);
game.addChild(btn);
}
// --- GAME LOGIC ---
function showRound(roundIdx) {
locked = false;
selectedIndex = -1;
var round = rounds[roundIdx];
// Set question text
questionText.setText("Which one is a lie?");
// Set round/score
roundText.setText('Round ' + (roundIdx + 1) + '/10');
scoreText.setText('Score: ' + score);
// Shuffle answers for each round
var indices = [0, 1, 2];
shuffleArray(indices);
// Map: btnIdx -> original statement idx
var btnToStatement = [indices[0], indices[1], indices[2]];
// Store mapping for answer checking
showRound.btnToStatement = btnToStatement;
showRound.lieIdx = round.lie;
// Set button text and reset state
for (var i = 0; i < 3; i++) {
var statementIdx = btnToStatement[i];
answerButtons[i].setText(round.statements[statementIdx]);
answerButtons[i].setState('default');
}
}
// Handle answer selection
function handleAnswer(btnIdx) {
if (locked) return;
locked = true;
selectedIndex = btnIdx;
var round = rounds[currentRound];
var btnToStatement = showRound.btnToStatement;
var selectedStatementIdx = btnToStatement[btnIdx];
var isCorrect = selectedStatementIdx === round.lie;
// Mark selected
for (var i = 0; i < 3; i++) {
if (i === btnIdx) {
if (isCorrect) {
answerButtons[i].setState('correct');
} else {
answerButtons[i].setState('wrong');
}
} else {
// Show correct answer
if (btnToStatement[i] === round.lie) {
answerButtons[i].setState('correct');
} else {
answerButtons[i].setState('default');
}
}
}
// Update score
if (isCorrect) {
score += 1;
scoreText.setText('Score: ' + score);
}
// Wait, then next round or end
LK.setTimeout(function () {
currentRound += 1;
if (currentRound < 10) {
showRound(currentRound);
} else {
// Game over
LK.setScore(score);
LK.showGameOver();
}
}, 1200);
}
// --- START GAME ---
showRound(0);
// --- CLEANUP ON GAME OVER (handled by LK) ---
// --- (No update loop needed for this game) --- ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,241 @@
-/****
+/****
+* Classes
+****/
+// No plugins needed for MVP
+// AnswerButton: A selectable answer option
+var AnswerButton = Container.expand(function () {
+ var self = Container.call(this);
+ // Default state
+ self.state = 'default'; // 'default', 'selected', 'correct', 'wrong'
+ self.index = 0; // 0,1,2
+ // Attach default button asset
+ var btn = self.attachAsset('answerBtn', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Attach answer text
+ self.txt = new Text2('', {
+ size: 80,
+ fill: 0xFFFFFF,
+ wordWrap: true,
+ wordWrapWidth: 1500,
+ align: 'center'
+ });
+ self.txt.anchor.set(0.5, 0.5);
+ self.txt.x = 0;
+ self.txt.y = 0;
+ self.addChild(self.txt);
+ // Set answer text
+ self.setText = function (str) {
+ self.txt.setText(str);
+ };
+ // Set state: 'default', 'selected', 'correct', 'wrong'
+ self.setState = function (state) {
+ self.state = state;
+ if (state === 'default') {
+ btn.assetId = 'answerBtn';
+ } else if (state === 'selected') {
+ btn.assetId = 'answerBtnSelected';
+ } else if (state === 'correct') {
+ btn.assetId = 'answerBtnCorrect';
+ } else if (state === 'wrong') {
+ btn.assetId = 'answerBtnWrong';
+ }
+ // Swap asset
+ self.removeChild(btn);
+ btn = self.attachAsset(btn.assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.setChildIndex(btn, 0);
+ };
+ // Down event (touch/click)
+ self.down = function (x, y, obj) {
+ if (typeof self.onSelect === 'function') {
+ self.onSelect(self.index);
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x181c24
+});
+
+/****
+* Game Code
+****/
+// Shapes for answer buttons
+// --- DATA: 10 rounds, each with 3 statements (2 true, 1 lie) ---
+// Each round: { statements: [str, str, str], lie: index }
+var rounds = [{
+ statements: ["The heart of a shrimp is located in its head.", "Venus is the closest planet to the Sun.", "Bananas grow on plants that are technically herbs."],
+ lie: 1
+}, {
+ statements: ["Honey never spoils and can last thousands of years.", "The Great Wall of China is visible from the Moon.", "Octopuses have three hearts."],
+ lie: 1
+}, {
+ statements: ["A group of crows is called a murder.", "Humans and dinosaurs coexisted.", "The Eiffel Tower can be 15 cm taller during hot days."],
+ lie: 1
+}, {
+ statements: ["Lightning can strike the same place twice.", "Goldfish only have a memory of three seconds.", "The unicorn is the national animal of Scotland."],
+ lie: 1
+}, {
+ statements: ["There are more stars in the universe than grains of sand on Earth.", "Bats are blind.", "Some turtles can breathe through their butts."],
+ lie: 1
+}, {
+ statements: ["The human nose can detect over 1 trillion smells.", "Mount Everest is the tallest mountain above sea level.", "Penguins can fly short distances."],
+ lie: 2
+}, {
+ statements: ["The inventor of the lightbulb was Thomas Edison.", "A snail can sleep for three years.", "The Statue of Liberty was a gift from France."],
+ lie: 0
+}, {
+ statements: ["The Amazon is the longest river in the world.", "Some metals are so reactive that they explode on contact with water.", "The fingerprints of a koala are so similar to humans that they can taint crime scenes."],
+ lie: 0
+}, {
+ statements: ["The human body has four lungs.", "The Mona Lisa has no eyebrows.", "The speed of light is faster than the speed of sound."],
+ lie: 0
+}, {
+ statements: ["The largest desert in the world is the Sahara.", "The tongue is the strongest muscle in the human body.", "A bolt of lightning contains enough energy to toast 100,000 slices of bread."],
+ lie: 1
+}];
+// Shuffle rounds for replayability
+function shuffleArray(arr) {
+ for (var i = arr.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = arr[i];
+ arr[i] = arr[j];
+ arr[j] = temp;
+ }
+}
+shuffleArray(rounds);
+// --- GAME STATE ---
+var currentRound = 0;
+var score = 0;
+var selectedIndex = -1;
+var locked = false; // Prevent multiple answers
+var answerButtons = [];
+var questionText = null;
+var roundText = null;
+var scoreText = null;
+// --- GUI SETUP ---
+// Score display (top right, away from top left menu)
+scoreText = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(1, 0);
+scoreText.x = LK.gui.top.width - 60;
+scoreText.y = 30;
+LK.gui.top.addChild(scoreText);
+// Round display (top center)
+roundText = new Text2('Round 1/10', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+roundText.anchor.set(0.5, 0);
+roundText.x = LK.gui.top.width / 2;
+roundText.y = 30;
+LK.gui.top.addChild(roundText);
+// Question text (centered, above answers)
+questionText = new Text2('', {
+ size: 90,
+ fill: 0xFFFBE6,
+ wordWrap: true,
+ wordWrapWidth: 1800,
+ align: 'center'
+});
+questionText.anchor.set(0.5, 0);
+questionText.x = 2048 / 2;
+questionText.y = 350;
+game.addChild(questionText);
+// --- ANSWER BUTTONS SETUP ---
+var btnSpacing = 320;
+var btnStartY = 800;
+for (var i = 0; i < 3; i++) {
+ var btn = new AnswerButton();
+ btn.index = i;
+ btn.x = 2048 / 2;
+ btn.y = btnStartY + i * btnSpacing;
+ // Assign select handler
+ btn.onSelect = function (idx) {
+ handleAnswer(idx);
+ };
+ answerButtons.push(btn);
+ game.addChild(btn);
+}
+// --- GAME LOGIC ---
+function showRound(roundIdx) {
+ locked = false;
+ selectedIndex = -1;
+ var round = rounds[roundIdx];
+ // Set question text
+ questionText.setText("Which one is a lie?");
+ // Set round/score
+ roundText.setText('Round ' + (roundIdx + 1) + '/10');
+ scoreText.setText('Score: ' + score);
+ // Shuffle answers for each round
+ var indices = [0, 1, 2];
+ shuffleArray(indices);
+ // Map: btnIdx -> original statement idx
+ var btnToStatement = [indices[0], indices[1], indices[2]];
+ // Store mapping for answer checking
+ showRound.btnToStatement = btnToStatement;
+ showRound.lieIdx = round.lie;
+ // Set button text and reset state
+ for (var i = 0; i < 3; i++) {
+ var statementIdx = btnToStatement[i];
+ answerButtons[i].setText(round.statements[statementIdx]);
+ answerButtons[i].setState('default');
+ }
+}
+// Handle answer selection
+function handleAnswer(btnIdx) {
+ if (locked) return;
+ locked = true;
+ selectedIndex = btnIdx;
+ var round = rounds[currentRound];
+ var btnToStatement = showRound.btnToStatement;
+ var selectedStatementIdx = btnToStatement[btnIdx];
+ var isCorrect = selectedStatementIdx === round.lie;
+ // Mark selected
+ for (var i = 0; i < 3; i++) {
+ if (i === btnIdx) {
+ if (isCorrect) {
+ answerButtons[i].setState('correct');
+ } else {
+ answerButtons[i].setState('wrong');
+ }
+ } else {
+ // Show correct answer
+ if (btnToStatement[i] === round.lie) {
+ answerButtons[i].setState('correct');
+ } else {
+ answerButtons[i].setState('default');
+ }
+ }
+ }
+ // Update score
+ if (isCorrect) {
+ score += 1;
+ scoreText.setText('Score: ' + score);
+ }
+ // Wait, then next round or end
+ LK.setTimeout(function () {
+ currentRound += 1;
+ if (currentRound < 10) {
+ showRound(currentRound);
+ } else {
+ // Game over
+ LK.setScore(score);
+ LK.showGameOver();
+ }
+ }, 1200);
+}
+// --- START GAME ---
+showRound(0);
+// --- CLEANUP ON GAME OVER (handled by LK) ---
+// --- (No update loop needed for this game) ---
\ No newline at end of file