User prompt
with the score gets higher the questions also get some complicated not very much
User prompt
Make the options in one line from up to down.
User prompt
make the font some bigger
User prompt
Like on the wrong answer screen gets red, on right answer the screen gets green.
User prompt
Show the timer on the screen.
User prompt
Make time limit on every answer for 5 seconds
User prompt
Score counts on right side, up side.
User prompt
Can't choose the options
User prompt
Make the options away from each other, I can't choose the options
User prompt
I cannot choose the options on every option I choose, that gets wrong.
Initial prompt
Math trivia
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for Math Puzzle
var MathPuzzle = Container.expand(function () {
var self = Container.call(this);
self.question = '';
self.correctAnswer = 0;
self.wrongAnswers = [];
self.answerOptions = [];
// Method to generate a new math puzzle
self.generatePuzzle = function () {
var num1 = Math.floor(Math.random() * (10 + Math.floor(score / 10))) + 1;
var num2 = Math.floor(Math.random() * (10 + Math.floor(score / 10))) + 1;
self.correctAnswer = num1 + num2;
self.question = num1 + " + " + num2 + " = ?";
self.wrongAnswers = [self.correctAnswer + Math.floor(Math.random() * 3) + 1, self.correctAnswer - Math.floor(Math.random() * 3) - 1];
self.answerOptions = [self.correctAnswer].concat(_toConsumableArray(self.wrongAnswers));
self.answerOptions.sort(function () {
return Math.random() - 0.5;
}); // Shuffle answers
};
// Method to display the puzzle
self.displayPuzzle = function () {
questionText.setText(self.question);
for (var i = 0; i < answerTexts.length; i++) {
answerTexts[i].setText(self.answerOptions[i]);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize variables
function _toConsumableArray(r) {
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) {
return _arrayLikeToArray(r, a);
}
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _iterableToArray(r) {
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) {
return Array.from(r);
}
}
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) {
return _arrayLikeToArray(r);
}
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) {
n[e] = r[e];
}
return n;
}
var score = 0;
var mathPuzzle = new MathPuzzle();
var questionText = new Text2('', {
size: 150,
fill: 0xFFFFFF
});
var scoreText = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0); // Anchor to the top right
scoreText.x = 2048; // Position at the right edge of the screen
scoreText.y = 0; // Position at the top of the screen
game.addChild(scoreText);
var answerTexts = [new Text2('', {
size: 120,
fill: 0xFFFFFF
}), new Text2('', {
size: 120,
fill: 0xFFFFFF
}), new Text2('', {
size: 120,
fill: 0xFFFFFF
})];
// Position question and answers
questionText.anchor.set(0.5, 0);
questionText.x = 2048 / 2;
questionText.y = 200;
game.addChild(questionText);
for (var i = 0; i < answerTexts.length; i++) {
answerTexts[i].anchor.set(0.5, 0);
answerTexts[i].x = 2048 / 2; // Center the answer options
answerTexts[i].y = 500 + i * 200; // Distribute the answer options vertically
game.addChild(answerTexts[i]);
}
// Function to start a new puzzle
function startNewPuzzle() {
mathPuzzle.generatePuzzle();
mathPuzzle.displayPuzzle();
// Reset the time limit for the new puzzle
timeLimit = 300; // 5 seconds * 60 FPS
}
// Event handler for selecting an answer
function selectAnswer(index) {
if (mathPuzzle.answerOptions[index] === mathPuzzle.correctAnswer) {
score++;
scoreText.setText('Score: ' + score); // Update the score display
LK.effects.flashScreen(0x00ff00, 1000); // Flash screen green
startNewPuzzle();
} else {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Add event listeners for answer selection
for (var i = 0; i < answerTexts.length; i++) {
(function (i) {
answerTexts[i].down = function (x, y, obj) {
selectAnswer(i);
};
})(i);
}
// Start the first puzzle
startNewPuzzle();
// Initialize a variable to keep track of the time limit for each question
var timeLimit = Math.max(60, 300 - score * 10); // Decrease time limit by 0.1 second for each point scored, with a minimum of 1 second
// Create a new Text2 object to display the timer
var timerText = new Text2('Time: ' + (timeLimit / 60).toFixed(1), {
size: 80,
fill: 0xFFFFFF
});
timerText.anchor.set(0, 0); // Anchor to the top left
timerText.x = 0; // Position at the left edge of the screen
timerText.y = 0; // Position at the top of the screen
game.addChild(timerText);
// Update function to increase difficulty over time and check if time limit is exceeded
game.update = function () {
// Decrease the time limit every tick
timeLimit--;
// Update the timer display
timerText.setText('Time: ' + (timeLimit / 60).toFixed(1));
// If time limit is exceeded, end the game
if (timeLimit <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
if (LK.ticks % 600 === 0) {// Every 10 seconds
// Increase difficulty by reducing time to answer or increasing number range
}
}; ===================================================================
--- original.js
+++ change.js
@@ -11,10 +11,10 @@
self.wrongAnswers = [];
self.answerOptions = [];
// Method to generate a new math puzzle
self.generatePuzzle = function () {
- var num1 = Math.floor(Math.random() * 10) + 1;
- var num2 = Math.floor(Math.random() * 10) + 1;
+ var num1 = Math.floor(Math.random() * (10 + Math.floor(score / 10))) + 1;
+ var num2 = Math.floor(Math.random() * (10 + Math.floor(score / 10))) + 1;
self.correctAnswer = num1 + num2;
self.question = num1 + " + " + num2 + " = ?";
self.wrongAnswers = [self.correctAnswer + Math.floor(Math.random() * 3) + 1, self.correctAnswer - Math.floor(Math.random() * 3) - 1];
self.answerOptions = [self.correctAnswer].concat(_toConsumableArray(self.wrongAnswers));
@@ -139,9 +139,9 @@
}
// Start the first puzzle
startNewPuzzle();
// Initialize a variable to keep track of the time limit for each question
-var timeLimit = 300; // 5 seconds * 60 FPS
+var timeLimit = Math.max(60, 300 - score * 10); // Decrease time limit by 0.1 second for each point scored, with a minimum of 1 second
// Create a new Text2 object to display the timer
var timerText = new Text2('Time: ' + (timeLimit / 60).toFixed(1), {
size: 80,
fill: 0xFFFFFF