使用非html5实现js板连连看游戏示例代码(5)


// 拐两次弯搜索
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的资源里下载。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdzjgw.html