From d63982bff0840f9ad18a03de4b8f6fe6f1e667cd Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Wed, 12 Apr 2023 18:58:14 +0200 Subject: [PATCH] Add memory if a guess took place for the current round --- game.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/game.js b/game.js index f66c7f1..edada4a 100644 --- a/game.js +++ b/game.js @@ -94,6 +94,7 @@ class Model { #currentCpu; #nextCpu; + #tookGuessOnCurrent; #score; #highscore; @@ -106,6 +107,8 @@ class Model { this.#nextCpu = this.#getRandomCpu(); this.#score = 0; this.#highscore = localStorage.getItem("highscore_cpu") ?? 0; + + this.#tookGuessOnCurrent = false; } get highscore() { @@ -124,8 +127,15 @@ class Model { return this.#nextCpu; } + get hasGuessed() { + return this.#tookGuessOnCurrent; + } + // Can be 'higher' or 'lower' postAnswer(answer) { + if (this.#tookGuessOnCurrent) return false; + this.#tookGuessOnCurrent = true; + let answerWasCorrect = false; if (answer === 'higher') { answerWasCorrect = this.nextCpu.score > this.#currentCpu.score; @@ -146,6 +156,7 @@ class Model { nextRound() { this.#currentCpu = this.#nextCpu; this.#nextCpu = this.#getRandomCpu(); + this.#tookGuessOnCurrent = false; } #getRandomCpu() {