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
===================================================================
--- original.js
+++ change.js
@@ -1,99 +1,133 @@
-/****
+/****
* 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) + 1;
- var num2 = Math.floor(Math.random() * 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, ...self.wrongAnswers];
- self.answerOptions.sort(() => 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;
+ 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) + 1;
+ var num2 = Math.floor(Math.random() * 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
+ 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: 100,
- fill: 0xFFFFFF
+ size: 100,
+ fill: 0xFFFFFF
});
var answerTexts = [new Text2('', {
- size: 80,
- fill: 0xFFFFFF
+ size: 80,
+ fill: 0xFFFFFF
}), new Text2('', {
- size: 80,
- fill: 0xFFFFFF
+ size: 80,
+ fill: 0xFFFFFF
}), new Text2('', {
- size: 80,
- fill: 0xFFFFFF
+ size: 80,
+ 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;
- answerTexts[i].y = 500 + i * 200;
- game.addChild(answerTexts[i]);
+ answerTexts[i].anchor.set(0.5, 0);
+ answerTexts[i].x = 2048 / 2;
+ answerTexts[i].y = 500 + i * 200;
+ game.addChild(answerTexts[i]);
}
// Function to start a new puzzle
function startNewPuzzle() {
- mathPuzzle.generatePuzzle();
- mathPuzzle.displayPuzzle();
+ mathPuzzle.generatePuzzle();
+ mathPuzzle.displayPuzzle();
}
// Event handler for selecting an answer
function selectAnswer(index) {
- if (mathPuzzle.answerOptions[index] === mathPuzzle.correctAnswer) {
- score++;
- startNewPuzzle();
- } else {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
+ if (mathPuzzle.answerOptions[index] === mathPuzzle.correctAnswer) {
+ score++;
+ startNewPuzzle();
+ } else {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
}
// Add event listeners for answer selection
for (var i = 0; i < answerTexts.length; i++) {
- answerTexts[i].down = function (x, y, obj) {
- selectAnswer(i);
- };
+ answerTexts[i].down = function (x, y, obj) {
+ selectAnswer(i);
+ };
}
// Start the first puzzle
startNewPuzzle();
// Update function to increase difficulty over time
game.update = function () {
- if (LK.ticks % 600 === 0) {// Every 10 seconds
- // Increase difficulty by reducing time to answer or increasing number range
- }
+ if (LK.ticks % 600 === 0) {// Every 10 seconds
+ // Increase difficulty by reducing time to answer or increasing number range
+ }
};
\ No newline at end of file