Snake fix
This commit is contained in:
parent
7c58cc32a8
commit
1ee29ac8cf
31
js/snake.js
31
js/snake.js
@ -1,33 +1,34 @@
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
console.log("DOM fully loaded and parsed");
|
||||
$(document).ready(function() {
|
||||
console.log("ready");
|
||||
var snake = $("#snake");
|
||||
var fruit = $("#fruit");
|
||||
|
||||
function drawFruit(){
|
||||
var xFruit = Math.floor((Math.random()*10) +1);
|
||||
var yFruit = Math.floor((Math.random()*10) +1);
|
||||
var xFruit = Math.floor((Math.random()*10)+1)*4;
|
||||
var yFruit = Math.floor((Math.random()*10)+1)*4;
|
||||
var positionFruit = [xFruit,yFruit];
|
||||
return positionFruit;
|
||||
}
|
||||
function startGame(){
|
||||
var myVar = setInterval(moveSnake(),1000);
|
||||
}
|
||||
function moveSnake(){
|
||||
|
||||
|
||||
snake.css({
|
||||
'left' : "+=1rem",
|
||||
})
|
||||
}
|
||||
snake.css({
|
||||
'left' : "+=1rem",
|
||||
})
|
||||
}
|
||||
newPositionFruit = drawFruit();
|
||||
function startGame(){
|
||||
var myVar = setInterval(moveSnake(),3000);
|
||||
}
|
||||
|
||||
for(var i = 0; i !==5; i++){
|
||||
startGame();
|
||||
}
|
||||
var newPositionFruit = drawFruit();
|
||||
|
||||
fruit.css({
|
||||
'left': newPositionFruit[0] + 'rem',
|
||||
'top': newPositionFruit[1] + 'rem',
|
||||
})
|
||||
|
||||
moveSnake();
|
||||
// moveSnake();
|
||||
})
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user