Neustart der while-Schleife

Ich versuche zu starten der while-Schleife. Ich habe deklarierte variable keepGoing vom Typ boolean. Wenn die int-variable x wird aus dem Fenster, keepGoing änderungen auf false. Dann die reset () - Methode haben, um keepGoing=true. Es funktioniert, aber die while-Schleife nicht funktioniert.

Klasse mit reset() und checkWin():

private void reset() {
    b.x = 250;
    b.y = 100;
    b.keepRunning = true;
    a.keepGoing = true;
    System.out.println(a.keepGoing);
}

public void checkWin() {
    if (b.keepRunning) {
        if (b.getX() < -10) {
            a.score++;

            JOptionPane.showMessageDialog(okno, "Player " + p.getScore()
                    + " - Computer " + a.getScore(), "Oh, well...",
                    JOptionPane.INFORMATION_MESSAGE);
            b.keepRunning = false;
            a.keepGoing = false;
            System.out.println(a.keepGoing);
            reset();
        } else if (b.getX() > 599) {
            p.score++;
            JOptionPane.showMessageDialog(okno, "Player " + p.getScore()
                    + " - Computer " + a.getScore(), "Good!",
                    JOptionPane.INFORMATION_MESSAGE);
            b.keepRunning = false;
            a.keepGoing = false;
            System.out.println(a.keepGoing);
            reset();
        }
    }
}

Zweite Klasse, mit Gewinde, keepGoing und die while-Schleife:

Runnable intel = new Runnable() {
    public void run() {
        while (keepGoing) {
            while (getY() < board.ball.getY()) {
                System.out.println(keepGoing + " " + getY());
                try {
                    if (y == 220) {
                    } else {
                        y += 1;
                        Thread.sleep(10);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            while (getY() > board.ball.getY()) {
                System.out.println(keepGoing + " " + getY());
                try {
                    if (y == 0) {
                    } else {
                        y -= 1;
                        Thread.sleep(10);
                    }
                } catch (InterruptedException e) {
                    //TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
};

InformationsquelleAutor Adrian Marszałek | 2012-07-11

Schreibe einen Kommentar