/**** * Classes ****/ // Define InputText class to fix the 'InputText is not defined' error var InputText = Container.expand(function () { var self = Container.call(this); self.text = new Text2('', { size: 50, fill: "#ffffff" }); self.addChild(self.text); self.setText = function (text) { self.text.setText(text); }; self.getValue = function () { return self.text.text; }; return self; }); //<Assets used in the game will automatically appear here> // Question class to handle individual questions var Question = Container.expand(function () { var self = Container.call(this); self.text = new Text2('', { size: 50, fill: "#ffffff" }); self.addChild(self.text); self.setText = function (question) { self.text.setText(question); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize variables var questions = [{ question: "What is the correct form of the verb in this sentence: 'She ____ to the store.'", options: ["go", "goes", "gone"], answer: "goes" }, { question: "Choose the correct article: 'I saw ____ elephant at the zoo.'", options: ["a", "an", "the"], answer: "an" }, { question: "Which word is a noun: 'quickly, happiness, run'?", options: ["quickly", "happiness", "run"], answer: "happiness" } // Add more questions here up to 20,000 ]; var currentQuestionIndex = 0; var score = 0; var timer; var questionDisplay; var option1; var option2; var option3; var scoreTxt; var timerTxt; var currentQuestionIndex = 0; var score = 0; var timer; var questionDisplay; var answerInput; var scoreTxt; var timerTxt; // Function to start the game function startGame() { currentQuestionIndex = 0; score = 0; showQuestion(); startTimer(); } // Function to show a question function showQuestion() { if (currentQuestionIndex >= questions.length) { endGame(); return; } questionDisplay.setText(questions[currentQuestionIndex].question); option1.setText(questions[currentQuestionIndex].options[0]); option2.setText(questions[currentQuestionIndex].options[1]); option3.setText(questions[currentQuestionIndex].options[2]); } // Function to start the timer function startTimer() { var timeLeft = 10; timerTxt.setText('Time: ' + timeLeft); timer = LK.setInterval(function () { timeLeft--; timerTxt.setText('Time: ' + timeLeft); if (timeLeft <= 0) { checkAnswer(); } }, 1000); } // Function to check the answer function checkAnswer() { LK.clearInterval(timer); if (selectedOption && selectedOption.getText().toLowerCase() === questions[currentQuestionIndex].answer.toLowerCase()) { score++; scoreTxt.setText('Score: ' + score); } currentQuestionIndex++; showQuestion(); startTimer(); } // Function to end the game function endGame() { LK.clearInterval(timer); LK.showGameOver(); } // Initialize game elements questionDisplay = new Question(); questionDisplay.x = 2048 / 2; questionDisplay.y = 2732 / 4; game.addChild(questionDisplay); option1 = new InputText(); option1.x = 2048 / 2; option1.y = 2732 / 2; game.addChild(option1); option2 = new InputText(); option2.x = 2048 / 2; option2.y = 2732 / 2 + 100; game.addChild(option2); option3 = new InputText(); option3.x = 2048 / 2; option3.y = 2732 / 2 + 200; game.addChild(option3); scoreTxt = new Text2('Score: 0', { size: 50, fill: "#ffffff" }); scoreTxt.x = 2048 / 2; scoreTxt.y = 100; game.addChild(scoreTxt); timerTxt = new Text2('Time: 10', { size: 50, fill: "#ffffff" }); timerTxt.x = 2048 / 2; timerTxt.y = 200; game.addChild(timerTxt); // Start the game startGame(); // Event listeners for answer input game.down = function (x, y, obj) { // Simulate input for the answer var input = prompt("Enter your answer:"); answerInput.setText(input); checkAnswer(); }; game.update = function () { // Game update logic };
/****
* Classes
****/
// Define InputText class to fix the 'InputText is not defined' error
var InputText = Container.expand(function () {
var self = Container.call(this);
self.text = new Text2('', {
size: 50,
fill: "#ffffff"
});
self.addChild(self.text);
self.setText = function (text) {
self.text.setText(text);
};
self.getValue = function () {
return self.text.text;
};
return self;
});
//<Assets used in the game will automatically appear here>
// Question class to handle individual questions
var Question = Container.expand(function () {
var self = Container.call(this);
self.text = new Text2('', {
size: 50,
fill: "#ffffff"
});
self.addChild(self.text);
self.setText = function (question) {
self.text.setText(question);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize variables
var questions = [{
question: "What is the correct form of the verb in this sentence: 'She ____ to the store.'",
options: ["go", "goes", "gone"],
answer: "goes"
}, {
question: "Choose the correct article: 'I saw ____ elephant at the zoo.'",
options: ["a", "an", "the"],
answer: "an"
}, {
question: "Which word is a noun: 'quickly, happiness, run'?",
options: ["quickly", "happiness", "run"],
answer: "happiness"
}
// Add more questions here up to 20,000
];
var currentQuestionIndex = 0;
var score = 0;
var timer;
var questionDisplay;
var option1;
var option2;
var option3;
var scoreTxt;
var timerTxt;
var currentQuestionIndex = 0;
var score = 0;
var timer;
var questionDisplay;
var answerInput;
var scoreTxt;
var timerTxt;
// Function to start the game
function startGame() {
currentQuestionIndex = 0;
score = 0;
showQuestion();
startTimer();
}
// Function to show a question
function showQuestion() {
if (currentQuestionIndex >= questions.length) {
endGame();
return;
}
questionDisplay.setText(questions[currentQuestionIndex].question);
option1.setText(questions[currentQuestionIndex].options[0]);
option2.setText(questions[currentQuestionIndex].options[1]);
option3.setText(questions[currentQuestionIndex].options[2]);
}
// Function to start the timer
function startTimer() {
var timeLeft = 10;
timerTxt.setText('Time: ' + timeLeft);
timer = LK.setInterval(function () {
timeLeft--;
timerTxt.setText('Time: ' + timeLeft);
if (timeLeft <= 0) {
checkAnswer();
}
}, 1000);
}
// Function to check the answer
function checkAnswer() {
LK.clearInterval(timer);
if (selectedOption && selectedOption.getText().toLowerCase() === questions[currentQuestionIndex].answer.toLowerCase()) {
score++;
scoreTxt.setText('Score: ' + score);
}
currentQuestionIndex++;
showQuestion();
startTimer();
}
// Function to end the game
function endGame() {
LK.clearInterval(timer);
LK.showGameOver();
}
// Initialize game elements
questionDisplay = new Question();
questionDisplay.x = 2048 / 2;
questionDisplay.y = 2732 / 4;
game.addChild(questionDisplay);
option1 = new InputText();
option1.x = 2048 / 2;
option1.y = 2732 / 2;
game.addChild(option1);
option2 = new InputText();
option2.x = 2048 / 2;
option2.y = 2732 / 2 + 100;
game.addChild(option2);
option3 = new InputText();
option3.x = 2048 / 2;
option3.y = 2732 / 2 + 200;
game.addChild(option3);
scoreTxt = new Text2('Score: 0', {
size: 50,
fill: "#ffffff"
});
scoreTxt.x = 2048 / 2;
scoreTxt.y = 100;
game.addChild(scoreTxt);
timerTxt = new Text2('Time: 10', {
size: 50,
fill: "#ffffff"
});
timerTxt.x = 2048 / 2;
timerTxt.y = 200;
game.addChild(timerTxt);
// Start the game
startGame();
// Event listeners for answer input
game.down = function (x, y, obj) {
// Simulate input for the answer
var input = prompt("Enter your answer:");
answerInput.setText(input);
checkAnswer();
};
game.update = function () {
// Game update logic
};