📄 xiaobing.java
字号:
package com.abc.hrd;
public class Xiaobing extends Qizi {
public Xiaobing(Qipan qipan, int x, int y) {
super(qipan, x, y);
this.w = 1;
this.h = 1;
}
public boolean inside(int x, int y) {
if (x == this.x && y == this.y) {
return true;
} else {
return false;
}
}
public boolean move(int x, int y) {
// 原地不动
if (this.x == x && this.y == y) {
return false;
}
// 横向移动
if (y == this.y) {
if (Math.abs(x - this.x) == 1) { // 横向移动一格
this.x = x;
return true;
}
if (this.x + 2 == x && !qipan.exists(this.x + 1, y)) { // 横向移动二格
this.x = x;
return true;
} else if (this.x - 2 == x && !qipan.exists(this.x - 1, y)) {
this.x = x;
return true;
}
// 间距太大,超出移动范围
return false;
}
// 纵向移动
if (x == this.x) {
if (Math.abs(y - this.y) == 1) { // 纵向移动一格
this.y = y;
return true;
}
if (this.y + 2 == y && !qipan.exists(x, this.y + 1)) { // 纵向移动二格
this.y = y;
return true;
} else if (this.y - 2 == y && !qipan.exists(x, this.y - 1)) {
this.y = y;
return true;
}
// 间距太大,超出移动范围
return false;
}
// 斜向移动,下面的算法有无问题?
if (Math.abs(x - this.x) == 1 && Math.abs(y - this.y) == 1) {
if (!qipan.exists(this.x, y) || !qipan.exists(x, this.y)) {
this.x = x;
this.y = y;
return true;
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -