浏览代码

snake self collision

eraisedtoipi 10 年之前
父节点
当前提交
847c264de0
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      js/controller.js

+ 7 - 1
js/controller.js

@@ -156,6 +156,7 @@ Controller.prototype.tick = function(event){
 		this.canTurn = true;
 		this.physicists_count();
 		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();
         if(this.collectibles.length < this.maximum_spawns){
 		    this.spawn_collectibles();
         }
@@ -265,8 +266,13 @@ var get_random_element_with_probabilities = function(array){
 
 
 Controller.prototype.physicists_count = function(){
-	if(this.counter >= 3) {
+	if(this.counter >= 1) {
 		this.add_physicist();
 		this.counter = 0;
 	}
 }
+
+Controller.prototype.game_over = function(){
+	alert("Game Over!");
+	// ...
+}