/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for Room var Room = Container.expand(function () { var self = Container.call(this); self.question = null; self.answer = null; self.code = null; self.setQuestion = function (question, answer, code) { self.question = question; self.answer = answer; self.code = code; }; self.checkAnswer = function (input) { return input === self.answer; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize rooms var rooms = []; var currentRoomIndex = 0; var currentRoom = null; // Questions and answers for each room var questions = [{ question: "What is the chemical symbol for water?", answer: "H2O", code: "1234" }, { question: "What planet is known as the Red Planet?", answer: "Mars", code: "5678" }, { question: "What is the speed of light?", answer: "299792458", code: "91011" }, { question: "What is the powerhouse of the cell?", answer: "Mitochondria", code: "1213" }, { question: "What is the largest organ in the human body?", answer: "Skin", code: "1415" }, { question: "What gas do plants absorb from the atmosphere?", answer: "CO2", code: "1617" }]; // Create rooms and set questions for (var i = 0; i < 6; i++) { var room = new Room(); room.setQuestion(questions[i].question, questions[i].answer, questions[i].code); rooms.push(room); } // Function to display the current room's question function displayQuestion() { var questionText = new Text2(rooms[currentRoomIndex].question, { size: 100, fill: 0xFFFFFF }); questionText.anchor.set(0.5, 0.5); questionText.x = 2048 / 2; questionText.y = 2732 / 2; game.addChild(questionText); } // Function to handle answer submission function submitAnswer(input) { if (rooms[currentRoomIndex].checkAnswer(input)) { currentRoomIndex++; if (currentRoomIndex < rooms.length) { displayQuestion(); } else { // Game completed var completionText = new Text2("Congratulations! You've completed the game.", { size: 100, fill: 0x00FF00 }); completionText.anchor.set(0.5, 0.5); completionText.x = 2048 / 2; completionText.y = 2732 / 2; game.addChild(completionText); } } else { // Incorrect answer var incorrectText = new Text2("Incorrect! Try again.", { size: 100, fill: 0xFF0000 }); incorrectText.anchor.set(0.5, 0.5); incorrectText.x = 2048 / 2; incorrectText.y = 2732 / 2; game.addChild(incorrectText); } } // Start the game by displaying the first question displayQuestion();
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for Room
var Room = Container.expand(function () {
var self = Container.call(this);
self.question = null;
self.answer = null;
self.code = null;
self.setQuestion = function (question, answer, code) {
self.question = question;
self.answer = answer;
self.code = code;
};
self.checkAnswer = function (input) {
return input === self.answer;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize rooms
var rooms = [];
var currentRoomIndex = 0;
var currentRoom = null;
// Questions and answers for each room
var questions = [{
question: "What is the chemical symbol for water?",
answer: "H2O",
code: "1234"
}, {
question: "What planet is known as the Red Planet?",
answer: "Mars",
code: "5678"
}, {
question: "What is the speed of light?",
answer: "299792458",
code: "91011"
}, {
question: "What is the powerhouse of the cell?",
answer: "Mitochondria",
code: "1213"
}, {
question: "What is the largest organ in the human body?",
answer: "Skin",
code: "1415"
}, {
question: "What gas do plants absorb from the atmosphere?",
answer: "CO2",
code: "1617"
}];
// Create rooms and set questions
for (var i = 0; i < 6; i++) {
var room = new Room();
room.setQuestion(questions[i].question, questions[i].answer, questions[i].code);
rooms.push(room);
}
// Function to display the current room's question
function displayQuestion() {
var questionText = new Text2(rooms[currentRoomIndex].question, {
size: 100,
fill: 0xFFFFFF
});
questionText.anchor.set(0.5, 0.5);
questionText.x = 2048 / 2;
questionText.y = 2732 / 2;
game.addChild(questionText);
}
// Function to handle answer submission
function submitAnswer(input) {
if (rooms[currentRoomIndex].checkAnswer(input)) {
currentRoomIndex++;
if (currentRoomIndex < rooms.length) {
displayQuestion();
} else {
// Game completed
var completionText = new Text2("Congratulations! You've completed the game.", {
size: 100,
fill: 0x00FF00
});
completionText.anchor.set(0.5, 0.5);
completionText.x = 2048 / 2;
completionText.y = 2732 / 2;
game.addChild(completionText);
}
} else {
// Incorrect answer
var incorrectText = new Text2("Incorrect! Try again.", {
size: 100,
fill: 0xFF0000
});
incorrectText.anchor.set(0.5, 0.5);
incorrectText.x = 2048 / 2;
incorrectText.y = 2732 / 2;
game.addChild(incorrectText);
}
}
// Start the game by displaying the first question
displayQuestion();