1
0
Fork 0

Aufgabe 3.3

This commit is contained in:
rxbn_ 2019-12-17 22:15:00 +01:00
parent 0548e10e6b
commit 94a394438d
2 changed files with 13 additions and 2 deletions

View File

@ -132,6 +132,12 @@ public class Controller implements ActionListener, KeyListener {
game.getLevel().getPaddleBottom().setDirection(+1); game.getLevel().getPaddleBottom().setDirection(+1);
game.getLevel().getPaddleTop().setDirection(+1); game.getLevel().getPaddleTop().setDirection(+1);
break; break;
// escape was pressed
case KeyEvent.VK_ESCAPE:
// exit current level
game.getLevel().setFinished(true);
toStartScreen();
break;
} }
} }

View File

@ -36,6 +36,11 @@ public class Level extends Thread implements ILevel {
*/ */
private boolean ballWasStarted = false; private boolean ballWasStarted = false;
/**
* Flag that shows if the level was finished
*/
private boolean levelFinished = false;
/** /**
* The paddles of the level * The paddles of the level
*/ */
@ -109,7 +114,7 @@ public class Level extends Thread implements ILevel {
game.notifyObservers(); game.notifyObservers();
// endless loop // endless loop
while (true) { while (!levelFinished) {
// if ballWasStarted is true, the ball is moving // if ballWasStarted is true, the ball is moving
if (ballWasStarted()) { if (ballWasStarted()) {
@ -184,7 +189,7 @@ public class Level extends Thread implements ILevel {
* @param finished game state * @param finished game state
*/ */
public void setFinished(boolean finished) { public void setFinished(boolean finished) {
this.levelFinished = finished;
} }
} }