mirror of
https://github.com/flynx/Course-JavaScript.git
synced 2025-10-29 19:10:09 +00:00
cleanup and notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
dc0d0f1e11
commit
61aae0a112
@ -25,6 +25,9 @@ var Snake = {
|
|||||||
_field: null,
|
_field: null,
|
||||||
_cells: null,
|
_cells: null,
|
||||||
|
|
||||||
|
// XXX BUG: going down into bottom left corner breaks the snake...
|
||||||
|
// ...check other corner cases!
|
||||||
|
// ...looks like the only corner case...
|
||||||
_tick: function(){
|
_tick: function(){
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
@ -81,15 +84,18 @@ var Snake = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// apples...
|
// apples...
|
||||||
|
// XXX TEST
|
||||||
var age = cell.age
|
var age = cell.age
|
||||||
if(next.style.backgroundColor == that.config.apple_color){
|
if(next.style.backgroundColor == that.config.apple_color){
|
||||||
age += 1
|
age += 1
|
||||||
|
|
||||||
// special case: other snake's head -- kill both...
|
// special case: other snake's head -- kill both...
|
||||||
|
// XXX TEST
|
||||||
} else if(next.direction){
|
} else if(next.direction){
|
||||||
next.style.backgroundColor = ''
|
next.style.backgroundColor = ''
|
||||||
// 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 = ''
|
||||||
delete next.age
|
delete next.age
|
||||||
|
|
||||||
// empty...
|
// empty...
|
||||||
@ -125,7 +131,7 @@ var Snake = {
|
|||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
player: function(color, x, y, direction, age){
|
snake: function(color, x, y, direction, age){
|
||||||
var head = this._cells[x + y * this.field_size.width]
|
var head = this._cells[x + y * this.field_size.width]
|
||||||
|
|
||||||
head.style.backgroundColor = color
|
head.style.backgroundColor = color
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user