diff --git a/index.html b/index.html index 91f6199..47b1aa3 100644 --- a/index.html +++ b/index.html @@ -20,6 +20,7 @@
Score:
diff --git a/script.js b/script.js index 792fb04..c4eb6b5 100644 --- a/script.js +++ b/script.js @@ -48,6 +48,7 @@ const levelChoicesTarget = byId("levelChoice") const startGameBtn = byId("startGameBtn") const stopGameBtn = byId("stopGameBtn") const canvasTarget = byId("canvasTarget") +const scoreTarget = byId("scoreTarget") /** @@ -89,6 +90,7 @@ async function startGame(gameID) { // Initialize the map & snake arrays let map = []; let snake = []; + let score = 0; /// First with empty cells... for(let i = 0; i < level.dimensions[0]; i++) { @@ -164,6 +166,7 @@ async function startGame(gameID) { case FOOD: increaseSize = true; + score++; break; case SNAKE: @@ -186,6 +189,9 @@ async function startGame(gameID) { } + + // Refresh score + scoreTarget.innerHTML = score; // Redraw screen