mirror of
https://github.com/flynx/Slang.git
synced 2025-10-29 18:50:08 +00:00
adde ages to events to keep score...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
721f68eead
commit
e46a555705
@ -2,6 +2,6 @@ CACHE MANIFEST
|
|||||||
# Last Modified: 2017 Apr 13
|
# Last Modified: 2017 Apr 13
|
||||||
|
|
||||||
CACHE:
|
CACHE:
|
||||||
|
simplesnake.html
|
||||||
simplesnake.css
|
simplesnake.css
|
||||||
simplesnake.js
|
simplesnake.js
|
||||||
simplesnake.html
|
|
||||||
|
|||||||
@ -182,15 +182,15 @@ var Snake = {
|
|||||||
// NOTE: we are not deleteing .direction here as
|
// NOTE: we are not deleteing .direction here as
|
||||||
// we can have upto 4 snakes colliding...
|
// we can have upto 4 snakes colliding...
|
||||||
next.direction = ''
|
next.direction = ''
|
||||||
|
that.snakeKilled(other, next.age+1)
|
||||||
|
that.snakeKilled(color, age+2)
|
||||||
delete next.age
|
delete next.age
|
||||||
that.snakeKilled(other)
|
|
||||||
that.snakeKilled(color)
|
|
||||||
|
|
||||||
// apple -> increment age...
|
// apple -> increment age...
|
||||||
} else if(next.style.backgroundColor == that.config.apple_color){
|
} else if(next.style.backgroundColor == that.config.apple_color){
|
||||||
age += 1
|
age += 1
|
||||||
move = true
|
move = true
|
||||||
that.appleEaten()
|
that.appleEaten(color, age+2)
|
||||||
|
|
||||||
// empty -> just move...
|
// empty -> just move...
|
||||||
} else if(next.style.backgroundColor == ''){
|
} else if(next.style.backgroundColor == ''){
|
||||||
@ -199,7 +199,7 @@ var Snake = {
|
|||||||
// other -> kill...
|
// other -> kill...
|
||||||
// NOTE: anything but an apple or empty will kill the snake...
|
// NOTE: anything but an apple or empty will kill the snake...
|
||||||
} else {
|
} else {
|
||||||
that.snakeKilled(color)
|
that.snakeKilled(color, age+2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the move...
|
// do the move...
|
||||||
@ -384,12 +384,17 @@ function setup(snake, timer, size){
|
|||||||
.pause()
|
.pause()
|
||||||
|
|
||||||
// stuff...
|
// stuff...
|
||||||
.appleEaten(function(){ this.apple() })
|
.appleEaten(function(color, age){
|
||||||
|
// XXX show score...
|
||||||
|
console.log(`Apple eaten by: ${color}: ${age}`)
|
||||||
|
this.apple()
|
||||||
|
})
|
||||||
.apple()
|
.apple()
|
||||||
.apple()
|
.apple()
|
||||||
|
|
||||||
// players...
|
// players...
|
||||||
.snakeKilled(function(color){
|
.snakeKilled(function(color, age){
|
||||||
|
console.log(`Killed: ${color}: ${age}`)
|
||||||
this
|
this
|
||||||
.pause()
|
.pause()
|
||||||
.snake(color, 3) })
|
.snake(color, 3) })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user