【发布时间】:2019-05-22 08:19:03
【问题描述】:
我正在尝试检查 arraylist 中每个立方体的碰撞,但结果是,该碰撞仅适用于 arraylist 中的最后一个立方体..
public class Cube {
public int x, y;
private boolean conflict = false;
public Cube(int x, int y) {
this.x = x;
this.y = y;
}
public void moveDown() {
if(!conflict("down")) {
this.y += 18;
}
}
public boolean conflict(String dir) {
if(dir.equals("down")) {
for(Cube cubes : Panel.cubes) {
if(this.hashCode() != cubes.hashCode()) {
if(this.y + 18 == cubes.y && this.x == cubes.x || this.y >= Main.height - 18*4) {
this.conflict = true;
} else this.conflict = false;
}
}
}
}
}
【问题讨论】: