summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-09-15 12:31:35 -0500
committersanine-a <sanine.not@pm.me>2020-09-15 12:31:35 -0500
commit82573dc615710c13d988ef27823d24839df100ab (patch)
tree1cae3f0dc036dd24a96886ea293ab864a2719757 /index.js
parentfc54f453fcdd208bc92ae33dbaa0ccd7d54fcd57 (diff)
switch to 20 chars per level and clean up level size code
Diffstat (limited to 'index.js')
-rw-r--r--index.js34
1 files changed, 26 insertions, 8 deletions
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<numLevels; i++) {
+ let levelString = `${(i+1) * CHARS_PER_LEVEL} Characters`;
+ levelSelect.append(
+ $('<option></option>')
+ .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);