summaryrefslogtreecommitdiff
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
parentfc54f453fcdd208bc92ae33dbaa0ccd7d54fcd57 (diff)
switch to 20 chars per level and clean up level size code
-rw-r--r--index.html50
-rw-r--r--index.js34
2 files changed, 26 insertions, 58 deletions
diff --git a/index.html b/index.html
index 0b6f8c3..cac2203 100644
--- a/index.html
+++ b/index.html
@@ -28,56 +28,6 @@
<label>Level</label>
<select id="level-select">
- <option value="1">100 Characters</option>
- <option value="2">200 Characters</option>
- <option value="3">300 Characters</option>
- <option value="4">400 Characters</option>
- <option value="5">500 Characters</option>
- <option value="6">600 Characters</option>
- <option value="7">700 Characters</option>
- <option value="8">800 Characters</option>
- <option value="9">900 Characters</option>
- <option value="10">1000 Characters</option>
- <option value="11">1100 Characters</option>
- <option value="12">1200 Characters</option>
- <option value="13">1300 Characters</option>
- <option value="14">1400 Characters</option>
- <option value="15">1500 Characters</option>
- <option value="16">1600 Characters</option>
- <option value="17">1700 Characters</option>
- <option value="18">1800 Characters</option>
- <option value="19">1900 Characters</option>
- <option value="20">2000 Characters</option>
- <option value="21">2100 Characters</option>
- <option value="22">2200 Characters</option>
- <option value="23">2300 Characters</option>
- <option value="24">2400 Characters</option>
- <option value="25">2500 Characters</option>
- <option value="26">2600 Characters</option>
- <option value="27">2700 Characters</option>
- <option value="28">2800 Characters</option>
- <option value="29">2900 Characters</option>
- <option value="30">3000 Characters</option>
- <option value="31">3100 Characters</option>
- <option value="32">3200 Characters</option>
- <option value="33">3300 Characters</option>
- <option value="34">3400 Characters</option>
- <option value="35">3500 Characters</option>
- <option value="36">3600 Characters</option>
- <option value="37">3700 Characters</option>
- <option value="38">3800 Characters</option>
- <option value="39">3900 Characters</option>
- <option value="40">4000 Characters</option>
- <option value="41">4100 Characters</option>
- <option value="42">4200 Characters</option>
- <option value="43">4300 Characters</option>
- <option value="44">4400 Characters</option>
- <option value="45">4500 Characters</option>
- <option value="46">4600 Characters</option>
- <option value="47">4700 Characters</option>
- <option value="48">4800 Characters</option>
- <option value="49">4900 Characters</option>
- <option value="50">5000 Characters</option>
</select>
<br>
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);