Skip to content

Commit

Permalink
Fix: Updated game UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangsonww committed Mar 12, 2024
1 parent 3b4a06f commit 2181350
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<header>
<h1>The Maze Game</h1>
<p>A simple yet fun game to play when you're bored.</p>
<p id="lifetimeScore">Lifetime Score: 0</p>
</header>

<div class="game-container">
Expand All @@ -34,7 +35,7 @@ <h1>The Maze Game</h1>
<button id="moveRight" style="font: inherit; cursor: pointer">Right</button>
</div>
</div>
<button id="regenerateMaze" style="margin-top: 25px">Regenerate Maze</button>
<button id="regenerateMaze" style="margin-top: 25px" title="Too hard? Regenerate the maze! Note that you will lose 1 point for that." onclick="regenerateMaze()">Regenerate Maze</button>
<button id="aboutGame" onclick="window.location.href='src/html/about.html'" style="margin-top: 25px">About Game</button>
</div>

Expand Down
7 changes: 5 additions & 2 deletions src/js/game.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
document.getElementById('regenerateMaze').addEventListener('click', () => {
localStorage.getItem('highScore') ? localStorage.setItem('highScore', parseInt(localStorage.getItem('highScore')) - 1) : localStorage.setItem('highScore', 0);
window.location.reload();
});

document.getElementById('lifetimeScore').innerText = localStorage.getItem('highScore') ? `Lifetime Score: ${localStorage.getItem('highScore')}` : 'Lifetime Score: 0';

const canvas = document.getElementById('mazeCanvas');
const ctx = canvas.getContext('2d');

Expand Down Expand Up @@ -96,7 +99,8 @@ function movePlayer(dx, dy) {

function checkWin() {
if (player.x === exit.x && player.y === exit.y) {
alert("Congratulations, you've escaped the maze! Now we dare you to do it again!");
localStorage.getItem('highScore') ? localStorage.setItem('highScore', parseInt(localStorage.getItem('highScore')) + 1) : localStorage.setItem('highScore', 1);
alert("Congratulations, you've escaped the maze! Now we dare you to do it again! FYI, your lifetime score is currently: " + localStorage.getItem('highScore'));
window.location.reload();
}
}
Expand Down Expand Up @@ -125,4 +129,3 @@ document.getElementById('moveUp').addEventListener('click', () => movePlayer(0,
document.getElementById('moveDown').addEventListener('click', () => movePlayer(0, 1));
document.getElementById('moveLeft').addEventListener('click', () => movePlayer(-1, 0));
document.getElementById('moveRight').addEventListener('click', () => movePlayer(1, 0));

0 comments on commit 2181350

Please sign in to comment.