|
|
|
@ -73,13 +73,7 @@ public class Level extends Thread implements ILevel {
|
|
|
|
|
this.score = score;
|
|
|
|
|
this.ball = new Ball();
|
|
|
|
|
|
|
|
|
|
// calc paddle positions
|
|
|
|
|
Position posPaddleTop = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, 0);
|
|
|
|
|
Position posPaddleBottom = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, Constants.SCREEN_HEIGHT - Constants.PADDLE_HEIGHT);
|
|
|
|
|
|
|
|
|
|
// set paddles
|
|
|
|
|
this.paddleTop = new Paddle(posPaddleTop);
|
|
|
|
|
this.paddleBottom = new Paddle(posPaddleBottom);
|
|
|
|
|
resetPaddles();
|
|
|
|
|
|
|
|
|
|
// set paddles color
|
|
|
|
|
this.paddleTop.setColor(Constants.COLOR_PADDLE_TOP);
|
|
|
|
@ -137,6 +131,11 @@ public class Level extends Thread implements ILevel {
|
|
|
|
|
// Call here the balls method for reacting on the borders of the playground
|
|
|
|
|
getBall().reactOnBorder();
|
|
|
|
|
|
|
|
|
|
// Call here the balls method for reacting on lost ball state
|
|
|
|
|
if(getBall().isLost()) {
|
|
|
|
|
decreaseLives();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if ball hits paddle (top|bottom), reflect ball
|
|
|
|
|
if(getBall().hitsPaddle(paddleTop)) getBall().reflectOnPaddle(paddleTop);
|
|
|
|
|
if(getBall().hitsPaddle(paddleBottom)) getBall().reflectOnPaddle(paddleBottom);
|
|
|
|
@ -282,6 +281,57 @@ public class Level extends Thread implements ILevel {
|
|
|
|
|
private boolean allStonesBroken() {
|
|
|
|
|
return stones.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* decreases the lives and interact to the new count
|
|
|
|
|
*/
|
|
|
|
|
private void decreaseLives() {
|
|
|
|
|
lifeCounter--;
|
|
|
|
|
// reset paddles to center pos
|
|
|
|
|
if(lifeCounter > 0) {
|
|
|
|
|
resetPaddles();
|
|
|
|
|
getBall().resetPosition();
|
|
|
|
|
getBall().setLost(false);
|
|
|
|
|
stopBall();
|
|
|
|
|
// level failed
|
|
|
|
|
} else {
|
|
|
|
|
setFinished(true);
|
|
|
|
|
game.getController().toStartScreen();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* resets paddles position and or init them
|
|
|
|
|
*/
|
|
|
|
|
private void resetPaddles() {
|
|
|
|
|
// calc paddle positions
|
|
|
|
|
Position posPaddleTop = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, 0);
|
|
|
|
|
Position posPaddleBottom = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, Constants.SCREEN_HEIGHT - Constants.PADDLE_HEIGHT);
|
|
|
|
|
|
|
|
|
|
// resets top paddle
|
|
|
|
|
if(paddleTop == null) paddleTop = new Paddle(posPaddleTop);
|
|
|
|
|
else paddleTop.setPosition(posPaddleTop);
|
|
|
|
|
|
|
|
|
|
// resets bottom paddle
|
|
|
|
|
if(paddleBottom == null) paddleBottom = new Paddle(posPaddleBottom);
|
|
|
|
|
else paddleBottom.setPosition(posPaddleBottom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The getter for levels score
|
|
|
|
|
* @return the score
|
|
|
|
|
*/
|
|
|
|
|
public int getScore() {
|
|
|
|
|
return score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The getter for levels lives
|
|
|
|
|
* @return the life counter
|
|
|
|
|
*/
|
|
|
|
|
public int getLives() {
|
|
|
|
|
return lifeCounter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|