From 0634570c60f1dd4ae2d4a10af8061d80b7e5dc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= <89932980@qq.com> Date: Tue, 5 Jan 2016 11:17:49 +0800 Subject: [PATCH] =?UTF-8?q?updated=20=E7=BB=98=E5=88=B6=E5=87=BANPC?= =?UTF-8?q?=E5=BD=A2=E8=B1=A1=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=AF=BB=E5=BE=84?= =?UTF-8?q?=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 35 +++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/game.js b/game.js index 453204a..f1dc44b 100644 --- a/game.js +++ b/game.js @@ -57,6 +57,7 @@ function Game(id,options){ } } }); + e.preventDefault(); }); } _events[eventType]['s'+this.stage.index+'i'+this.index] = callback.bind(this); //绑定作用域 @@ -103,6 +104,68 @@ function Game(id,options){ offset:Math.sqrt(fx*fx+fy*fy) }; }; + //寻址算法 + Map.prototype.finder = function(param){ + var defaults = { + map :this.data, + start:[0,0], + end:[0,0] + }; + var options = (function(target, params) { + for (var prop in params) { + target[prop] = params[prop]; + } + return target; + })(defaults,param); + var result = []; + if(options.map[options.start[0]][options.start[1]]||options.map[options.end[0]][options.end[1]]){ //当起点或终点设置在墙上 + return []; + } + var finded = false; + var length_x = options.map.length; + var steps = new Array(length_x); //步骤的映射 + for(var x=length_x;x--;){ + var length_y = options.map[x].length; + steps[x] = new Array(length_y); + for(var y=length_y;y--;){ + steps[x][y] = 0; + } + } + (function(list){ + var new_list = []; + var next = function(from,to){ + var x = to[0],y = to[1]; + if(typeof steps[x]!= 'undefined'&&typeof steps[x][y] != 'undefined'&&!options.map[x][y]&&!finded){ //当前点是否可以走 + if(x==options.end[0]&&y==options.end[1]){ + steps[x][y] = from; + finded = true; + }else if(!steps[x][y]){ + steps[x][y] = from; + new_list.push(to); + } + } + }; + for(var i=0,len=list.length;i