Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new game Whack a mole #4477

Merged
merged 10 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,25 @@ 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) |
1911aditi marked this conversation as resolved.
Show resolved Hide resolved
| [Snake](https://github.com/kunjgit/GameZone/tree/main/Games/snake)                |
1911aditi marked this conversation as resolved.
Show resolved Hide resolved
| [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) |
1911aditi marked this conversation as resolved.
Show resolved Hide resolved
| [Snake](https://github.com/kunjgit/GameZone/tree/main/Games/snake)                |
1911aditi marked this conversation as resolved.
Show resolved Hide resolved



|[Lunar Lander](https://github.com/kunjgit/GameZone/tree/main/Games/Lunar_Lander)|
|[AquaSort_Game](https://github.com/kunjgit/GameZone/tree/main/Games/AquaSort_Game) |
|[Chess_Game_computer](https://github.com/kunjgit/GameZone/tree/main/Games/Chess_Game_computer) |
|[Turn_on_the_light](https://github.com/kunjgit/GameZone/tree/main/Games/Turn_on_the_light) |
|[AquaSort_Game](https://github.com/kunjgit/GameZone/tree/main/Games/AquaSort_Game) |
| [Snake](https://github.com/kunjgit/GameZone/tree/main/Games/snake)                |
| [Tetris Game](https://github.com/kunjgit/GameZone/tree/main/Games/tetris_game)|

|[Chess_Game_computer](https://github.com/kunjgit/GameZone/tree/main/Games/Chess_Game_computer) |
|[Turn_on_the_light](https://github.com/kunjgit/GameZone/tree/main/Games/Turn_on_the_light) |
| [Tic-Tac-Toe Game](https://github.com/kunjgit/GameZone/tree/main/Games/Tic-Tac-Toe) |
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.