浏览代码

better while

Dima Mironov 10 年之前
父节点
当前提交
668544a856
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      js/controller.js

+ 3 - 1
js/controller.js

@@ -148,9 +148,11 @@ Controller.prototype.tick = function(event){
 		this.snake.move(next_cell);
 		this.canTurn = true;
 		this.physicists_count();
-		while (var next_cell_content = this.is_position_occupied(next_cell)){
+		var next_cell_content  = this.is_position_occupied(next_cell);
+		while (next_cell_content){
 			if (next_cell_content && next_cell_content.collectible) this.snake.physicists[0].collect(next_cell_content.collectible);
 			if (next_cell_content && next_cell_content.physicist && event.time > 5000) this.game_over();
+			next_cell_content = this.is_position_occupied(next_cell);
 		}
         if(this.collectibles.length < this.maximum_spawns){
 		    this.spawn_collectibles();