?? xiang.java
字號:
package com.catking.chess;
import java.util.*;
import com.catking.Utility.Position;
public class Xiang extends Chess{
public Xiang(int color) {
super(color);
// TODO Auto-generated constructor stub
this.name = (color == ATTACK_UP )?'相':'象';
}
@Override
public void go() {
// TODO Auto-generated method stub
System.out.print((color == ATTACK_UP )?"相":"象");
}
@Override
public Set<Position> availableSteps() {
// TODO Auto-generated method stub
//田象 注意憋象眼,并且不能過河
Set<Position>set = new HashSet<Position>();
//左上
//首先檢查會不會過河
if(isOverRiver(x-2))
;
//能過河
else if(x >= 2 && y >= 2
&& ChessPane.chesses[x-2][y-2].color != color
&& ChessPane.chesses[x-1][y-1].color == KONG ){
set.add(new Position(x-2, y-2));
}
//左下
if(isOverRiver(x+2))
;
else if(x <= ChessPane.ROWS-3 && y >= 2
&& ChessPane.chesses[x+2][y-2].color != color
&& ChessPane.chesses[x+1][y-1].color == KONG ){
set.add(new Position(x+2, y-2));
}
//右上
if(isOverRiver(x-2))
;
else if(x >= 2 && y <= ChessPane.COLS-3
&& ChessPane.chesses[x-2][y+2].color != color
&& ChessPane.chesses[x-1][y+1].color == KONG ){
set.add(new Position(x-2, y+2));
}
//右下
if(isOverRiver(x+2))
;
else if(x <= ChessPane.ROWS-3 && y <= ChessPane.COLS-3
&& ChessPane.chesses[x+2][y+2].color != color
&& ChessPane.chesses[x+1][y+1].color == KONG ){
set.add(new Position(x+2, y+2));
}
System.out.println("有"+set.size()+"條道路");
return set;
}
private boolean isOverRiver(int x){
boolean isOver = (color == ChessPane.ATTACK_UP && x < ChessPane.ATTACK_UP_BANK)
||(color == ChessPane.ATTACK_DOWN && x > ChessPane.ATTACK_DOWN_BANK);
return isOver;
}
//覆蓋父類
public boolean isJiangJun(){
//相不能將軍
return false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -