/**** * Classes ****/ // Class for the Answer var Answer = Container.expand(function () { var self = Container.call(this); self.text = new Text2('', { size: 80, fill: "#ffffff" }); self.color = LK.getAsset('box', { width: 600, height: 200, color: 0x0000ff, shape: 'box', glow: true }); self.color.filters = [new filters.GlowFilter({ distance: 15, outerStrength: 2 })]; self.addChildAt(self.color, 0); self.text.anchor.set(0.5, 0.5); self.text.x = self.color.width / 2; self.text.y = self.color.height / 2; self.addChild(self.text); self.setText = function (text) { self.text.setText(text); }; self.correct = false; self.down = function (x, y, obj) { if (self.correct) { LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); self.color.tint = 0x00ff00; } else { LK.effects.flashScreen(0xff0000, 1000); self.color.tint = 0xff0000; } nextQuestion(); }; return self; }); //<Assets used in the game will automatically appear here> // Class for the Question var Question = Container.expand(function () { var self = Container.call(this); self.text = new Text2('', { size: 100, fill: "#ffffff", dropShadow: true, dropShadowColor: "#000000", dropShadowBlur: 4, dropShadowDistance: 6 }); self.text.filters = [new filters.DropShadowFilter()]; self.text.anchor.set(0.5, 0.5); self.addChild(self.text); self.setText = function (text) { self.text.setText(text); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var background = game.attachAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); // Function to generate random questions with different operations function generateQuestions() { var questions = []; var operations = ['+', '-', '*', '/']; for (var i = 0; i < 10; i++) { var operation = operations[Math.floor(Math.random() * operations.length)]; var num1 = Math.floor(Math.random() * 10); var num2 = Math.floor(Math.random() * 10); var correctAnswer; switch (operation) { case '+': correctAnswer = num1 + num2; break; case '-': correctAnswer = num1 - num2; break; case '*': correctAnswer = num1 * num2; break; case '/': correctAnswer = num1 / num2; break; } var question = { question: "What is " + num1 + " " + operation + " " + num2 + "?", answers: [{ text: correctAnswer.toString(), correct: true }, { text: (correctAnswer + 1).toString(), correct: false }, { text: (correctAnswer - 1).toString(), correct: false }, { text: (correctAnswer + 2).toString(), correct: false }] }; questions.push(question); } return questions; } // Generate questions var questions = generateQuestions(); var currentQuestionIndex = 0; var questionNode = new Question(); questionNode.x = 2048 / 2; questionNode.y = 2732 / 4; game.addChild(questionNode); var answerNodes = []; for (var i = 0; i < 4; i++) { var answerNode = new Answer(); answerNode.x = 2048 / 2; answerNode.y = 2732 / 2 + i * 200; game.addChild(answerNode); answerNodes.push(answerNode); } var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function nextQuestion() { if (currentQuestionIndex >= questions.length) { LK.showGameOver(); return; } var question = questions[currentQuestionIndex]; questionNode.setText(question.question); for (var i = 0; i < 4; i++) { answerNodes[i].setText(question.answers[i].text); answerNodes[i].correct = question.answers[i].correct; } currentQuestionIndex++; } nextQuestion(); game.update = function () { // Game update logic if needed };
/****
* Classes
****/
// Class for the Answer
var Answer = Container.expand(function () {
var self = Container.call(this);
self.text = new Text2('', {
size: 80,
fill: "#ffffff"
});
self.color = LK.getAsset('box', {
width: 600,
height: 200,
color: 0x0000ff,
shape: 'box',
glow: true
});
self.color.filters = [new filters.GlowFilter({
distance: 15,
outerStrength: 2
})];
self.addChildAt(self.color, 0);
self.text.anchor.set(0.5, 0.5);
self.text.x = self.color.width / 2;
self.text.y = self.color.height / 2;
self.addChild(self.text);
self.setText = function (text) {
self.text.setText(text);
};
self.correct = false;
self.down = function (x, y, obj) {
if (self.correct) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
self.color.tint = 0x00ff00;
} else {
LK.effects.flashScreen(0xff0000, 1000);
self.color.tint = 0xff0000;
}
nextQuestion();
};
return self;
});
//<Assets used in the game will automatically appear here>
// Class for the Question
var Question = Container.expand(function () {
var self = Container.call(this);
self.text = new Text2('', {
size: 100,
fill: "#ffffff",
dropShadow: true,
dropShadowColor: "#000000",
dropShadowBlur: 4,
dropShadowDistance: 6
});
self.text.filters = [new filters.DropShadowFilter()];
self.text.anchor.set(0.5, 0.5);
self.addChild(self.text);
self.setText = function (text) {
self.text.setText(text);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Function to generate random questions with different operations
function generateQuestions() {
var questions = [];
var operations = ['+', '-', '*', '/'];
for (var i = 0; i < 10; i++) {
var operation = operations[Math.floor(Math.random() * operations.length)];
var num1 = Math.floor(Math.random() * 10);
var num2 = Math.floor(Math.random() * 10);
var correctAnswer;
switch (operation) {
case '+':
correctAnswer = num1 + num2;
break;
case '-':
correctAnswer = num1 - num2;
break;
case '*':
correctAnswer = num1 * num2;
break;
case '/':
correctAnswer = num1 / num2;
break;
}
var question = {
question: "What is " + num1 + " " + operation + " " + num2 + "?",
answers: [{
text: correctAnswer.toString(),
correct: true
}, {
text: (correctAnswer + 1).toString(),
correct: false
}, {
text: (correctAnswer - 1).toString(),
correct: false
}, {
text: (correctAnswer + 2).toString(),
correct: false
}]
};
questions.push(question);
}
return questions;
}
// Generate questions
var questions = generateQuestions();
var currentQuestionIndex = 0;
var questionNode = new Question();
questionNode.x = 2048 / 2;
questionNode.y = 2732 / 4;
game.addChild(questionNode);
var answerNodes = [];
for (var i = 0; i < 4; i++) {
var answerNode = new Answer();
answerNode.x = 2048 / 2;
answerNode.y = 2732 / 2 + i * 200;
game.addChild(answerNode);
answerNodes.push(answerNode);
}
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function nextQuestion() {
if (currentQuestionIndex >= questions.length) {
LK.showGameOver();
return;
}
var question = questions[currentQuestionIndex];
questionNode.setText(question.question);
for (var i = 0; i < 4; i++) {
answerNodes[i].setText(question.answers[i].text);
answerNodes[i].correct = question.answers[i].correct;
}
currentQuestionIndex++;
}
nextQuestion();
game.update = function () {
// Game update logic if needed
};