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