Save score
This commit is contained in:
parent
4aa6e5b2f1
commit
380abb24b0
@ -20,6 +20,7 @@
|
||||
|
||||
<div id="gameScreen">
|
||||
<h1>Game</h1>
|
||||
<p>Score: <span id="scoreTarget"></span></p>
|
||||
|
||||
<div id="canvasTarget"></div>
|
||||
|
||||
|
@ -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:
|
||||
@ -187,6 +190,9 @@ async function startGame(gameID) {
|
||||
|
||||
|
||||
|
||||
// Refresh score
|
||||
scoreTarget.innerHTML = score;
|
||||
|
||||
|
||||
// Redraw screen
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
||||
|
Loading…
Reference in New Issue
Block a user