Skip to content

Commit 8b81f84

Browse files
Merge pull request Dezenix#397 from iamrahulmahato/mole
Mole Attack Game
2 parents 8e56a3b + e8d5134 commit 8b81f84

File tree

7 files changed

+156
-0
lines changed

7 files changed

+156
-0
lines changed

Mole Attack/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<p align="center">
2+
<img alt="" height="80" src="./img/256px-Icon-notepad.svg.png">
3+
</a>
4+
</p>
5+
<h1 align="center">Mole Attack</h1>
6+
7+
<div align="center">
8+
Attack mole to gain points
9+
</div>
10+
11+
12+
13+
## Description:
14+
Mole Attack is a game where you have to attack the mole to gain points
15+
16+
---
17+
18+
## Tech Stack Used:
19+
HTML5,CSS3,JavaScript
20+
21+
---
22+
23+
## It Look's Like:
24+
25+
![image](./img/Screenshot%202022-05-30%20075521.png)
26+
27+
---
28+
29+
30+
## **Quick Start**
31+
- Clone this repository
32+
33+
```
34+
git clone https://github.com/Dezenix/frontend-html-css-js
35+
```
36+
- Change Directory
37+
38+
```
39+
cd Change Mole Attack
40+
```
41+
42+
```
43+
cd index.html
44+
```
45+
> open ```index.html``` file in your default Browser.
46+
---
47+
## **Installation and Dependencies**
48+
- Install any Code Editors like : VS Code, Atom, etc.
49+
- Then follow the ```Quick Start``` steps given above and open the
50+
Change Mole Attack in your Code Editor.
51+
- Then open ```index.html``` file then edit and save it .

Mole Attack/css/style.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.body {
2+
background-color: aqua;
3+
}
4+
5+
.grid {
6+
width: 606px;
7+
height: 606px;
8+
display: flex;
9+
flex-wrap: wrap;
10+
}
11+
12+
.square {
13+
height: 200px;
14+
width: 200px;
15+
border: solid black 1px;
16+
}
17+
18+
.mole {
19+
background-image: url("../img/mole.jpg");
20+
background-size: cover;
21+
}
18.6 KB
Loading
17.5 KB
Loading

Mole Attack/img/mole.jpg

8.72 KB
Loading

Mole Attack/index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!doctype html>
2+
3+
<html lang="en">
4+
5+
<head>
6+
<meta charset="utf-8">
7+
<title>mole attack</title>
8+
<link rel="stylesheet" href="./css/style.css">
9+
</head>
10+
11+
<body>
12+
13+
<h2>Your score:</h2>
14+
<h2 id="score">0</h2>
15+
16+
<h2>Time Left:</h2>
17+
<h2 id="time-left">60</h2>
18+
19+
<div class="grid">
20+
<div class="square" id="1"></div>
21+
<div class="square" id="2"></div>
22+
<div class="square" id="3"></div>
23+
<div class="square" id="4"></div>
24+
<div class="square" id="5"></div>
25+
<div class="square" id="6"></div>
26+
<div class="square" id="7"></div>
27+
<div class="square" id="8"></div>
28+
<div class="square" id="9"></div>
29+
</div>
30+
31+
<script src="./js/script.js"></script>
32+
</body>
33+
34+
</html>

Mole Attack/js/script.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const squares = document.querySelectorAll('.square')
2+
const mole = document.querySelector('.mole')
3+
const timeLeft = document.querySelector('#time-left')
4+
const score = document.querySelector('#score')
5+
6+
let result = 0
7+
let hitPosition
8+
let currentTime = 60
9+
let timerId = null
10+
11+
function randomSquare() {
12+
squares.forEach(square => {
13+
square.classList.remove('mole')
14+
})
15+
16+
let randomSquare = squares[Math.floor(Math.random() * 9)]
17+
randomSquare.classList.add('mole')
18+
19+
hitPosition = randomSquare.id
20+
}
21+
22+
squares.forEach(square => {
23+
square.addEventListener('mousedown', () => {
24+
if (square.id == hitPosition) {
25+
result++
26+
score.textContent = result
27+
hitPosition = null
28+
}
29+
})
30+
})
31+
32+
function moveMole() {
33+
timerId = setInterval(randomSquare, 500)
34+
}
35+
36+
moveMole()
37+
38+
function countDown() {
39+
currentTime--
40+
timeLeft.textContent = currentTime
41+
42+
if (currentTime == 0) {
43+
clearInterval(countDownTimerId)
44+
clearInterval(timerId)
45+
alert('GAME OVER! Your final score is ' + result)
46+
}
47+
48+
}
49+
50+
let countDownTimerId = setInterval(countDown, 1000)

0 commit comments

Comments
 (0)