-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from Surajit0573/Snake_Game
Snake game
- Loading branch information
Showing
10 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
- BLog Website | ||
- Expense tracker | ||
- Word Scramble | ||
- Snake Game | ||
|
||
|
||
<h2>🍰 Contribution Guidelines:</h2> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Snake-Game | ||
Its a basics Javascript snake game using DOM Event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
let food =document.querySelector(".food"); | ||
let snake=document.querySelector(".snake"); | ||
let move=document.querySelector("input"); | ||
let h1=document.querySelector("h1"); | ||
let mh=0; | ||
let mv=0; | ||
let fh=0; | ||
let fv=0; | ||
let count =-1; | ||
move.addEventListener("keydown",function(event){ | ||
if(mv==fv&&mh==fh){ | ||
fv=Math.floor(Math.random()*19)*30; | ||
fh=Math.floor(Math.random()*29)*30; | ||
food.style.marginTop=`${fv}px`; | ||
food.style.marginLeft=`${fh}px`; | ||
count++; | ||
h1.innerText=`SCORE : ${count}`; | ||
} | ||
if(event.code=="ArrowUp"&&mv>0){ | ||
mv-=30; | ||
} | ||
if(event.code=="ArrowDown"&&mv<560){ | ||
mv+=30; | ||
} | ||
if(event.code=="ArrowLeft"&&mh>0){ | ||
mh-=30; | ||
} | ||
if(event.code=="ArrowRight"&&mh<860){ | ||
mh+=30; | ||
} | ||
snake.style.marginTop=`${mv}px`; | ||
snake.style.marginLeft=`${mh}px`; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Snake Game</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="playground"> | ||
|
||
</div> | ||
<div class="snake"></div> | ||
<div class="food"></div> | ||
<div class="score"> | ||
<div class="input">MOVE<input type="text"></div> | ||
<br><br> | ||
<h1>SCORE : 0 </h1> | ||
</div> | ||
|
||
<Script src="app.js"></Script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
*{ | ||
margin: 0px; | ||
padding: 0px; | ||
} | ||
.playground{ | ||
height:600px; | ||
width: 900px; | ||
background-image: url(Assets/grass.jpg); | ||
background-size: cover; | ||
position: absolute; | ||
opacity: 0.8; | ||
} | ||
|
||
.food{ | ||
height: 50px; | ||
width:70px; | ||
background-image: url(Assets/food.png); | ||
background-size: cover; | ||
position: absolute; | ||
} | ||
|
||
.snake{ | ||
height: 60px; | ||
width: 60px; | ||
position: absolute; | ||
background-image: url(Assets/snake.png); | ||
background-size: cover; | ||
position: absolute; | ||
} | ||
.score{ | ||
|
||
height: 300px; | ||
width: 300px; | ||
position: absolute; | ||
margin-left: 903px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters