87,901
社区成员
发帖
与我相关
我的任务
分享
var CChessConsts = {
classes: {
"0": "space"
,"1": "red1", "2": "red2", "3": "red3", "4": "red4", "5": "red5", "6": "red6", "7": "red7"
,"-1": "black1", "-2": "black2", "-3": "black3", "-4": "black4", "-5": "black5", "-6": "black6", "-7": "black7"
}
, initBorad: [
-5, -4, -3, -2, -1, -2, -3, -4, -5
, 00, 00, 00, 00, 00, 00, 00, 00, 00
, 00, -6, 00, 00, 00, 00, 00, -6, 00
, -7, 00, -7, 00, -7, 00, -7, 00, -7
, 00, 00, 00, 00, 00, 00, 00, 00, 00
, 00, 00, 00, 00, 00, 00, 00, 00, 00
, +7, 00, +7, 00, +7, 00, +7, 00, +7
, 00, +6, 00, 00, 00, 00, 00, +6, 00
, 00, 00, 00, 00, 00, 00, 00, 00, 00
, +5, +4, +3, +2, +1, +2, +3, +4, +5
]
};
.div_desktop {width:459px;height:538px;}
.div_desktop input {width:65px;position:absolute;}
.div_desktop .input_username {border:none 0;background:transparent;left:70px;width:100px;font-weight:bold;}
.div_desktop .input_rank {border:none 0;background:transparent;width:70px;font-weight:bold;}
.div_player {position:relative;}
.table_board{width:459px;height:510px;background:url(/Images/chinesechess_board.gif)}
.table_board td{width:51px;height:51px;text-align:center;line-height:34px;}
.chess{background:url(/Images/chinesechess_corner.gif);}
.space{background:none;}
.red1{background-position:0 0;}
.red2{background-position:-50px 0;}
.red3{background-position:-100px 0;}
.red4{background-position:-150px 0;}
.red5{background-position:-200px 0;}
.red6{background-position:-250px 0;}
.red7{background-position:-300px 0;}
.black1{background-position:0 -50px;}
.black2{background-position:-50px -50px;}
.black3{background-position:-100px -50px;}
.black4{background-position:-150px -50px;}
.black5{background-position:-200px -50px;}
.black6{background-position:-250px -50px;}
.black7{background-position:-300px -50px;}
.redJiang{background-position:-200px -100px;}
.blackJiang{background-position:-250px -100px;}
.cur_drag{cursor:pointer;}
.div_selection{width:50px;height:50px;background:url(/Images/chinesechess_corner.gif) no-repeat 0 -100px;}
.div_from{width:50px;height:50px;background:url(/Images/chinesechess_corner.gif) no-repeat -50px -100px;}
.div_to{width:50px;height:50px;background:url(/Images/chinesechess_corner.gif) no-repeat -50px -100px;}
.cur_kill{cursor:url(/Images/kill.cur),auto;}
.cur_move{cursor:url(/Images/footprint.cur),auto;}
.div_manual{width:300px;height:510px;border:1px solid #75c6d9;overflow:scroll;}
ChineseChess.prototype.updateMovepoints = function() {
this.movepoints = {};
if (this.selection < 0) return;
if (this.echoPlace != this.currPlayer) return;
var chess = this.types[this.selection];
var x = this.selection % 9;
var y = Math.floor(this.selection / 9);
var offset = [{ x: +1, y: 00 }, { x: -1, y: 00 }, { x: 00, y: +1 }, { x: 00, y: -1 }];
var offsetX = [{ x: +1, y: +1 }, { x: -1, y: -1 }, { x: +1, y: -1 }, { x: -1, y: +1 }];
var offset8 = [
{ x: +2, y: -1 }
, { x: +2, y: +1 }
, { x: -2, y: -1 }
, { x: -2, y: +1 }
, { x: +1, y: +2 }
, { x: -1, y: +2 }
, { x: -1, y: -2 }
, { x: +1, y: -2 }
];
var position;
var mx, my, i;
switch (Math.abs(chess)) {
case 1: // 帅
for (i = 0; i < offset.length; i++) {
mx = x + offset[i].x;
my = y + offset[i].y;
if (mx < 3 || mx > 5 || my < 0 || my >= 10) continue;
if (chess > 0 && my < 7) continue;
if (chess < 0 && my > 2) continue;
position = my * 9 + mx;
if (this.types[position] == 0) {
this.movepoints[position] = "move";
} else {
if (sign(this.types[position]) != sign(chess))
this.movepoints[position] = "kill";
}
}
// 见面
i = chess > 0 ? 3 : 2;
mx = x + offset[i].x;
my = y + offset[i].y;
while (mx >= 0 && mx < 9 && my >= 0 && my < 10) {
position = my * 9 + mx;
if (this.types[position] != 0) {
if (this.types[position] == -chess)
this.movepoints[position] = "kill";
break;
}
mx += offset[i].x;
my += offset[i].y;
}
break;
case 2: // 士
for (i = 0; i < offsetX.length; i++) {
mx = x + offsetX[i].x;
my = y + offsetX[i].y;
if (mx < 3 || mx > 5 || my < 0 || my >= 10) continue;
if (chess > 0 && my < 7) continue;
if (chess < 0 && my > 2) continue;
position = my * 9 + mx;
if (this.types[position] == 0) {
this.movepoints[position] = "move";
} else {
if (sign(this.types[position]) != sign(chess))
this.movepoints[position] = "kill";
}
}
break;
case 3: // 象
for (i = 0; i < offsetX.length; i++) {
mx = x + offsetX[i].x;
my = y + offsetX[i].y;
if (mx < 0 || mx >= 9 || my < 0 || my >= 10) continue;
if (this.types[my * 9 + mx] != 0) continue; // 中间有棋子
mx += offsetX[i].x;
my += offsetX[i].y;
if (mx < 0 || mx > 9) continue;
if (chess > 0 && my < 5) continue;
if (chess < 0 && my > 4) continue;
position = my * 9 + mx;
if (this.types[position] == 0) {
this.movepoints[position] = "move";
} else {
if (sign(this.types[position]) != sign(chess))
this.movepoints[position] = "kill";
}
}
break;
case 4: // 马
for (i = 0; i < offset8.length; i++) {
var check = Math.floor(i / 2);
mx = x + offset[check].x;
my = y + offset[check].y;
if (mx < 0 || mx >= 9 || my < 0 || my >= 10) continue;
if (this.types[my * 9 + mx] != 0) continue; // 中间有棋子
mx = x + offset8[i].x;
my = y + offset8[i].y;
if (mx < 0 || mx >= 9 || my < 0 || my >= 10) continue;
position = my * 9 + mx;
if (this.types[position] == 0) {
this.movepoints[position] = "move";
} else {
if (sign(this.types[position]) != sign(chess))
this.movepoints[position] = "kill";
}
}
break;
case 5: // 車
for (i = 0; i < offset.length; i++) {
mx = x + offset[i].x;
my = y + offset[i].y;
while (mx >= 0 && mx < 9 && my >= 0 && my < 10) {
position = my * 9 + mx;
if (this.types[position] == 0) {
this.movepoints[position] = "move";
} else {
if (sign(this.types[position]) != sign(chess))
this.movepoints[position] = "kill";
break;
}
mx += offset[i].x;
my += offset[i].y;
}
}
break;
case 6: // 炮
for (i = 0; i < offset.length; i++) {
mx = x + offset[i].x;
my = y + offset[i].y;
var kill = false;
while (mx >= 0 && mx < 9 && my >= 0 && my < 10) {
position = my * 9 + mx;
if (this.types[position] == 0) {
if (!kill) this.movepoints[position] = "move";
} else {
if (kill) {
if (sign(this.types[position]) != sign(chess))
this.movepoints[position] = "kill";
break;
}
kill = true;
}
mx += offset[i].x;
my += offset[i].y;
}
}
break;
case 7: // 兵
for (i = 0; i < offset.length; i++) {
if (chess > 0 && (offset[i].y > 0 || y > 4 && offset[i].x != 0)) continue;
if (chess < 0 && (offset[i].y < 0 || y < 5 && offset[i].x != 0)) continue;
mx = x + offset[i].x;
my = y + offset[i].y;
if (mx >= 0 && mx < 9 && my >= 0 && my < 10) {
position = my * 9 + mx;
if (this.types[position] == 0) {
this.movepoints[position] = "move";
} else {
if (sign(this.types[position]) != sign(chess))
this.movepoints[position] = "kill";
}
}
}
break;
}
}