📄 guanyu.java
字号:
package com.abc.hrd;
public class Guanyu extends Qizi {
public Guanyu(Qipan qipan, int x, int y) {
super(qipan, x, y);
this.w = 2;
this.h = 1;
}
public boolean move(int x, int y) {
// 原地不动
if (inside(x, y)) {
return false;
}
// 横向移动
if (this.y == y) {
if (this.x + 2 == x) { // 向右移动一格
this.x++;
return true;
}
if (this.x - 1 == x) { // 向左移动一格
this.x--;
return true;
}
if (this.x + 3 == x && !qipan.exists(this.x + 2, y)) { // 向右移动二格
this.x += 2;
return true;
}
if (this.x - 2 == x && !qipan.exists(this.x - 1, y)) { // 向左移动二格
this.x -= 2;
return true;
}
return false;
} else {
// 纵向移动
if (this.y > y) {
if (!qipan.exists(this.x, this.y - 1) // 向上移动一格
&& !qipan.exists(this.x + 1, this.y - 1)) {
this.y--;
return true;
}
}
if (this.y < y) {
if (!qipan.exists(this.x, this.y + 1) // 向下移动一格
&& !qipan.exists(this.x + 1, this.y + 1)) {
this.y++;
return true;
}
}
return false;
}
}
public boolean inside(int x, int y) {
if (x > this.x) {
x = x - 1;
}
if (x == this.x && y == this.y) {
return true;
} else {
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -