From e46a555705ffa78d201c1be25b2efc6b7fe7025c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 13 Apr 2017 17:44:01 +0300 Subject: [PATCH] adde ages to events to keep score... Signed-off-by: Alex A. Naanou --- simplesnake/simplesnake.appcache | 2 +- simplesnake/simplesnake.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/simplesnake/simplesnake.appcache b/simplesnake/simplesnake.appcache index a6551e9..ef27606 100755 --- a/simplesnake/simplesnake.appcache +++ b/simplesnake/simplesnake.appcache @@ -2,6 +2,6 @@ CACHE MANIFEST # Last Modified: 2017 Apr 13 CACHE: +simplesnake.html simplesnake.css simplesnake.js -simplesnake.html diff --git a/simplesnake/simplesnake.js b/simplesnake/simplesnake.js index 9928833..f7eb8fc 100755 --- a/simplesnake/simplesnake.js +++ b/simplesnake/simplesnake.js @@ -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) })