From f01001a5536815ffefcf0a25ccae792f3345e72d Mon Sep 17 00:00:00 2001 From: Manu Date: Mon, 16 May 2022 15:25:44 +0200 Subject: [PATCH] Hausaufgabe 4 Ergebnis --- GameProject/src/base/GameLoop.java | 3 +- GameProject/src/base/MultiLevelGame.java | 38 +++++++---------- GameProject/src/playground/LevelWithBox.java | 43 ++++++++++++++++++++ GameProject/src/playground/Playground.java | 1 - 4 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 GameProject/src/playground/LevelWithBox.java diff --git a/GameProject/src/base/GameLoop.java b/GameProject/src/base/GameLoop.java index f98bd42..9b5365d 100644 --- a/GameProject/src/base/GameLoop.java +++ b/GameProject/src/base/GameLoop.java @@ -8,6 +8,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import gameobjects.GameObject; import playground.Level1; +import playground.LevelWithBox; import playground.Playground; import ui.GameUI; @@ -55,7 +56,7 @@ public class GameLoop { */ void defineLevels() { this.resetLevels(); - this.addLevel(new Level1()); + this.addLevel(new LevelWithBox()); } /** diff --git a/GameProject/src/base/MultiLevelGame.java b/GameProject/src/base/MultiLevelGame.java index 800df34..3b455a2 100644 --- a/GameProject/src/base/MultiLevelGame.java +++ b/GameProject/src/base/MultiLevelGame.java @@ -2,29 +2,21 @@ package base; import java.io.IOException; -import playground.*; +import playground.Level5; +import playground.LevelWithBox; public class MultiLevelGame extends GameLoop { - - @Override - void defineLevels() { - this.resetLevels(); - - //this.addLevel(new Level1()); - // this.addLevel(new LevelHitTwice()); - // this.addLevel(new Level3()); - // this.addLevel(new LevelBoss()); - this.addLevel(new Level5()); - this.addLevel(new Level6()); - this.addLevel(new Level7()); - - } - - public static void main(String[] args) throws IOException { - - MultiLevelGame l5 = new MultiLevelGame(); - l5.runGame(args); - } - } - + + void defineLevels() { + this.addLevel(new LevelWithBox()); + } + + + + + public static void main(String[] args) throws IOException { + GameLoop gl = new GameLoop(); + gl.runGame(args); + } +} diff --git a/GameProject/src/playground/LevelWithBox.java b/GameProject/src/playground/LevelWithBox.java new file mode 100644 index 0000000..36a35fc --- /dev/null +++ b/GameProject/src/playground/LevelWithBox.java @@ -0,0 +1,43 @@ +package playground; + +import gameobjects.RectObject; +import java.awt.Color; + + +/** + * The class creates its own level, which contains 2 methods + * and takes methods from the SpaceInvadersLevel class as well as + * from the RectObject class.The graphical content is changed here. + * RectObject initialized with a suitable RectArtist to draw the RectObject. + * + * This class extends from {@link SpaceInvadersLife}. + */ +public class LevelWithBox extends SpaceInvadersLevel { + +/** + * + * PrepareLevel + * First sets up the layer and calls it every time it starts. + * An object with transmitted parameters from RectObject is created. + * addObject Method from the {@link Playground} class adds the graphics object to a level. + * @param id - String unique name to be used. + */ + public void prepareLevel(String id) { + + super.prepareLevel(id); + RectObject Object = new RectObject(id,null,350,100,0,0,700,250,Color.RED); + this.addObject(Object); + } + + /** + * Returns the text that should be displayed at the beginning of the game. + * + * @return a string that is displayed at the beginning. It should be not longer than 30 characters. + */ + protected String getStartupMessage() { + return "Box-Level!"; + } +} + + + diff --git a/GameProject/src/playground/Playground.java b/GameProject/src/playground/Playground.java index 6346d60..f2e663a 100644 --- a/GameProject/src/playground/Playground.java +++ b/GameProject/src/playground/Playground.java @@ -76,7 +76,6 @@ public abstract class Playground { /** * Adds a graphics object to a level. * - * @param o GameObject The object to be added */ public void addObjectNow(GameObject o) { gameObjects.put(o.getId(), o);