Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created September 24, 2020 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/8fcb645d3f2f2dbb195cf1cf2a548c72 to your computer and use it in GitHub Desktop.
Save parzibyte/8fcb645d3f2f2dbb195cf1cf2a548c72 to your computer and use it in GitHub Desktop.
checkGameStatus() {
if (this.playerWins()) {
Swal.fire("You win! The word was " + this.getUnhiddenWord());
this.resetGame();
}
if (this.playerLoses()) {
Swal.fire("You lose. The word was " + this.getUnhiddenWord());
this.resetGame();
}
},
getUnhiddenWord() {
let word = "";
for (const letter of this.hiddenWord) {
word += letter.letter;
}
return word;
},
playerWins() {
// If there's at least a hidden letter, the player hasn't win yet
for (const letter of this.hiddenWord) {
if (letter.hidden) {
return false;
}
}
return true;
},
playerLoses() {
return this.remainingAttempts <= 0;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment