Skip to content

Commit 681d903

Browse files
committed
New game mode
1 parent 260fd2a commit 681d903

File tree

7 files changed

+236
-120
lines changed

7 files changed

+236
-120
lines changed

folders/latin/entry-level/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
tandem at last/finally
150150
timeo, timere, timui fear/be afraid
151151
tu, tui you (singular)
152-
ubi where?/where/when
152+
ubi where(?)/when
153153
urbs, urbis, f. city/town
154154
venio, venire, veni come
155155
via, viae, f. street/road/way

help/index.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,21 @@ <h3 class="faq-header">Classic Mode</h3>
5858
sets will come up, and you have to <strong>type the definition</strong> and press <kbd>ENTER</kbd>.
5959
</p>
6060
<p class="faq-answer">
61-
You can <strong>keep playing for as long as you want</strong>, as the terms will keep reshuffling.
62-
When you are finished, <strong>press the finish button</strong>, and the site will show you a
63-
<strong>list of mistakes</strong> that you made.
61+
You can keep playing <strong>until the selected terms run out</strong>, or you can finish the game
62+
early using the finish button. At the end, you can <strong>retry your mistakes</strong>.
6463
</p>
6564
<p class="faq-answer">
6665
VTP6 is supported by a <strong>superior typo detection algorithm</strong> which can prompt you to
6766
retry a question if it thinks you made a typo. Furthermore, the algorithm <strong>ignores case and
6867
punctuation</strong> to make it easier for mobile users (where the first letter is usually
6968
auto-capitalised).
7069
</p>
70+
<h3 class="faq-header">Classic Infinite Mode</h3>
71+
<p class="faq-answer">
72+
Classic Infinite Mode is an extension of Classic Mode where the <strong>terms keep reshuffling
73+
forever</strong>. To exit, you can <strong>press the finish button</strong> and you can see your
74+
mistakes in a table, just like with Classic Mode.
75+
</p>
7176
<h3 class="faq-header">Match Mode</h3>
7277
<p class="faq-answer">
7378
The aim of Match Mode is to <strong>pair up the six terms</strong> on the left <strong>with the six

scripts/folders-classic.js

Lines changed: 219 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
// NOTE: because Quick Fire and Classic share a lot of features,
2-
// the code behind Quick Fire mode was added to this file instead
3-
// of a separate folders-quickfire.js
1+
// NOTE: this file contains the code behind the Classic, Classic Infinite, and
2+
// Quick Fire modes on VTP6. They were bundled together because they share a lot of
3+
// features with each other, and so some code can be reused.
4+
5+
// NOTE: this is going to be very confusing, but whenever the code mentions
6+
// `classic` mode, this means "Classic Infinite" mode. "Classic" mode is referred to
7+
// as `legacy` mode in the code. This is because what is now "Classic Infinite" mode
8+
// was originally called "Classic" mode, and what is now "Classic" mode was added
9+
// in later at the request of a VTP6 user.
410

511
let full_terms_list = [];
612
let randomised_terms = [];
@@ -27,7 +33,9 @@ function set_progress_bar_background(val) {
2733
.style.width = `${100 - val}%`;
2834
}
2935

