/****
* Classes
****/
// Class for Answer Button
var AnswerButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2('', {
size: 80,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.setText = function (text) {
buttonText.setText(text);
};
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
self.onClick = function (callback) {
self.down = function (x, y, obj) {
callback();
};
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for Quiz Question
var QuizQuestion = Container.expand(function () {
var self = Container.call(this);
var questionText = new Text2('', {
size: 100,
fill: 0xFFFFFF
});
questionText.anchor.set(0.5, 0.5);
self.addChild(questionText);
self.setQuestion = function (text) {
questionText.setText(text);
};
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
// Class for Quiz API
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Class for Quiz API
var QuizAPI = function QuizAPI() {
this.questions = [];
this.currentQuestionIndex = 0;
this.score = 0;
this.getQuestions = function () {
// This is where you would normally fetch the questions from an API
// For the purpose of this example, we will use a static list of questions
this.questions = [{
question: "The Pyramids of Giza were constructed using advanced alien technology.",
answer: "Mystery"
}, {
question: "The Antikythera Mechanism is considered the world’s first analog computer, used to predict celestial events.",
answer: "Science"
}, {
question: "Stonehenge was built by giants who roamed the earth in prehistoric times.",
answer: "Mystery"
}, {
question: "Lidar technology has been used to discover ancient Maya cities hidden beneath dense jungle canopies.",
answer: "Science"
}, {
question: "The Nazca Lines in Peru were created as landing strips for extraterrestrial spacecraft.",
answer: "Mystery"
}, {
question: "DNA analysis has confirmed that the people of Ötzi the Iceman’s community were early European farmers.",
answer: "Science"
}, {
question: "The Voynich Manuscript contains a secret code from an ancient, unknown civilization.",
answer: "Mystery"
}, {
question: "Ground-penetrating radar helped uncover Viking ship burials in Norway without disturbing the earth.",
answer: "Science"
}, {
question: "The Baghdad Battery was used to generate electricity thousands of years ago.",
answer: "Mystery"
}, {
question: "Carbon dating revealed that the Dead Sea Scrolls were written over 2,000 years ago.",
answer: "Science"
}, {
question: "Atlantis was a real, advanced civilization that sank beneath the ocean.",
answer: "Mystery"
}, {
question: "Laser scanning technology reconstructed the city layout of Angkor Wat.",
answer: "Science"
}, {
question: "The Ark of the Covenant is buried in Ethiopia, as claimed by local legend.",
answer: "Mystery"
}, {
question: "Isotope analysis from human remains shows migration patterns during the Bronze Age.",
answer: "Science"
}, {
question: "The Easter Island statues walked to their positions using ancient methods of transportation.",
answer: "Mystery"
}];
};
this.getCurrentQuestion = function () {
if (this.currentQuestionIndex < this.questions.length) {
return this.questions[this.currentQuestionIndex];
} else {
return {
question: "No more questions available.",
answer: ""
};
}
};
this.checkAnswer = function (answer) {
if (this.getCurrentQuestion().answer === answer) {
this.score++;
}
this.currentQuestionIndex++;
};
this.getScore = function () {
return this.score;
};
this.hasMoreQuestions = function () {
return this.currentQuestionIndex < this.questions.length;
};
};
var quizAPI = new QuizAPI();
quizAPI.getQuestions();
var questionDisplay = new QuizQuestion();
questionDisplay.setPosition(1024, 500);
game.addChild(questionDisplay);
var mysteryButton = new AnswerButton();
mysteryButton.setText("Mystery");
mysteryButton.setPosition(724, 1500);
game.addChild(mysteryButton);
var scienceButton = new AnswerButton();
scienceButton.setText("Science");
scienceButton.setPosition(1324, 1500);
game.addChild(scienceButton);
var scoreDisplay = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreDisplay);
var finalScoreText = new Text2('', {
size: 80,
fill: 0xFFFFFF
});
finalScoreText.anchor.set(0.5, 0);
LK.gui.bottom.addChild(finalScoreText);
scoreDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreDisplay);
function updateQuestion() {
if (quizAPI.hasMoreQuestions()) {
questionDisplay.setQuestion(quizAPI.getCurrentQuestion().question);
} else {
finalScoreText.setText('Final Score: ' + quizAPI.getScore());
}
}
function checkAnswer(answer) {
quizAPI.checkAnswer(answer);
scoreDisplay.setText('Score: ' + quizAPI.getScore());
updateQuestion();
}
mysteryButton.onClick(function () {
checkAnswer("Mystery");
});
scienceButton.onClick(function () {
checkAnswer("Science");
});
updateQuestion(); /****
* Classes
****/
// Class for Answer Button
var AnswerButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2('', {
size: 80,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.setText = function (text) {
buttonText.setText(text);
};
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
self.onClick = function (callback) {
self.down = function (x, y, obj) {
callback();
};
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for Quiz Question
var QuizQuestion = Container.expand(function () {
var self = Container.call(this);
var questionText = new Text2('', {
size: 100,
fill: 0xFFFFFF
});
questionText.anchor.set(0.5, 0.5);
self.addChild(questionText);
self.setQuestion = function (text) {
questionText.setText(text);
};
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
// Class for Quiz API
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Class for Quiz API
var QuizAPI = function QuizAPI() {
this.questions = [];
this.currentQuestionIndex = 0;
this.score = 0;
this.getQuestions = function () {
// This is where you would normally fetch the questions from an API
// For the purpose of this example, we will use a static list of questions
this.questions = [{
question: "The Pyramids of Giza were constructed using advanced alien technology.",
answer: "Mystery"
}, {
question: "The Antikythera Mechanism is considered the world’s first analog computer, used to predict celestial events.",
answer: "Science"
}, {
question: "Stonehenge was built by giants who roamed the earth in prehistoric times.",
answer: "Mystery"
}, {
question: "Lidar technology has been used to discover ancient Maya cities hidden beneath dense jungle canopies.",
answer: "Science"
}, {
question: "The Nazca Lines in Peru were created as landing strips for extraterrestrial spacecraft.",
answer: "Mystery"
}, {
question: "DNA analysis has confirmed that the people of Ötzi the Iceman’s community were early European farmers.",
answer: "Science"
}, {
question: "The Voynich Manuscript contains a secret code from an ancient, unknown civilization.",
answer: "Mystery"
}, {
question: "Ground-penetrating radar helped uncover Viking ship burials in Norway without disturbing the earth.",
answer: "Science"
}, {
question: "The Baghdad Battery was used to generate electricity thousands of years ago.",
answer: "Mystery"
}, {
question: "Carbon dating revealed that the Dead Sea Scrolls were written over 2,000 years ago.",
answer: "Science"
}, {
question: "Atlantis was a real, advanced civilization that sank beneath the ocean.",
answer: "Mystery"
}, {
question: "Laser scanning technology reconstructed the city layout of Angkor Wat.",
answer: "Science"
}, {
question: "The Ark of the Covenant is buried in Ethiopia, as claimed by local legend.",
answer: "Mystery"
}, {
question: "Isotope analysis from human remains shows migration patterns during the Bronze Age.",
answer: "Science"
}, {
question: "The Easter Island statues walked to their positions using ancient methods of transportation.",
answer: "Mystery"
}];
};
this.getCurrentQuestion = function () {
if (this.currentQuestionIndex < this.questions.length) {
return this.questions[this.currentQuestionIndex];
} else {
return {
question: "No more questions available.",
answer: ""
};
}
};
this.checkAnswer = function (answer) {
if (this.getCurrentQuestion().answer === answer) {
this.score++;
}
this.currentQuestionIndex++;
};
this.getScore = function () {
return this.score;
};
this.hasMoreQuestions = function () {
return this.currentQuestionIndex < this.questions.length;
};
};
var quizAPI = new QuizAPI();
quizAPI.getQuestions();
var questionDisplay = new QuizQuestion();
questionDisplay.setPosition(1024, 500);
game.addChild(questionDisplay);
var mysteryButton = new AnswerButton();
mysteryButton.setText("Mystery");
mysteryButton.setPosition(724, 1500);
game.addChild(mysteryButton);
var scienceButton = new AnswerButton();
scienceButton.setText("Science");
scienceButton.setPosition(1324, 1500);
game.addChild(scienceButton);
var scoreDisplay = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreDisplay);
var finalScoreText = new Text2('', {
size: 80,
fill: 0xFFFFFF
});
finalScoreText.anchor.set(0.5, 0);
LK.gui.bottom.addChild(finalScoreText);
scoreDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreDisplay);
function updateQuestion() {
if (quizAPI.hasMoreQuestions()) {
questionDisplay.setQuestion(quizAPI.getCurrentQuestion().question);
} else {
finalScoreText.setText('Final Score: ' + quizAPI.getScore());
}
}
function checkAnswer(answer) {
quizAPI.checkAnswer(answer);
scoreDisplay.setText('Score: ' + quizAPI.getScore());
updateQuestion();
}
mysteryButton.onClick(function () {
checkAnswer("Mystery");
});
scienceButton.onClick(function () {
checkAnswer("Science");
});
updateQuestion();