📄 chessitem.java
字号:
package chs;
public class ChessItem {
protected ChessBoard b = null;
boolean a = true;
String id = "";
int x, y;
public ChessItem(String id, int x, int y) {
this.id = id;
this.x = x;
this.y = y;
}
public ChessItem(ChessBoard b, String id, int x, int y) {
this.b = b;
this.id = id;
this.x = x;
this.y = y;
}
public boolean isType(char t){
return this.id.charAt(1) == (t);
}
public boolean isItem(String id){
return this.id.equals(id);
}
public boolean isAt(int x, int y){
return this.x == x && this.y == y;
}
public void dead(){
a = false;
}
public boolean isDead(){
return !a;
}
public boolean isLive(){
return a;
}
public boolean moveTo(int x, int y){
return false;
}
public void setBoard(ChessBoard b) {
this.b = b;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public boolean isOnStep(int x, int y){
return (Math.abs(this.x - x) + Math.abs(this.y - y)) == 1 ;
}
public boolean isInBase(int x, int y){
return (x < 4 || x > 6 || y < 1 || y > 10) || (y > 3 && y < 8);
}
public boolean isOnLine(int x, int y){
return this.x == x || this.y == y;
}
public boolean isOnLine(int x0, int y0, int x1, int y1){
if(x0 == x1){
return x==x0 && (y-y0)*(y-y1) < 0;
}else if(y0 == y1){
return y==y0 && (x-x0)*(x-x1) < 0;
}else{
return false;
}
}
public int getCenterX(int x){
return this.x + (x - this.x)/2;
}
public int getCenterY(int y){
return this.y + (y - this.y)/2;
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -