File tree Expand file tree Collapse file tree 7 files changed +156
-0
lines changed Expand file tree Collapse file tree 7 files changed +156
-0
lines changed Original file line number Diff line number Diff line change
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 .
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments