码迷,mamicode.com
首页 > 其他好文 > 详细

团队-象棋游戏3-模块开发过程

时间:2017-10-27 01:39:25      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:问题   zha   遇到   over   项目   selector   turn   实现   开发   

项目托管平台地址:https://gitee.com/zhanghongjian666/ZhongGuoXiangQi/blob/0156ad731ab887b252ada203757058ba78b029e4/zgxq.html
开发模块功能:
棋子加载功能,开发时间:10天(小时),实现棋子的加载,
实现过程是
var QiZi = function (qipan, r, c, text, isred) {
this.text = text;
this.isred = isred;
this.ctx = qipan.ctx;
this.qipan = qipan;
this.r = r;
this.c = c;
 
 
this.draw();
var that = this, maxR = that.qipan.maxR, maxC = that.qipan.maxC;
this.checkstep = (function () {
 
 
if (text == "兵" || text == "卒") {
if (that.r > 4) {
 
 
return function (r, c) {
return this.r > 4 && (this.r - 1) == r && this.c == c
|| this.r <= 4 && this.r == r && ((this.c - 1) == c || (this.c + 1) == c)
|| this.r <= 4 && (this.r - 1) == r && this.c == c;
}
 
 
} else {
return function (r, c) {
return this.r < 5 && (this.r + 1) == r && this.c == c || this.r >= 5 && this.r == r && ((this.c - 1) == c || (this.c + 1) == c) || this.r >= 5 && (this.r + 1) == r && this.c == c;
}
}
 
 
} else if (text == "炮") {
return function (r, c) {
if (this.r != r && this.c != c) {
return false;
}
var bodys = this.qipan.bodys, step = this.getMoveRange(r, c);
 
 
return bodys[r][c].qizi != null && step == 1 || bodys[r][c].qizi == null && step == 0;
 
 
}
} else if (text == "车" || text == "車") {
return function (r, c) {
if (this.r != r && this.c != c) {
return false;
}
return this.getMoveRange(r, c) == 0;
 
 
}
} else if (text == "马" || text == "馬") {
return function (r, c) {
 
 
return this.r - 2 == r && this.c - 1 == c && this.isEnemyOrEmpty(this.r - 1, this.c)
|| this.r - 2 == r && this.c + 1 == c && this.isEnemyOrEmpty(this.r - 1, this.c)
|| this.r + 2 == r && this.c - 1 == c && this.isEnemyOrEmpty(this.r + 1, this.c)
|| this.r + 2 == r && this.c + 1 == c && this.isEnemyOrEmpty(this.r + 1, this.c)
|| this.r - 1 == r && this.c - 2 == c && this.isEnemyOrEmpty(this.r, this.c - 1)
|| this.r - 1 == r && this.c + 2 == c && this.isEnemyOrEmpty(this.r, this.c + 1)
|| this.r + 1 == r && this.c - 2 == c && this.isEnemyOrEmpty(this.r, this.c - 1)
|| this.r + 1 == r && this.c + 2 == c && this.isEnemyOrEmpty(this.r, this.c + 1)
;
}
} else if (text == "相" || text == "象") {
return function (r, c) {
return this.r - 2 == r && this.c - 2 == c && this.isEnemyOrEmpty(this.r - 1, this.c - 1)
|| this.r - 2 == r && this.c + 2 == c && this.isEnemyOrEmpty(this.r - 1, this.c + 1)
|| this.r + 2 == r && this.c - 2 == c && this.isEnemyOrEmpty(this.r + 1, this.c - 1)
|| this.r + 2 == r && this.c + 2 == c && this.isEnemyOrEmpty(this.r + 1, this.c + 1)
;
}
} else if (text == "士" || text == "仕") {
if (that.r > 4) {
return function (r, c) {
var l = 7, l2 = 9, b = 3, b2 = 5;
if (r < l || r > l2 || c < b || c > b2) {
return false;
}
return this.r - 1 == r && this.c - 1 == c
|| this.r - 1 == r && this.c + 1 == c
|| this.r + 1 == r && this.c - 1 == c
|| this.r + 1 == r && this.c + 1 == c
;
}
} else {
return function (r, c) {
var l = 0, l2 = 3, b = 3, b2 = 5;
if (r < l || r > l2 || c < b || c > b2) {
return false;
}
return this.r - 1 == r && this.c - 1 == c
|| this.r - 1 == r && this.c + 1 == c
|| this.r + 1 == r && this.c - 1 == c
|| this.r + 1 == r && this.c + 1 == c
;
}
}
 
 
} else if (text == "将" || text == "帅") {
if (that.r > 4) {
return function (r, c) {
var l = 7, l2 = 9, b = 3, b2 = 5;
if (r < l || r > l2 || c < b || c > b2) {
return false;
}
return this.r - 1 == r && this.c == c
|| this.r + 1 == r && this.c == c
|| this.r == r && this.c - 1 == c
|| this.r == r && this.c + 1 == c
;
}
} else {
return function (r, c) {
var l = 0, l2 = 2, b = 3, b2 = 5;
if (r < l || r > l2 || c < b || c > b2) {
return false;
}
return this.r - 1 == r && this.c == c
|| this.r + 1 == r && this.c == c
|| this.r == r && this.c - 1 == c
|| this.r == r && this.c + 1 == c
;
}
}
}
return function () {
 
 
};
 
 
}());
}
QiZi.prototype = {
isEnemyOrEmpty: function (r, c) {
return this.qipan.bodys[r][c].qizi == null;
},

开发炮的功能时遇到了能在错误的规则下吃掉其他子问题,最终使用this.getMoveRange(r, c)方法解决了这个问题 调用方法事方法写错 没进行算法计算。
 
 
 

团队-象棋游戏3-模块开发过程

标签:问题   zha   遇到   over   项目   selector   turn   实现   开发   

原文地址:http://www.cnblogs.com/paoxiaodedaxuongmao/p/7740120.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!