From 82573dc615710c13d988ef27823d24839df100ab Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 15 Sep 2020 12:31:35 -0500 Subject: switch to 20 chars per level and clean up level size code --- index.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 9c6c90d..b7386eb 100644 --- a/index.js +++ b/index.js @@ -9,12 +9,29 @@ let hintLevel = 0; let previousCharacters = []; let completed = false; let mode = "newchars"; -let totalChars = 100; + +const CHARS_PER_LEVEL = 20; + +let totalChars = CHARS_PER_LEVEL; + +function setupLevels() +{ + let levelSelect = $('#level-select'); + let numLevels = Math.floor(characters.length/CHARS_PER_LEVEL); + for (let i=0; i') + .val(i+1) + .text(levelString)); + } +} function randomCharacter() { - let minVal = level * 100 - totalChars; - let maxVal = level * 100; + let minVal = level * CHARS_PER_LEVEL - totalChars; + let maxVal = level * CHARS_PER_LEVEL; + console.log(minVal, maxVal); let index = Math.floor(Math.random() * (maxVal-minVal)) + minVal; return characters[index]; } @@ -24,22 +41,23 @@ function reset() completed = false; level = Number($('#level-select').val()); mode = $('#mode-select').val(); + if (mode === 'allchars') + totalChars = level * CHARS_PER_LEVEL; + else + totalChars = CHARS_PER_LEVEL; + $('#level').text(`Level ${level}`); totalGuesses = 0; totalCorrect = 0; previousCharacters = []; updateCharacter(); updateScore(); - - if (mode === 'allchars') - totalChars = level * 100; - else - totalChars = 100; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $(document).ready(() => { + setupLevels(); $('#level-select').val('1'); $('#level-select').change(reset); $('#mode-select').change(reset); -- cgit v1.2.1