Improve math-quiz difficulty handling

This commit is contained in:
Dragon Fire
2020-05-15 21:14:50 -04:00
parent 69cdda1d66
commit 7ed0ce5bc4
2 changed files with 27 additions and 9 deletions
+26 -8
View File
@@ -4,13 +4,21 @@ const { list } = require('../../util/Util');
const difficulties = ['baby', 'easy', 'medium', 'hard', 'extreme', 'impossible'];
const operations = ['+', '-', '*'];
const maxValues = {
baby: 5,
easy: 10,
baby: 10,
easy: 50,
medium: 100,
hard: 500,
extreme: 1000,
impossible: Number.MAX_SAFE_INTEGER
};
const maxMultiplyValues = {
baby: 5,
easy: 12,
medium: 30,
hard: 50,
extreme: 100,
impossible: Number.MAX_SAFE_INTEGER
};
module.exports = class MathQuizCommand extends Command {
constructor(client) {
@@ -33,14 +41,24 @@ module.exports = class MathQuizCommand extends Command {
}
async run(msg, { difficulty }) {
const value1 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
const value2 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
const operation = operations[Math.floor(Math.random() * operations.length)];
let answer;
let answer, value1, value2;
switch (operation) {
case '+': answer = value1 + value2; break;
case '-': answer = value1 - value2; break;
case '*': answer = value1 * value2; break;
case '+':
value1 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
value2 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
answer = value1 + value2;
break;
case '-':
value1 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
value2 = Math.floor(Math.random() * maxValues[difficulty]) + 1;
answer = value1 - value2;
break;
case '*':
value1 = Math.floor(Math.random() * maxMultiplyValues[difficulty]) + 1;
value2 = Math.floor(Math.random() * maxMultiplyValues[difficulty]) + 1;
answer = value1 * value2;
break;
}
await msg.reply(stripIndents`
**You have 10 seconds to answer this question.**
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "114.10.2",
"version": "114.10.3",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {