From 380abb24b02d0bd2ac73a60569b8582b23b8a410 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Mon, 23 Mar 2020 17:39:20 +0100 Subject: [PATCH] Save score --- index.html | 1 + script.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/index.html b/index.html index 91f6199..47b1aa3 100644 --- a/index.html +++ b/index.html @@ -20,6 +20,7 @@

Game

+

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