📄 ju.java
字号:
package com.catking.chess;
import java.util.HashSet;
import java.util.Set;
import com.catking.Utility.*;
public class Ju extends Chess{
public Ju(int color){
super(color);
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>();
//left
int temp = y;
while(temp-- != 0){
if(!add(set, x, temp))
break;
}
//right
temp = y;
while(temp++ != ChessPane.COLS-1){
if(!add(set, x, temp))
break;
}
//up
temp = x;
while(temp-- != 0){
if(!add(set, temp, y))
break;
}
//down
temp = x;
while(temp++ != ChessPane.ROWS-1){
if(!add(set, temp, y))
break;
}
//System.out.println("有"+set.size()+"条道路");
return set;
}
private boolean add(Set<Position>set, int x, int y){
int clr = ChessPane.chesses[x][y].color;
//不是同色的棋子
if( clr != color){
set.add(new Position(x, y));
//遇到了第一个对方的棋子
return clr == KONG;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -