// 拐两次弯搜索
isReach2 : function(piece) {
// 沿x轴正向搜索
for (var i = this.x + 1; i < 17; i ++) {
if (!this.game.pieceMap.get(i + "," + this.y).isPass()) {
this.game.trackList = [];
break;
} else if (this.game.pieceMap.get(i + "," + this.y).isReach(piece)
&& this.game.pieceMap.get(i + "," + this.y).isPass()) {
this.game.trackList.push(this.game.pieceMap.get(i + "," + this.y));
return true;
}
}
// 沿x轴搜索
for (var i = this.x - 1; i >= 0; i --) {
if (!this.game.pieceMap.get(i + "," + this.y).isPass()) {
this.game.trackList = [];
break;
} else if (this.game.pieceMap.get(i + "," + this.y).isReach(piece)
&& this.game.pieceMap.get(i + "," + this.y).isPass()) {
this.game.trackList.push(this.game.pieceMap.get(i + "," + this.y));
return true;
}
}
// 沿y轴搜索
for (var i = this.y - 1; i >= 0; i --) {
if (!this.game.pieceMap.get(this.x + "," + i).isPass()) {
this.game.trackList = [];
break;
} else if (this.game.pieceMap.get(this.x + "," + i).isReach(piece)
&& this.game.pieceMap.get(this.x + "," + i).isPass()) {
this.game.trackList.push(this.game.pieceMap.get(this.x + "," + i));
return true;
}
}
// 沿y轴正向搜索
for (var i = this.y + 1; i < 12; i ++) {
if (!this.game.pieceMap.get(this.x + "," + i).isPass()) {
this.game.trackList = [];
break;
} else if (this.game.pieceMap.get(this.x + "," + i).isReach(piece)
&& this.game.pieceMap.get(this.x + "," + i).isPass()) {
this.game.trackList.push(this.game.pieceMap.get(this.x + "," + i));
return true;
}
}
return false;
},
该函数以点击的图片为中心分别沿x轴,y轴展开搜索。
以上是本游戏代码的全部内容。具体游戏源码请到CSDN中zhangjinpeng66的资源里下载。
您可能感兴趣的文章: