Skip to content

Commit

Permalink
Merge pull request #4477 from 1911aditi/main
Browse files Browse the repository at this point in the history
added new game Whack a mole
  • Loading branch information
kunjgit authored Jun 21, 2024
2 parents 112f9ac + 245ef33 commit 590c313
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
Empty file added Games/whack a mole/README.md
Empty file.
27 changes: 27 additions & 0 deletions Games/whack a mole/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Whack-a-Mole</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="game-container">
<div class="hole" id="hole1"></div>
<div class="hole" id="hole2"></div>
<div class="hole" id="hole3"></div>
<div class="hole" id="hole4"></div>
<div class="hole" id="hole5"></div>
<div class="hole" id="hole6"></div>
<div class="hole" id="hole7"></div>
<div class="hole" id="hole8"></div>
<div class="hole" id="hole9"></div>
</div>
<div id="scoreboard">
<div id="score">Score: 0</div>
<div id="timer">Time: 30</div>
</div>
<script src="script.js"></script>
</body>
</html>
47 changes: 47 additions & 0 deletions Games/whack a mole/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
let score = 0;
let timeLeft = 30;
let timerId;
let moleTimerId;
const scoreDisplay = document.getElementById('score');
const timerDisplay = document.getElementById('timer');
const holes = document.querySelectorAll('.hole');

function randomHole() {
const index = Math.floor(Math.random() * holes.length);
return holes[index];
}

function showMole() {
const hole = randomHole();
const mole = document.createElement('div');
mole.classList.add('mole');
hole.appendChild(mole);

mole.addEventListener('click', () => {
score++;
scoreDisplay.textContent = `Score: ${score}`;
hole.removeChild(mole);
});

setTimeout(() => {
if (hole.contains(mole)) {
hole.removeChild(mole);
}
}, 1000);
}

function startGame() {
timerId = setInterval(() => {
timeLeft--;
timerDisplay.textContent = `Time: ${timeLeft}`;
if (timeLeft === 0) {
clearInterval(timerId);
clearInterval(moleTimerId);
alert(`Game Over! Your score is ${score}`);
}
}, 1000);

moleTimerId = setInterval(showMole, 800);
}

startGame();
47 changes: 47 additions & 0 deletions Games/whack a mole/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}

#game-container {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-template-rows: repeat(3, 100px);
gap: 10px;
margin-bottom: 20px;
}

.hole {
width: 100px;
height: 100px;
background-color: #8B4513;
position: relative;
cursor: pointer;
}

.mole {
width: 60px;
height: 60px;
background-color: #000;
border-radius: 50%;
position: absolute;
top: 20px;
left: 20px;
}

#scoreboard {
display: flex;
justify-content: space-between;
width: 300px;
font-size: 24px;
}

#score, #timer {
margin: 0;
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,11 @@ This repository also provides one such platforms where contributers come over an
| [Sudoku_light_theme](https://github.com/kunjgit/GameZone/tree/main/Games/Sudoku_light_theme) |
| [Find_the_ball](https://github.com/kunjgit/GameZone/tree/main/Games/Find_the_ball) |
|[Color The Page](https://github.com/kunjgit/GameZone/tree/main/Games/Color_The_Page)|
|[AquaSort_Game](https://github.com/kunjgit/GameZone/tree/main/Games/AquaSort_Game) |
| [Snake](https://github.com/kunjgit/GameZone/tree/main/Games/snake)                |
| [whack a mole](https://github.com/kunjgit/GameZone/tree/main/Games/whack%20a%20mole) |
|[AquaSort_Game](https://github.com/kunjgit/GameZone/tree/main/Games/AquaSort_Game) |
| [Snake](https://github.com/kunjgit/GameZone/tree/main/Games/snake)                |
| [Dice_Game] (https://github.com/shivan2004/GameZone/tree/main/Games/Dice_Game)|
|[HitOrMiss](https://github.com/kunjgit/GameZone/tree/main/Games/HitOrMiss)|
|[Lunar Lander](https://github.com/kunjgit/GameZone/tree/main/Games/Lunar_Lander)|
Expand Down Expand Up @@ -803,7 +808,9 @@ This repository also provides one such platforms where contributers come over an
| [Go-fish-master](https://github.com/kunjgit/GameZone/tree/main/Games/Go-fish-master) |
|[Pottery-Game](https://github.com/kunjgit/GameZone/tree/main/Games/Pottery-Game)|
| [Ganesh QR Maker](https://github.com/kunjgit/GameZone/tree/main/Games/Ganesh_QR_Maker) |

| [Ganesh_QR_Maker](https://github.com/kunjgit/GameZone/tree/main/Games/Ganesh_QR_Maker) |

|[Wheel_of_Fortunes](https://github.com/Saipradyumnagoud/GameZone/tree/main/Games/Wheel_of_Fortunes)|
|[Tic-tac-toe](https://github.com/Saipradyumnagoud/GameZone/tree/main/Games/Tic-tac-toe)|
|[Quest_For_Riches](https://github.com/kunjgit/GameZone/tree/main/Games/Quest_For_Riches)|
Expand Down
Binary file added assets/images/whack a mole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/whack a mole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 590c313

Please sign in to comment.