Added the real questions
This commit is contained in:
parent
3107bd8a2f
commit
d6bdd56fef
9 changed files with 185 additions and 33 deletions
|
|
@ -3,7 +3,6 @@ import { gameState } from "./gamestate.js";
|
|||
|
||||
export default class extends Controller {
|
||||
startGame(ev) {
|
||||
console.log("Start game");
|
||||
gameState.clearChoices();
|
||||
}
|
||||
}
|
||||
|
|
@ -9,9 +9,9 @@ class GameState {
|
|||
return null;
|
||||
}
|
||||
|
||||
setQuestionChoice(qId, cId) {
|
||||
setQuestionChoice(qId, cId, isRight) {
|
||||
let savedItem = this._readGameState();
|
||||
savedItem[qId] = cId;
|
||||
savedItem[qId] = {cId: cId, isRight: isRight};
|
||||
localStorage.setItem(GAME_STATE_KEY, JSON.stringify(savedItem));
|
||||
}
|
||||
|
||||
|
|
@ -19,6 +19,20 @@ class GameState {
|
|||
localStorage.removeItem(GAME_STATE_KEY);
|
||||
}
|
||||
|
||||
getSummary() {
|
||||
let savedItem = this._readGameState();
|
||||
let summary = { totalAnswered: 0, totalRight: 0 };
|
||||
|
||||
for (let k in savedItem) {
|
||||
summary.totalAnswered++;
|
||||
if (savedItem[k].isRight) {
|
||||
summary.totalRight++;
|
||||
}
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
_readGameState() {
|
||||
let savedItem = localStorage.getItem(GAME_STATE_KEY);
|
||||
if (savedItem === null) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export default class extends Controller {
|
|||
if (hasAnswer) {
|
||||
this._revealAnswer();
|
||||
|
||||
let e = this.radioTargets.find((e) => e.value == hasAnswer);
|
||||
let e = this.radioTargets.find((e) => e.value == hasAnswer.cId);
|
||||
if (e) {
|
||||
e.checked = true;
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ export default class extends Controller {
|
|||
return;
|
||||
}
|
||||
|
||||
gameState.setQuestionChoice(this.qidValue, e.value);
|
||||
gameState.setQuestionChoice(this.qidValue, e.value, e.value === this.answerValue);
|
||||
|
||||
this.element.classList.add("reveal");
|
||||
window.setTimeout(() => { this._revealAnswer(); });
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export default class extends Controller {
|
|||
}
|
||||
|
||||
_startAnimating(t) {
|
||||
this._finalScore = 10;
|
||||
this._finalScore = gameState.getSummary().totalRight;
|
||||
|
||||
this._startT = t;
|
||||
this._finalArcPostition = 360 * this._finalScore / MAX_QUESTIONS;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue