adde ages to events to keep score...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-04-13 17:44:01 +03:00
parent 721f68eead
commit e46a555705
2 changed files with 12 additions and 7 deletions

View File

@ -2,6 +2,6 @@ CACHE MANIFEST
# Last Modified: 2017 Apr 13
CACHE:
simplesnake.html
simplesnake.css
simplesnake.js
simplesnake.html

View File

@ -182,15 +182,15 @@ var Snake = {
// NOTE: we are not deleteing .direction here as
// we can have upto 4 snakes colliding...
next.direction = ''
that.snakeKilled(other, next.age+1)
that.snakeKilled(color, age+2)
delete next.age
that.snakeKilled(other)
that.snakeKilled(color)
// apple -> increment age...
} else if(next.style.backgroundColor == that.config.apple_color){
age += 1
move = true
that.appleEaten()
that.appleEaten(color, age+2)
// empty -> just move...
} else if(next.style.backgroundColor == ''){
@ -199,7 +199,7 @@ var Snake = {
// other -> kill...
// NOTE: anything but an apple or empty will kill the snake...
} else {
that.snakeKilled(color)
that.snakeKilled(color, age+2)
}
// do the move...
@ -384,12 +384,17 @@ function setup(snake, timer, size){
.pause()
// stuff...
.appleEaten(function(){ this.apple() })
.appleEaten(function(color, age){
// XXX show score...
console.log(`Apple eaten by: ${color}: ${age}`)
this.apple()
})
.apple()
.apple()
// players...
.snakeKilled(function(color){
.snakeKilled(function(color, age){
console.log(`Killed: ${color}: ${age}`)
this
.pause()
.snake(color, 3) })