Skip to content

Commit

Permalink
Updated endgame state
Browse files Browse the repository at this point in the history
  • Loading branch information
townsean committed Mar 18, 2024
1 parent 10989fb commit 5b898da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
30 changes: 19 additions & 11 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,31 @@ function startRound(round) {
* Determine whether or not the player guess correctly before ending the round
*/
function endRound() {
let playerWon = true;
let pieceToMove = _blunders[_currentBlunderIndex].pieceToMove;
let destination = _blunders[_currentBlunderIndex].destination;
// Check to see if the user won the round
for(let cell of _clickedCells) {
if(!(cell[0] == pieceToMove[0] && cell[1] == pieceToMove[1]) ||
!(cell[0] == destination[0] && cell[1] == destination[1])) {
playerWon = false;
}
}
console.log(_clickedCells, pieceToMove, destination);

// Check to see if the user won the rounds
const containsPieceToMove = _clickedCells.some(p => pieceToMove[0] == p[0] && pieceToMove[1] == p[1]);
const containsDestination = _clickedCells.some(d => destination[0] == d[0] && destination[1] == d[1]);

const playerWon = containsPieceToMove && containsDestination;

if (playerWon) {
const blunderExplanation = document.getElementById('blunder-explanation');
blunderExplanation.innerText = _blunders[_currentBlunderIndex].description;

const hintButton = document.getElementById('hint-button');
hintButton.classList.add('hidden');

// Hide the next round button if player is in the last round
if(_currentBlunderIndex + 1 == _blunders.length) {
const nextRoundButton = document.getElementById('next-round-button');
nextRoundButton.classList.add('hidden');
}

const correctAnswer = document.getElementById('correct-answer');
correctAnswer.classList.remove('hidden');

const blunderExplanation = document.getElementById('blunder-explanation');
blunderExplanation.innerText = _blunders[_currentBlunderIndex].description;
} else {
const incorrectAnswer = document.getElementById('incorrect-answer');
incorrectAnswer.classList.remove('hidden');
Expand Down
8 changes: 8 additions & 0 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--color-primary: #222831;
--color-secondary: #31363F;
--teal: #76ABAE;
--translucent-teal: #76abaed9;
--dark-teal: #007F73;
--translucent-dark-teal: #007f728c;
--off-white: #EEEEEE;
Expand Down Expand Up @@ -222,4 +223,11 @@ tr:nth-child(odd) td:nth-child(even) {
font-family: "Holtwood One SC";
text-shadow: 2px 2px var(--color-primary);
font-size: 1.5rem;
}

#blunder-explanation {
padding: 5% 10%;
background-color: var(--translucent-teal);
text-shadow: 1px 1px var(--color-secondary);
text-align: justify;
}

0 comments on commit 5b898da

Please sign in to comment.