From 8b1f89452c12adb7480f5349fc9a923fda0e6151 Mon Sep 17 00:00:00 2001 From: fdai7303 Date: Thu, 23 Jun 2022 09:15:20 +0200 Subject: [PATCH] finished HA 09 --- .../src/playground/BreakoutLevel3.java | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/GameProject/src/playground/BreakoutLevel3.java b/GameProject/src/playground/BreakoutLevel3.java index cac5682..9f0c1d9 100644 --- a/GameProject/src/playground/BreakoutLevel3.java +++ b/GameProject/src/playground/BreakoutLevel3.java @@ -1,11 +1,57 @@ package playground; +import java.awt.Color; +import java.util.HashMap; +import java.util.LinkedList; +import gameobjects.TextObject; +import gameobjects.GameObject; public class BreakoutLevel3 extends BreakoutLevel0 { - + gameobjects.TextObject showPoints = new gameobjects.TextObject("showPoints", this, 50, 10, 0, 0, "0", 20, Color.BLACK); + gameobjects.TextObject showLives = new gameobjects.TextObject("showLives", this, 600, 10, 0, 0, "3", 20, Color.GREEN); + // your code here + //protected static HashMap flags = new HashMap(); + //LinkedList addables = new LinkedList(); + + @Override + protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) { + super.actionIfBallHitsBrick(ball, brick); + + this.setLevelFlag("points", (Integer)this.getLevelFlag("points") + 10); + showPoints.setText(String.valueOf((Integer)this.getLevelFlag("points"))); + } + + @Override + public void applyGameLogic() { + super.applyGameLogic(); + + if (ball.getY() > ego.getY()) { + this.setLevelFlag("lives", (Integer)this.getLevelFlag("lives") - 1); + showLives.setText(String.valueOf((Integer)this.getLevelFlag("lives"))); + ball.setY(ego.getY() - 20); + ball.setX(ego.getX()); + } + } + + public boolean gameOver() { + if( (Integer)this.getLevelFlag("lives") < 0) { + return true; + } + + return false; + }; + //prepareLevel + public void prepareLevel(String level) { + this.setLevelFlag("points", 0); + this.setLevelFlag("lives", 3); + this.addObject(showPoints); + this.addObject(showLives); + + super.prepareLevel(level); + }; }