首页上一页 1 下一页尾页 2 条记录 1/1页
java项目开发全程实录第十章,谁帮忙解释下棋子规则代码
发表在Java图书答疑
2009-05-15
是否精华
是
否
版块置顶:
是
否
private void theRuleOfChe(int m, int n, int sx, int sy) {// 车的规则
g = 0;
if (m == sx) {
if (n > sy) {
for (i = 1; i < n - sy; i++) {
if (point[sy + i][m] != 0) {
g++;
}
}
} else {
for (i = 1; i < sy - n; i++) {
if (point[n + i][m] != 0) {
g++;
}
}
}
if (g == 0) {
changTwoChessNum(m, n, sx, sy, true);
}
}
if (n == sy) {
if (m > sx) {
for (i = 1; i < m - sx; i++) {
if (point[n][i + sx] != 0) {
g++;
}
}
} else {
for (i = 1; i < sx - m; i++) {
if (point[n][m + i] != 0) {
g++;
}
}
}
if (g == 0) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
private void theRuleOfMa(int m, int n, int sx, int sy) {// 马的规则
if (n < 9) {
if (point[n + 1][m] == 0) {
if (sx - m == 1) {
if (sy - n == 2) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (n > 0) {
if (point[n - 1][m] == 0) {
if (m - sx == 1) {
if (n - sy == 2) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (n < 9) {
if (point[n + 1][m] == 0) {
if (sx - m == -1) {
if (sy - n == 2) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (n > 0) {
if (point[n - 1][m] == 0) {
if (m - sx == -1) {
if (n - sy == 2) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (m < 8) {
if (point[n][m + 1] == 0) {
if (sx - m == 2) {
if (sy - n == 1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (m > 0) {
if (point[n][m - 1] == 0) {
if (m - sx == 2) {
if (n - sy == 1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (m < 8) {
if (point[n][m + 1] == 0) {
if (sx - m == 2) {
if (sy - n == -1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (m > 0) {
if (point[n][m - 1] == 0) {
if (m - sx == 2) {
if (n - sy == -1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
}
private void theRuleOfPao(int m, int n, int sx, int sy, int g1) {// 炮的规则
g = 0;
if (m == sx) {
if (n > sy) {
for (i = 1; i < n - sy; i++) {
if (point[sy + i][m] != 0) {
g++;
}
}
} else {
for (i = 1; i < sy - n; i++) {
if (point[n + i][m] != 0) {
g++;
}
}
}
if (g == g1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
if (n == sy) {
if (m > sx) {
for (i = 1; i < m - sx; i++) {
if (point[n][i + sx] != 0) {
g++;
}
}
} else {
for (i = 1; i < sx - m; i++) {
if (point[n][m + i] != 0) {
g++;
}
}
}
if (g == g1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
private void theRuleOfXiang(int m, int n, int sx, int sy) {// 相的规则
if (color.equals("red"))
if (sy < 5)
return;
else if (color.equals("while"))
if (sy > 4)
return;
if (n < 9 & m < 8) {
if (point[n + 1][m + 1] == 0) {
if ((sx - m == 2) & (sy - n == 2)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
if (n > 0 & m < 8) {
if (point[n - 1][m + 1] == 0) {
if ((sx - m == 2) & (sy - n == -2)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
if (n < 9 & m > 0) {
if (point[n + 1][m - 1] == 0) {
if ((sx - m == -2) & (sy - n == 2)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
if (n > 0 & m > 0) {
if (point[n - 1][m - 1] == 0) {
if ((sx - m == -2) & (sy - n == -2)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
private void theRuleOfShi(int m, int n, int sx, int sy) {// 士的规则
if ((m > 2 & m < 6) & (sx > 2 & sx < 6) & (n >= 7 & n <= 9)
& (sy >= 7 & sy <= 9)) {
if ((sx - m == 1) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 1) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
if ((m > 2 & m < 6) & (sx > 2 & sx < 6) & (n >= 0 & n < 3)
& (sy >= 0 & sy < 3)) {
if ((sx - m == 1) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 1) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
private void theRuleOfShuai(int m, int n, int sx, int sy) {// 帅的规则
if ((m > 2 & m < 6) & (sx > 2 & sx < 6) & (n >= 7 & n <= 9)
& (sy >= 7 & sy <= 9)) {
if ((sx - m == 1) & (sy - n == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 0) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 0) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
if ((m > 2 & m < 6) & (sx > 2 & sx < 6) & (n >= 0 & n < 3)
& (sy >= 0 & sy < 3)) {
if ((sx - m == 1) & (sy - n == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 0) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 0) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
private void theRuleOfZu(int m, int n, int sx, int sy) {// 卒的规则
if (sy <= n) {
if (n > 4) {
if ((sy - n == -1) & (sx - m == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
} else {
if ((sy - n == -1) & (sx - m == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sy - n == 0) & (sx - m == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sy - n == 0) & (sx - m == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
g = 0;
if (m == sx) {
if (n > sy) {
for (i = 1; i < n - sy; i++) {
if (point[sy + i][m] != 0) {
g++;
}
}
} else {
for (i = 1; i < sy - n; i++) {
if (point[n + i][m] != 0) {
g++;
}
}
}
if (g == 0) {
changTwoChessNum(m, n, sx, sy, true);
}
}
if (n == sy) {
if (m > sx) {
for (i = 1; i < m - sx; i++) {
if (point[n][i + sx] != 0) {
g++;
}
}
} else {
for (i = 1; i < sx - m; i++) {
if (point[n][m + i] != 0) {
g++;
}
}
}
if (g == 0) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
private void theRuleOfMa(int m, int n, int sx, int sy) {// 马的规则
if (n < 9) {
if (point[n + 1][m] == 0) {
if (sx - m == 1) {
if (sy - n == 2) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (n > 0) {
if (point[n - 1][m] == 0) {
if (m - sx == 1) {
if (n - sy == 2) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (n < 9) {
if (point[n + 1][m] == 0) {
if (sx - m == -1) {
if (sy - n == 2) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (n > 0) {
if (point[n - 1][m] == 0) {
if (m - sx == -1) {
if (n - sy == 2) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (m < 8) {
if (point[n][m + 1] == 0) {
if (sx - m == 2) {
if (sy - n == 1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (m > 0) {
if (point[n][m - 1] == 0) {
if (m - sx == 2) {
if (n - sy == 1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (m < 8) {
if (point[n][m + 1] == 0) {
if (sx - m == 2) {
if (sy - n == -1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
if (m > 0) {
if (point[n][m - 1] == 0) {
if (m - sx == 2) {
if (n - sy == -1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
}
private void theRuleOfPao(int m, int n, int sx, int sy, int g1) {// 炮的规则
g = 0;
if (m == sx) {
if (n > sy) {
for (i = 1; i < n - sy; i++) {
if (point[sy + i][m] != 0) {
g++;
}
}
} else {
for (i = 1; i < sy - n; i++) {
if (point[n + i][m] != 0) {
g++;
}
}
}
if (g == g1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
if (n == sy) {
if (m > sx) {
for (i = 1; i < m - sx; i++) {
if (point[n][i + sx] != 0) {
g++;
}
}
} else {
for (i = 1; i < sx - m; i++) {
if (point[n][m + i] != 0) {
g++;
}
}
}
if (g == g1) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
private void theRuleOfXiang(int m, int n, int sx, int sy) {// 相的规则
if (color.equals("red"))
if (sy < 5)
return;
else if (color.equals("while"))
if (sy > 4)
return;
if (n < 9 & m < 8) {
if (point[n + 1][m + 1] == 0) {
if ((sx - m == 2) & (sy - n == 2)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
if (n > 0 & m < 8) {
if (point[n - 1][m + 1] == 0) {
if ((sx - m == 2) & (sy - n == -2)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
if (n < 9 & m > 0) {
if (point[n + 1][m - 1] == 0) {
if ((sx - m == -2) & (sy - n == 2)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
if (n > 0 & m > 0) {
if (point[n - 1][m - 1] == 0) {
if ((sx - m == -2) & (sy - n == -2)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}
private void theRuleOfShi(int m, int n, int sx, int sy) {// 士的规则
if ((m > 2 & m < 6) & (sx > 2 & sx < 6) & (n >= 7 & n <= 9)
& (sy >= 7 & sy <= 9)) {
if ((sx - m == 1) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 1) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
if ((m > 2 & m < 6) & (sx > 2 & sx < 6) & (n >= 0 & n < 3)
& (sy >= 0 & sy < 3)) {
if ((sx - m == 1) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 1) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
private void theRuleOfShuai(int m, int n, int sx, int sy) {// 帅的规则
if ((m > 2 & m < 6) & (sx > 2 & sx < 6) & (n >= 7 & n <= 9)
& (sy >= 7 & sy <= 9)) {
if ((sx - m == 1) & (sy - n == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 0) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 0) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
if ((m > 2 & m < 6) & (sx > 2 & sx < 6) & (n >= 0 & n < 3)
& (sy >= 0 & sy < 3)) {
if ((sx - m == 1) & (sy - n == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == -1) & (sy - n == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 0) & (sy - n == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sx - m == 0) & (sy - n == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
private void theRuleOfZu(int m, int n, int sx, int sy) {// 卒的规则
if (sy <= n) {
if (n > 4) {
if ((sy - n == -1) & (sx - m == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
} else {
if ((sy - n == -1) & (sx - m == 0)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sy - n == 0) & (sx - m == 1)) {
changTwoChessNum(m, n, sx, sy, true);
}
if ((sy - n == 0) & (sx - m == -1)) {
changTwoChessNum(m, n, sx, sy, true);
}
}
}
}