📄 shi.java
字号:
package com.catking.chess;
import java.util.*;
import com.catking.Utility.Position;
public class Shi extends Chess{
public Shi(int color) {
super(color);
// TODO Auto-generated constructor stub
this.name = '士';
}
@Override
public void go() {
// TODO Auto-generated method stub
System.out.print("士");
}
@Override
public Set<Position> availableSteps() {
// TODO Auto-generated method stub
Set<Position>set = new HashSet<Position>();
//叉士型
//正中
if( (x == 1 && y == 4)
|| (x == ChessPane.ROWS - 2 && y == 4)){
//左上
if(ChessPane.chesses[x-1][y-1].color != color)
set.add(new Position(x-1, y-1));
//左下
if(ChessPane.chesses[x+1][y-1].color != color)
set.add(new Position(x+1, y-1));
//右上
if(ChessPane.chesses[x-1][y+1].color != color)
set.add(new Position(x-1, y+1));
//右下
if(ChessPane.chesses[x+1][y+1].color != color)
set.add(new Position(x+1, y+1));
}
else{
if(color == ChessPane.ATTACK_UP && ChessPane.chesses[ChessPane.ROWS - 2][4].color != color)
set.add(new Position(ChessPane.ROWS - 2, 4));
if(color == ChessPane.ATTACK_DOWN && ChessPane.chesses[1][4].color != color)
set.add(new Position(1, 4));
}
System.out.println("有"+set.size()+"条道路");
return set;
}
//覆盖父类
public boolean isJiangJun(){
//士不能将军
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -