From 21813504272e24d486552a529be684b5b0dd4c8f Mon Sep 17 00:00:00 2001 From: Son Nguyen Hoang Date: Tue, 12 Mar 2024 18:52:40 -0400 Subject: [PATCH] Fix: Updated game UI --- .idea/.gitignore | 2 ++ index.html | 3 ++- src/js/game.js | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.idea/.gitignore b/.idea/.gitignore index b58b603..7abb13d 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -3,3 +3,5 @@ /workspace.xml # Editor-based HTTP Client requests /httpRequests/ +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/index.html b/index.html index a8e0d09..e90272b 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,7 @@

The Maze Game

A simple yet fun game to play when you're bored.

+

Lifetime Score: 0

@@ -34,7 +35,7 @@

The Maze Game

- + diff --git a/src/js/game.js b/src/js/game.js index 91b53cd..c285467 100644 --- a/src/js/game.js +++ b/src/js/game.js @@ -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'); @@ -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(); } } @@ -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)); -