⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 redgeneral.java

📁 Java程序设计课后练习题题目的相关练习答案
💻 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 + -