ArrayListの各キューブの衝突をチェック

mcfly24:

私は配列リスト内の各キューブの衝突をチェックしようとしているが、結果は衝突が唯一の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;
                }
            }
        }
    }
}
desmaxi:

すべての競合法の最初はそうではないreturn、私はどのようにこのコンパイルを思ったんだけど、何も。しかし、問題は、あなたが外出されることはありませんfor loopあなたが衝突を見つけたとき。

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;
                    break;
                } else {
                    this.conflict = false;
                }
            }
        }
    }

    return this.conflict;
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=335887&siteId=1