Skip to content

Commit

Permalink
make score appear on screen on all times, update its content, clean i…
Browse files Browse the repository at this point in the history
…t on gameover
  • Loading branch information
mariamagneu committed Jun 19, 2024
1 parent 4ba6946 commit 966ca87
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</head>
<body>
<div class="container">
<div id="score">Your Score = 0 </div>

<section id="start-screen">
<nav>
<button id="record-log">local record-log</button>
Expand Down
7 changes: 6 additions & 1 deletion js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ class Game {
if (this.player.didCollideFood(currentFood)) {
//increase score

this.score++;
const score = document.querySelector("#score");
this.score = this.score + 20;
score.innerHTML = `Your Score = ${this.score}`;

console.log(this.score);

//make food dissapear (remove from array & dom)
Expand All @@ -96,6 +99,8 @@ class Game {
this.foods.forEach((currentFood, index) => {
currentFood.destroy();
this.foods.splice(index, 1);
const score = document.querySelector("#score");
score.innerHTML = `Your Score = 0`;
});
}
}, 200);
Expand Down
5 changes: 4 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ h1 {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
#score {
padding: 10px 5px;
}

.all-buttons {
display: flex;
flex-direction: column;
Expand Down

0 comments on commit 966ca87

Please sign in to comment.