📄 redgeneral.java
字号:
package finalexam;
public class RedGeneral extends Chessman{
public RedGeneral() {
super(5,1,0);
}
public String getId(){
return "帅";
}
public String toString(){
return "帅,x=" + posX + ",y=" + posY;
}
public void moveTo(int x,int y) throws IllegalMoveException{
//帅只能在9宫内,不能斜走
if (x==posX && Math.abs(y-posY)!=1){
throw new IllegalMoveException("竖走只能1步");
}
if (y==posY && Math.abs(x-posX)!=1){
throw new IllegalMoveException("横走只能1步");
}
if (x!=posX && y!=posY){
throw new IllegalMoveException("不能斜走");
}
if (x<4 || x>6 || y>3){
throw new IllegalMoveException("帅只能在9宫内");
}
super.moveTo(x,y);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -