Skip to content

Commit

Permalink
updated the bombs to appear wrt time and updated the lives section
Browse files Browse the repository at this point in the history
  • Loading branch information
SoumyadevSaha committed Oct 26, 2023
1 parent 895c901 commit d9bd076
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function starting() {
document.getElementById("back-icon").style.display = "block";
}

// function maintaining the game time
// function maintaining the game time (also acts as main loop for the game)
function decreaseTime() {
let m = Math.floor(seconds / 60);
let s = seconds % 60;
Expand All @@ -205,6 +205,15 @@ function decreaseTime() {
// ---------- displaying total lives -------------
timeEl.innerHTML = `Time: ${m}:${s} <hr> ${_lives}`;

// -------------- bomb management section ----------------
if (totalBombs < MAX_BOMBS) { // check if there are already more than enough bombs present on screen
if (Math.random() < 0.5) { // randomly decide whether to create a bomb or not
createBomb();
totalBombs++;
}
}
// -------------- bomb management section ----------------

// -------------- game over section ----------------
if ((s == 0 && m == 0) || lives == 0) {
gameOver();
Expand All @@ -230,15 +239,6 @@ function createEdible() {

edible.addEventListener("click", catchEdible);
game_container.appendChild(edible);

// -------------- bomb management section ----------------
if (totalBombs < MAX_BOMBS) { // check if there are already more than enough bombs present on screen
if (Math.random() < 0.5) { // randomly decide whether to create a bomb or not
createBomb();
totalBombs++;
}
}
// -------------- bomb management section ----------------
}
}

Expand Down

0 comments on commit d9bd076

Please sign in to comment.