Skip to content

Commit

Permalink
Merge pull request #118 from Surajit0573/Snake_Game
Browse files Browse the repository at this point in the history
Snake game
  • Loading branch information
shrey141102 authored Dec 11, 2023
2 parents e86096f + dfa6dce commit c3d443c
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- BLog Website
- Expense tracker
- Word Scramble
- Snake Game


<h2>🍰 Contribution Guidelines:</h2>
Expand Down
Binary file added Snake_Game/Assets/food.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 Snake_Game/Assets/grass.jpg
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 Snake_Game/Assets/preview.jpg
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 Snake_Game/Assets/snake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Snake_Game/README.md
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
33 changes: 33 additions & 0 deletions Snake_Game/app.js
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`;
});
23 changes: 23 additions & 0 deletions Snake_Game/index.html
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>
62 changes: 62 additions & 0 deletions Snake_Game/style.css
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;
}






















8 changes: 8 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,21 @@ const projects = [
link: "./Word Scramble/index.html",
image: "https://dictionary.cambridge.org/external/images/wordscramble-og-image.png"
},
{
title: "Snake Game",
discription:
"Its a basics Javascript snake game using DOM Event.",
link: "./Snake_Game/index.html",
image: "https://w7.pngwing.com/pngs/543/374/png-transparent-snake-2000-classic-nokia-game-slither-worm-snake-a-classic-snake-game-classic-game-snake-ii-snake-food-animals-grass-thumbnail.png"
},
{
title: "Sudoku Game",
discription:
"Sudoku Game game made using HTML, CSS and JS",
link: "./Sudoku Game/index.html",
image: "./Sudoku Game/bozhin-karaivanov-yqcWOAHH1Rs-unsplash.jpg"
}

];

const cards = document.getElementsByClassName("cards");
Expand Down

0 comments on commit c3d443c

Please sign in to comment.