30-
function new_question() {
36+
function new_question(reload=true) {
37+
if (randomised_terms.length === 0 && !reload) return false;
38+
3139
[question, answer] = randomised_terms.shift();
3240
document.getElementById("classic-question-text").innerHTML = sanitise(question);
3341

@@ -38,9 +46,10 @@ function new_question() {
3846
if (OPTIONS["all"]) document.getElementById("classic-question-text").innerHTML +=
3947
` (<span id="classic-all-num">0</span>/${split_answer.length})`;
4048

41-
if (randomised_terms.length === 0) randomised_terms = random_shuffle(full_terms_list);
49+
if (randomised_terms.length === 0 && reload) randomised_terms = random_shuffle([...full_terms_list]);
4250

4351
textbox.focus();
52+
return true;
4453
}
4554

4655
function update_bar_text() {
@@ -158,6 +167,71 @@ function check_input_classic() {
158167
update_bar_text();
159168
}
160169

170+
function check_input_legacy() {
171+
let result = check_input(userans = textbox.value);
172+
let cont = true;
173+
174+
if (result === undefined) return;
175+
176+
textbox.classList.remove("correct");
177+
textbox.classList.remove("wrong");
178+
textbox.offsetWidth;
179+
180+
if (OPTIONS["all"]) {
181+
if (result) {
182+
textbox.classList.add("correct");
183+
split_answer = split_answer.filter(l =>
184+
!l.map(remove_punctuation)
185+
.includes(remove_punctuation(userans))
186+
);
187+
if (split_answer.length === 0) {
188+
correct++;
189+
document.getElementById("typo-text").innerHTML = `
190+
<span class="green">Correct!</span>
191+
`;
192+
cont = new_question(false);
193+
} else {
194+
let n = document.getElementById("classic-all-num");
195+
n.innerHTML = +n.innerHTML + 1;
196+
document.getElementById("typo-text").innerHTML = `
197+
<span class="green">Keep going!</span>
198+
`;
199+
}
200+
} else {
201+
wrong++;
202+
textbox.classList.add("wrong");
203+
document.getElementById("typo-text").innerHTML = `
204+
<span class="red">Wrong:</span>
205+
${answer}
206+
`;
207+
wrongtbl.push([question, answer, userans]);
208+
cont = new_question(false);
209+
}
210+
} else {
211+
if (result) {
212+
correct++;
213+
textbox.classList.add("correct");
214+
document.getElementById("typo-text").innerHTML = `
215+
<span class="green">Correct!</span>
216+
`;
217+
} else {
218+
wrong++;
219+
textbox.classList.add("wrong");
220+
document.getElementById("typo-text").innerHTML = `
221+
<span class="red">Wrong:</span>
222+
${answer}
223+
`;
224+
wrongtbl.push([question, answer, userans]);
225+
}
226+
cont = new_question(false);
227+
}
228+
update_bar_text();
229+
230+
if (!cont) {
231+
finish_legacy_game();
232+
}
233+
}
234+
161235
function check_input_quickfire() {
162236
let result = check_input(userans = textbox.value);
163237

@@ -289,6 +363,99 @@ function finish_classic_game() {
289363
}
290364
}
291365

366+
function finish_legacy_game() {
367+
if (randomised_terms.length === 0 || window.confirm("Are you sure you want to finish the game?")) {
368+
document.getElementById("classic-div").remove();
369+
let finish_div = document.createElement("div");
370+
finish_div.innerHTML = `
371+
<div id="score-div">
372+
<h3>${correct}/${correct + wrong} (${(correct / ((correct + wrong) || 1) * 100).toPrecision(3)}%)</h3>
373+
</div>
374+
<div id="restart-button-div">
375+
<button class="start-button" id="classic-retry-button"
376+
${wrongtbl.length === 0 ? 'disabled' : ''}>Mistakes</button>
377+
<button class="start-button" id="classic-restart-button">Restart!</button>
378+
</div>
379+
<table id="wrong-table">
380+
<tr>
381+
<th>Term</th>
382+
<th>Definition</th>
383+
<th>Your&nbsp;Answer</th>
384+
</tr>
385+
</table>
386+
`;
387+
finish_div.id = "finish-div";
388+
document.getElementById("content")
389+
.insertBefore(finish_div, document.getElementById("margin"));
390+
391+
[...wrongtbl].forEach(row => {
392+
let [a, b, c] = row;
393+
let tr = document.createElement("tr");
394+
tr.innerHTML = `
395+
<td>${a}</td> <td>${b}</td>
396+
<td><em>${c}</em></td>
397+
`;
398+
document.getElementById("wrong-table").appendChild(tr);
399+
});
400+
401+
document.getElementById("classic-restart-button")
402+
.addEventListener("click", () => {
403+
document.getElementById("finish-div").remove();
404+
document.getElementById("settings-bar").hidden = false;
405+
document.getElementById("units-flex").style.display = "flex";
406+
407+
full_terms_list = [];
408+
randomised_terms = [];
409+
410+
[question, answer] = ["", ""];
411+
412+
split_answer = [];
413+
414+
textbox = undefined;
415+
416+
correct = 0;
417+
wrong = 0;
418+
419+
wrongtbl = [];
420+
421+
quickfire_timer = 150;
422+
quickfire_timer_id = 0;
423+
quickfire_increment = 30;
424+
});
425+
426+
document.getElementById("classic-retry-button")
427+
.addEventListener("click", () => {
428+
let mistakes = [...wrongtbl].map(([x, y, _]) => [x, y]);
429+
430+
document.getElementById("finish-div").remove();
431+
document.getElementById("settings-bar").hidden = false;
432+
document.getElementById("units-flex").style.display = "flex";
433+
434+
full_terms_list = [];
435+
randomised_terms = [];
436+
437+
[question, answer] = ["", ""];
438+
439+
split_answer = [];
440+
441+
textbox = undefined;
442+
443+
correct = 0;
444+
wrong = 0;
445+
446+
wrongtbl = [];
447+
448+
quickfire_timer = 150;
449+
quickfire_timer_id = 0;
450+
quickfire_increment = 30;
451+
452+
folders_start_legacy([...mistakes]);
453+
document.getElementById("settings-bar").hidden = true;
454+
document.getElementById("units-flex").style.display = "none";
455+
})
456+
}
457+
}
458+
292459
function set_quickfire_high_score(score) {
293460
let currenths = get_cookies()["vtp6HighScore_quick_fire"];
294461
if (currenths === undefined || score > +currenths) {
@@ -411,6 +578,53 @@ function folders_start_classic(terms) {
411578
new_question();
412579
}
413580

581+
function folders_start_legacy(terms) {
582+
full_terms_list = [...terms];
583+
randomised_terms = random_shuffle(terms);
584+
585+
let classic_div = document.createElement("div");
586+
classic_div.innerHTML = `
587+
<div id="progress-bar-div">
588+
<div id="progress-bar-container"><div id="progress-bar"></div></div>
589+
<span id="progress-bar-text">0/0 (0.00%)</span>
590+
</div>
591+
<h1 id="classic-question">
592+
<button class="start-button" id="skip-button">Skip &rarr;</button>
593+
<span id="classic-question-text"></span>
594+
<button class="start-button" id="finish-button">Finish!</button>
595+
</h1>
596+
<div id="input-div">
597+
<input type="text" id="classic-input"
598+
placeholder="Type the definition here..."
599+
autocomplete="off" autocorrect="off"
600+
spellcheck="false" />
601+
<button class="start-button" id="square-finish-button"><img id="finish-image" /></button>
602+
</div>
603+
<p id="typo-text">&nbsp;</p>
604+
`;
605+
classic_div.id = "classic-div";
606+
document.getElementById("content")
607+
.insertBefore(classic_div, document.getElementById("margin"));
608+
609+
textbox = document.getElementById("classic-input");
610+
611+
document.getElementById("skip-button").addEventListener("click", () =>
612+
(textbox.value = "") || check_input_legacy()
613+
);
614+
615+
document.getElementById("finish-button").addEventListener("click", finish_legacy_game);
616+
document.getElementById("square-finish-button").addEventListener("click", finish_legacy_game);
617+
618+
textbox.addEventListener("keyup", ({ key }) => {
619+
if (key === "Enter") {
620+
check_input_legacy();
621+
}
622+
});
623+
624+
window.scrollTo(0, 0);
625+
new_question(false);
626+
}
627+
414628
function folders_start_quickfire(terms) {
415629
full_terms_list = [...terms];
416630
randomised_terms = random_shuffle(terms);

scripts/folders-misc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ document.addEventListener("keydown", (event) => {
6161

6262
const GAME_MODE_DESCRIPTIONS = {
6363
classic: "Simply give the definition of each term that comes up. No clock, no high scores, no stress.",
64+
classic_infinite: "Same as Classic mode, except you can keep answering questions for as long as you want.",
6465
match: "Match the terms on the left to the definitions on the right as quickly as possible.",
6566
quick_fire: "Race against the clock to answer as many questions as possible in a set amount of time."
6667
}

scripts/folders-start.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ function folders_start_game() {
1515
).map(arr => arr[1]).flat();
1616

1717
if (game_mode === "classic") {
18+
folders_start_legacy(selected_terms)
19+
} else if (game_mode === "classic_infinite") {
1820
folders_start_classic(selected_terms);
1921
} else if (game_mode === "match") {
2022
folders_start_match(selected_terms);

0 commit comments

Comments
 (0)