From 83c29d5fc1080d80a7c104edf027cab064151b68 Mon Sep 17 00:00:00 2001 From: Nico B Date: Thu, 23 Jun 2022 15:00:19 +0200 Subject: [PATCH] finished HA09 --- GameProject/src/base/BreakoutGame.java | 8 ++-- .../src/playground/BreakoutLevel3.java | 48 ++++++++++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/GameProject/src/base/BreakoutGame.java b/GameProject/src/base/BreakoutGame.java index a91dc4e..f939fa6 100644 --- a/GameProject/src/base/BreakoutGame.java +++ b/GameProject/src/base/BreakoutGame.java @@ -19,12 +19,12 @@ public class BreakoutGame extends GameLoop { @Override public void defineLevels() { this.resetLevels(); // removes Level1 added by superclass constructor -<<<<<<< HEAD + //this.addLevel(new BreakoutLevel1()); // FIXME add this as soon as your level exists - this.addLevel(new BreakoutLevel2()); -======= + //this.addLevel(new BreakoutLevel2()); + this.addLevel(new BreakoutLevel3()); // sorry for the git conflict this may cause! ->>>>>>> aa2436e4a45e3ac1bb4b8beb537007ae3887598e + } /** diff --git a/GameProject/src/playground/BreakoutLevel3.java b/GameProject/src/playground/BreakoutLevel3.java index cac5682..7b2f222 100644 --- a/GameProject/src/playground/BreakoutLevel3.java +++ b/GameProject/src/playground/BreakoutLevel3.java @@ -1,10 +1,56 @@ package playground; +import java.awt.Color; +import gameobjects.GameObject; +import gameobjects.TextObject; public class BreakoutLevel3 extends BreakoutLevel0 { + + TextObject pointsText = new TextObject("pointsText", this, 50, 10, 0.,0, "0", 20, Color.BLACK); + TextObject livesText = new TextObject("livesText", this, 600,10,0,0,"3", 20, Color.GREEN); - // your code here + @Override + public void prepareLevel(String id) { + setLevelFlag("points", 0); + TextObject score = pointsText; + this.addObject(score); + setGlobalFlag("lives", 3); + TextObject lives = livesText; + this.addObject(lives); + super.prepareLevel(id); + + } + + @Override + protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) { + super.actionIfBallHitsBrick(ball, brick); + int value = (int) getLevelFlag("points"); + setLevelFlag("points", value + 10); + pointsText.setText("" + getLevelFlag("points")); + } + + @Override + public void applyGameLogic (){ + super.applyGameLogic(); + int value = (int) getGlobalFlag("lives"); + if(this.ball.getY() > this.ego.getY()) { + setGlobalFlag("lives", --value); + livesText.setText("" + value); + this.ball.setY(this.ego.getY() - 20); + this.ball.setX(this.ego.getX()); + } + + + } + @Override + public boolean gameOver() { + int value = (int) getGlobalFlag("lives"); + if (value <0) { + return true; + } + return false; + } }