From 5542879906f79d1908c49ccabd78e77920312942 Mon Sep 17 00:00:00 2001 From: Ritabrata Dey Date: Tue, 14 May 2024 08:23:07 +0530 Subject: [PATCH] updated Whack-A-Mole game whack a mole game enhancement , added a speed slider and change typos in name --- Games/Whack_a_Mole/index.html | 11 ++++++++--- Games/Whack_a_Mole/mole.js | 16 +++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Games/Whack_a_Mole/index.html b/Games/Whack_a_Mole/index.html index 26cbe0e710..9a7fd0effe 100644 --- a/Games/Whack_a_Mole/index.html +++ b/Games/Whack_a_Mole/index.html @@ -3,13 +3,18 @@ - Whac a Mole + Whack a Mole -

Whac a Mole

-

0

+

Whack a Mole

+

Score:

0

+
+ + +
+  
diff --git a/Games/Whack_a_Mole/mole.js b/Games/Whack_a_Mole/mole.js index f5752204e6..9f7c2fa582 100644 --- a/Games/Whack_a_Mole/mole.js +++ b/Games/Whack_a_Mole/mole.js @@ -4,9 +4,12 @@ let score = 0; let gameOver = false; let moleIntervalId; let plantIntervalId; - +let speed = 2500; window.onload = function() { setGame(); + document.getElementById('speed-slider').addEventListener('input',()=>{ + speed = 3000 - parseInt(document.getElementById('speed-slider').value)*500; + }); } function setGame() { @@ -18,8 +21,8 @@ function setGame() { tile.addEventListener("click", selectTile); document.getElementById("board").appendChild(tile); } - setInterval(setMole, 2500); // 1000 miliseconds = 1 second, every 1 second call setMole - setInterval(setPlant, 5000); // 2000 miliseconds = 2 seconds, every 2 second call setPlant + setInterval(setMole, speed); // 1000 miliseconds = 1 second, every 1 second call setMole + setInterval(setPlant, 2000); // 2000 miliseconds = 2 seconds, every 2 second call setPlant } function getRandomTile() { @@ -82,6 +85,9 @@ function selectTile() { window.onload = function() { setGame(); document.querySelector('.start-btn').addEventListener('click', startNewGame); + document.getElementById('speed-slider').addEventListener('input',()=>{ + speed = 3000 - parseInt(document.getElementById('speed-slider').value)*500; + }); } function setGame() { @@ -97,8 +103,8 @@ function setGame() { function startNewGame() { resetGame(); - moleIntervalId = setInterval(setMole, 2500); // 1000 miliseconds = 1 second, every 1 second call setMole - plantIntervalId = setInterval(setPlant, 5000); // 2000 miliseconds = 2 seconds, every 2 second call setPlant + moleIntervalId = setInterval(setMole, speed); // 1000 miliseconds = 1 second, every 1 second call setMole + plantIntervalId = setInterval(setPlant, 2000); // 2000 miliseconds = 2 seconds, every 2 second call setPlant } function resetGame() {