/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Question class to handle math questions
//<Write imports for supported plugins here>
//<Assets used in the game will automatically appear here>
// Initialize variables
var Question = function Question() {
this.generate = function () {
// Generate a simple math question
var num1 = Math.floor(Math.random() * 10);
var num2 = Math.floor(Math.random() * 10);
this.answer = num1 + num2;
return "Is ".concat(num1, " + ").concat(num2, " = ").concat(this.answer, "?");
};
};
var question = new Question();
var questionText = new Text2('', {
size: 100,
fill: 0xFFFFFF
});
questionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(questionText);
var trueButton = LK.getAsset('button', {
x: 1024 - 200,
y: 2000,
anchorX: 0.5,
anchorY: 0.5
});
var falseButton = LK.getAsset('button', {
x: 1024 + 200,
y: 2000,
anchorX: 0.5,
anchorY: 0.5
});
game.addChild(trueButton);
game.addChild(falseButton);
// Create an asset named 'ali' and position it at the top of the screen
var ali = LK.getAsset('ali', {
x: 1024,
y: 400 + 2732 * 0.2,
anchorX: 0.5,
anchorY: 0.5
});
game.addChild(ali);
function askQuestion() {
questionText.setText(question.generate());
}
var score = 0; // Initialize score variable
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function handleAnswer(isTrue) {
if (isTrue) {
score++; // Increment score each time a question is answered correctly
scoreText.setText(score.toString());
askQuestion();
} else {
LK.showGameOver();
}
}
trueButton.down = function (x, y, obj) {
handleAnswer(true);
};
falseButton.down = function (x, y, obj) {
handleAnswer(false);
};
// Start the game by asking the first question
askQuestion();
// Set a timeout to end the game after 1 minute
LK.setTimeout(function () {
LK.showGameOver();
}, 60000); /****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Question class to handle math questions
//<Write imports for supported plugins here>
//<Assets used in the game will automatically appear here>
// Initialize variables
var Question = function Question() {
this.generate = function () {
// Generate a simple math question
var num1 = Math.floor(Math.random() * 10);
var num2 = Math.floor(Math.random() * 10);
this.answer = num1 + num2;
return "Is ".concat(num1, " + ").concat(num2, " = ").concat(this.answer, "?");
};
};
var question = new Question();
var questionText = new Text2('', {
size: 100,
fill: 0xFFFFFF
});
questionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(questionText);
var trueButton = LK.getAsset('button', {
x: 1024 - 200,
y: 2000,
anchorX: 0.5,
anchorY: 0.5
});
var falseButton = LK.getAsset('button', {
x: 1024 + 200,
y: 2000,
anchorX: 0.5,
anchorY: 0.5
});
game.addChild(trueButton);
game.addChild(falseButton);
// Create an asset named 'ali' and position it at the top of the screen
var ali = LK.getAsset('ali', {
x: 1024,
y: 400 + 2732 * 0.2,
anchorX: 0.5,
anchorY: 0.5
});
game.addChild(ali);
function askQuestion() {
questionText.setText(question.generate());
}
var score = 0; // Initialize score variable
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function handleAnswer(isTrue) {
if (isTrue) {
score++; // Increment score each time a question is answered correctly
scoreText.setText(score.toString());
askQuestion();
} else {
LK.showGameOver();
}
}
trueButton.down = function (x, y, obj) {
handleAnswer(true);
};
falseButton.down = function (x, y, obj) {
handleAnswer(false);
};
// Start the game by asking the first question
askQuestion();
// Set a timeout to end the game after 1 minute
LK.setTimeout(function () {
LK.showGameOver();
}, 60000);