From 7ed0ce5bc46369c194f69d8338a6b5b93a6659f4 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 15 May 2020 21:14:50 -0400 Subject: [PATCH] Improve math-quiz difficulty handling --- commands/games-sp/math-quiz.js | 34 ++++++++++++++++++++++++++-------- package.json | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/commands/games-sp/math-quiz.js b/commands/games-sp/math-quiz.js index e0414766..822d2c5a 100644 --- a/commands/games-sp/math-quiz.js +++ b/commands/games-sp/math-quiz.js @@ -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.** diff --git a/package.json b/package.json index 4ae6b267..9ac57141 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "114.10.2", + "version": "114.10.3", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {