-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eabe098
commit 612e4df
Showing
3 changed files
with
248 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>Snake v8</title> | ||
<link rel="stylesheet" type="text/css" href="main.css"/> | ||
</head> | ||
<body> | ||
<div class="container" id="container"> | ||
|
||
</div> | ||
<div class="marker"> | ||
<div class="common points"><p id="printpoint" align="center">0</p></div> | ||
<div class="common distance"><p id="distance" align="center">0</p></div> | ||
</div> | ||
<script src="jscript.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,157 @@ | ||
/** | ||
* Created by Rabi on 5-3-2017. | ||
*/ | ||
var container = document.getElementById("container"); | ||
var buzz=5000; | ||
var sheriff = document.getElementsByClassName("box"); | ||
var oggy; | ||
var xxx=5000; | ||
var dir=39; | ||
var tempDir; | ||
var check1, check2; | ||
var point; | ||
var ran=0; | ||
var pcount = 0; | ||
var points = document.getElementById("printpoint"); | ||
var box_array = new Array(); | ||
var distance = 0; | ||
var i=1; | ||
var rtime = 1000; | ||
var Distance = document.getElementById("distance"); | ||
|
||
var boxes = function() { | ||
var x = ""; | ||
for(var i=1;i<=10000;++i){ | ||
x = x + "<div class=\"box\" id=\"b" + i +" \" ></div>" | ||
} | ||
container.innerHTML = x; | ||
oggy = sheriff[1]; | ||
}; | ||
|
||
boxes(); | ||
|
||
var point = function(){ | ||
sheriff[ran].classList.remove("point"); | ||
ran = Math.random(); | ||
ran= Math.floor(ran*10000); | ||
sheriff[ran].classList.add("point"); | ||
}; | ||
|
||
point(); | ||
|
||
var kill = function(){ | ||
if(oggy.classList.contains("boxed")){ | ||
if(!alert("You have scored "+pcount + " and travelled " +distance+" blocks")) | ||
window.location.reload(); | ||
}; | ||
}; | ||
|
||
|
||
|
||
var mov = function(){ | ||
switch(dir) { | ||
case 37: | ||
if (xxx == buzz) { | ||
--xxx; | ||
|
||
check1 = xxx % 100; | ||
check2 = buzz % 100; | ||
if (check1 == 99 && check2 == 00 || xxx<0) { | ||
xxx=xxx+100; | ||
} | ||
|
||
oggy = sheriff[xxx]; | ||
kill(); | ||
} | ||
oggy.classList.add("boxed"); | ||
buzz = xxx; | ||
break; | ||
case 38: | ||
if (xxx == buzz) { | ||
xxx = xxx - 100; | ||
if (xxx < 0) | ||
xxx = xxx + 10000; | ||
oggy = sheriff[xxx]; | ||
kill(); | ||
} | ||
oggy.classList.add("boxed"); | ||
buzz = xxx; | ||
break; | ||
case 39: | ||
if (xxx == buzz) { | ||
++xxx; | ||
|
||
check1 = xxx % 100; | ||
check2 = buzz % 100; | ||
if (check1 == 00 && check2 == 99) { | ||
xxx=xxx-100; | ||
} | ||
|
||
oggy = sheriff[xxx]; | ||
kill(); | ||
} | ||
oggy.classList.add("boxed"); | ||
buzz = xxx; | ||
break; | ||
case 40: | ||
if (xxx == buzz) { | ||
xxx = xxx + 100; | ||
if (xxx > 9999) | ||
xxx = xxx - 10000; | ||
oggy = sheriff[xxx]; | ||
kill(); | ||
} | ||
oggy.classList.add("boxed"); | ||
buzz = xxx; | ||
break; | ||
default : | ||
break; | ||
} | ||
|
||
distance++ | ||
box_array[distance] = oggy; | ||
Distance.innerHTML = distance; | ||
|
||
setTimeout(function(){ | ||
box_array[i].className = "box"; | ||
i++; | ||
},rtime); | ||
|
||
if(buzz == ran){ | ||
rtime += 50; | ||
pcount++; | ||
points.innerHTML = pcount; | ||
point(); | ||
} | ||
}; | ||
|
||
interval = setInterval(mov, 50); | ||
|
||
var direction = function(e){ | ||
tempDir = e['keyCode']; | ||
switch (tempDir) { | ||
case 37: | ||
if (dir != 39) | ||
dir = tempDir; | ||
break; | ||
case 38: | ||
if (dir != 40) | ||
dir = tempDir; | ||
break; | ||
case 39: | ||
if (dir != 37) | ||
dir = tempDir; | ||
break; | ||
case 40: | ||
if (dir != 38) | ||
dir = tempDir; | ||
break; | ||
default : | ||
break; | ||
} | ||
}; | ||
|
||
interval; | ||
|
||
addEventListener('keydown',direction); | ||
|
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,73 @@ | ||
body{ | ||
background-color: darkslategrey; | ||
} | ||
|
||
.container{ | ||
width: 500px; | ||
height: 500px; | ||
margin: 30px auto; | ||
margin-bottom: 10px; | ||
background-color: #0c1021; | ||
|
||
padding: 0px; | ||
border: solid 10px slategrey; | ||
border-radius: 10px; | ||
|
||
-webkit-box-shadow: 0px 0px 20px 3px rgba(0,0,0,0.6); | ||
-moz-box-shadow: 0px 0px 20px 3px rgba(0,0,0,0.6); | ||
box-shadow: 0px 0px 20px 3px rgba(0,0,0,0.6); | ||
} | ||
|
||
.box{ | ||
width: 5px; | ||
height: 5px; | ||
border-radius: 10px; | ||
display: inline-block; | ||
float: left; | ||
} | ||
|
||
.boxed{ | ||
background-color: #fd6401; | ||
box-shadow: 0 0 5px #fd6401; | ||
} | ||
|
||
.point{ | ||
background-color: #68e768; | ||
} | ||
|
||
.common{ | ||
height: 30px; | ||
width: 200px; | ||
margin: auto; | ||
border-radius: 10px; | ||
border: solid 5px slategrey; | ||
color: dimgray; | ||
display: inline-block; | ||
|
||
background-color: #0C1021; | ||
-webkit-box-shadow: 0px 0px 20px 3px rgba(0,0,0,0.6); | ||
-moz-box-shadow: 0px 0px 20px 3px rgba(0,0,0,0.6); | ||
box-shadow: 0px 0px 20px 3px rgba(0,0,0,0.6); | ||
} | ||
|
||
#printpoint,#distance{ | ||
height: 30px; | ||
margin: 0px; | ||
font-size: 20px; | ||
font-family: cursive; | ||
padding: 0px 0px 0px 0px; | ||
} | ||
|
||
.points{ | ||
position: relative; | ||
left: 440px; | ||
margin: 5px; | ||
float: left; | ||
} | ||
|
||
.distance{ | ||
position: relative; | ||
right: 440px; | ||
margin: 5px; | ||
float:right; | ||
} |