From aa617adc65722dba17e7618e5be7f69ac2ecb1ea Mon Sep 17 00:00:00 2001 From: agreiner Date: Thu, 8 Apr 2021 15:56:26 +0200 Subject: [PATCH] Praktikum 3 --- .idea/uiDesigner.xml | 124 ++++++++++++++++++ .../src/superpangworld/LevelLabel.java | 77 +++++++++++ .../src/superpangworld/LevelProgressBar.java | 68 ++++++++++ .../src/superpangworld/Overlay.java | 2 - 4 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 .idea/uiDesigner.xml create mode 100644 SuperPangWorld/src/superpangworld/LevelLabel.java create mode 100644 SuperPangWorld/src/superpangworld/LevelProgressBar.java delete mode 100644 SuperPangWorld/src/superpangworld/Overlay.java diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SuperPangWorld/src/superpangworld/LevelLabel.java b/SuperPangWorld/src/superpangworld/LevelLabel.java new file mode 100644 index 0000000..0e17223 --- /dev/null +++ b/SuperPangWorld/src/superpangworld/LevelLabel.java @@ -0,0 +1,77 @@ +package superpangworld; + +import java.awt.*; + +/** + * The progress bar of a level. + */ +public class LevelProgressBar { + + /** The position of the progress bar */ + private Position position; + /** The color of the progress bar */ + private final Color color; + /** The size of the progress bar */ + private final double size; + /** The width of the progress bar */ + private final double width; + /** The height of the progress bar */ + private final double height; + /** The GameView to display the progress bar*/ + private final GameView gameView; + /** The progress of the level ranging from 0 to 100 */ + private int levelProgress; + /** The top and bottom border of the progress bar */ + private final static String PROGRESS_BAR_BORDER = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n"; + + /** + * Create a progress bar with default values. + * @param gameView the {@link GameView} to display the progress bar + */ + public LevelProgressBar(GameView gameView){ + color = Color.BLUE; + size = 3; + width = size * 101; + height = size * 8; + levelProgress = 30; + this.gameView = gameView; + position = new Position(GameView.WIDTH/2 - (width/2),GameView.HEIGHT-height); + } + + /** + * Draws the level progress bar onto the canvas of the {@link GameView}. + */ + public void addToCanvas(){ + String pixelArt = PROGRESS_BAR_BORDER; + String progressBarMiddle = getProgressBarMiddle(levelProgress); + pixelArt += progressBarMiddle.repeat(6); + pixelArt += PROGRESS_BAR_BORDER; + + gameView.addBlockImageToCanvas(pixelArt, position.x, position.y,size, 0); + } + + @Override + public String toString() { + return "Harpoon:" +position.toString(); + } + + /** + * Set the progress of the level. + * @param levelProgress the progress + */ + public void setLevelProgress(int levelProgress){ + this.levelProgress = levelProgress; + } + + /** + * Create the middle part of the level progress bar + * @param progress the progress to display + * @return the pixel art representing the middle part of the progress bar + */ + private String getProgressBarMiddle(int progress){ + String progressbarMiddle = "W"; + progressbarMiddle += "B".repeat(progress)+" ".repeat(100-progress); + progressbarMiddle += "W\n"; + return progressbarMiddle; + } +} diff --git a/SuperPangWorld/src/superpangworld/LevelProgressBar.java b/SuperPangWorld/src/superpangworld/LevelProgressBar.java new file mode 100644 index 0000000..35f9409 --- /dev/null +++ b/SuperPangWorld/src/superpangworld/LevelProgressBar.java @@ -0,0 +1,68 @@ +package superpangworld; + +import java.awt.*; + +/** + * The progress of a level. + */ +public class LevelProgress { + + private final static String HARPOON = + " B \n"+ + " BBB \n"+ + " kkkkk \n"+ + " k kkk k\n"+ + " k kkk k\n"; + + /** The position of the harpoon */ + private Position position; + /** The speed of the harpune in pixel per tick */ + private final double speedInPixel; + /** The color of the harpoon */ + private final Color color; + /** The size of the harpoon */ + private final double size; + /** The rotation of the harpoon */ + private final double rotation; + /** The width of the harpoon */ + private final double width; + /** The height of the harpoon */ + private final double height; + /** The GameView to display the harpoon*/ + private final GameView gameView; + + /** + * Create a harpoon with default values + * @param gameView the {@link GameView} to display the bubble + */ + public LevelProgress(GameView gameView){ + color = Color.BLUE; + position = new Position(300,300); + speedInPixel = 10; + size = 3; + width = size * 11; + height = size * 11; + rotation = 0; + + this.gameView = gameView; + } + + /** + * Zeichnet die Blase auf die {@link GameView}. + */ + public void addToCanvas(){ + gameView.addBlockImageToCanvas(HARPOON, position.x, position.y,size, rotation); + } + + @Override + public String toString() { + return "Harpoon:" +position.toString(); + } + + /** + * Bewegt die Harpune einen Schritt weiter. + */ + public void updatePosition(){ + position.up(speedInPixel); + } +} diff --git a/SuperPangWorld/src/superpangworld/Overlay.java b/SuperPangWorld/src/superpangworld/Overlay.java deleted file mode 100644 index d0f30b9..0000000 --- a/SuperPangWorld/src/superpangworld/Overlay.java +++ /dev/null @@ -1,2 +0,0 @@ -package superpangworld;public class Overlay { -}