Skip to content

Commit

Permalink
- add small hack for edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasMue91 committed Mar 24, 2024
1 parent 2b64a98 commit 44b89cf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions games/rock_paper_scissors_mp.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,16 @@ <h1>Rock Paper Scissors</h1>
update(gameRef, isPlayerTwo ? {player2Choice: choice} : {player1Choice: choice});
}
});

// hack to make game check again whether the game has concluded
setTimeout(() => {
get(gameRef).then(snapshot => {
processGameUpdate(snapshot);
});
}, 1000);
}

onValue(gameRef, (snapshot) => {
let processGameUpdate = (snapshot) => {
const game = snapshot.val();
if (!game) return;
const {player1Choice, player2Choice} = game;
Expand All @@ -204,7 +211,8 @@ <h1>Rock Paper Scissors</h1>
document.getElementById('game-info').classList.add('hidden');
displayResult(player1Choice, player2Choice);
}
});
};
onValue(gameRef, processGameUpdate);

document.querySelectorAll('.choice').forEach(element => {
element.addEventListener('click', (event) => {
Expand Down

0 comments on commit 44b89cf

Please sign in to comment.