浏览代码

Merge branch 'development' of github.com:snaky-particles/snaky-particles into models

Conflicts:
	js/controller.js
Dima Mironov 10 年之前
父节点
当前提交
448cf909ae
共有 4 个文件被更改,包括 26 次插入0 次删除
  1. 二进制
      img/favicon.ico
  2. 二进制
      img/logo.png
  3. 25 0
      js/controller.js
  4. 1 0
      js/models/physicist.js

二进制
img/favicon.ico


二进制
img/logo.png


+ 25 - 0
js/controller.js

@@ -8,6 +8,7 @@ var Controller = function(){
 	this.snake = new Snake(this.initial_length);
 	this.canTurn = true;
 
+	this.counter = 0;
 
 	var pos0 = {x: -1, y: -1};
 	
@@ -49,6 +50,15 @@ Controller.prototype.add_collectible = function(collectible, position){
     this.add_view(new ParticleView(collectible));
 }
 
+Controller.prototype.add_physicist = function(){
+	//var new_physicist = Object.create(this.snake.physicists[this.snake.physicists.length - 1]);
+	var	new_physicist = new Physicist(this, {x: 0, y: 0});//Object.create(physicist.physicist);
+	new_physicist.position = this.snake.physicists[this.snake.physicists.length - 1].position;
+	new_physicist.direction = this.snake.physicists[this.snake.physicists.length - 1].direction;
+	this.snake.physicists.push(new_physicist);
+	this.add_view(new PhysicistView(new_physicist));
+}
+
 Controller.prototype.start_game = function(){
 	// this.session = new Session();
     var c = this;
@@ -134,7 +144,9 @@ Controller.prototype.tick = function(event){
 		var next_cell_content = this.is_position_occupied(next_cell);
 		this.snake.move(next_cell);
 		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();
         }
@@ -241,3 +253,16 @@ var get_random_element_with_probabilities = function(array){
 	}
 	return null;
 }
+
+
+Controller.prototype.physicists_count = function(){
+	if(this.counter >= 1) {
+		this.add_physicist();
+		this.counter = 0;
+	}
+}
+
+Controller.prototype.game_over = function(){
+	alert("Game Over!");
+	// ...
+}

+ 1 - 0
js/models/physicist.js

@@ -10,4 +10,5 @@ Physicist.prototype.collect = function(collectible) {
 	this.bonus += " fat!";
 	controller.score += collectible.points;
 	controller.remove_collectible(collectible);
+	controller.counter += 1;
 };