Save score

This commit is contained in:
Pierre HUBERT 2020-03-23 17:39:20 +01:00
parent 4aa6e5b2f1
commit 380abb24b0
2 changed files with 7 additions and 0 deletions

View File

@ -20,6 +20,7 @@
<div id="gameScreen">
<h1>Game</h1>
<p>Score: <span id="scoreTarget"></span></p>
<div id="canvasTarget"></div>

View File

@ -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