Aufgaben 7

This commit is contained in:
Andreas Greiner 2021-05-01 14:00:26 +02:00
parent e8cfbb70ba
commit f0d73b7cf0
31 changed files with 66 additions and 27 deletions

View File

@ -3,6 +3,7 @@ package de.thdeg.greiner.superpangworld.game.managers;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.Bubble; import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject; import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject;
import de.thdeg.greiner.superpangworld.graphics.immovable.*; import de.thdeg.greiner.superpangworld.graphics.immovable.*;
import de.thdeg.greiner.superpangworld.graphics.moveable.*; import de.thdeg.greiner.superpangworld.graphics.moveable.*;
@ -65,8 +66,7 @@ class GameObjectManager {
gameObjects.add(player); gameObjects.add(player);
gameObjects.forEach(gameObject ->{ gameObjects.forEach(gameObject ->{
gameObject.updatePosition(); gameObject.update();
gameObject.updateStatus();
gameObject.addToCanvas(); gameObject.addToCanvas();
}); });
} }

View File

@ -18,7 +18,7 @@ public class GamePlayManager {
private GameView gameView; private GameView gameView;
/** The manager, which handles the game objects */ /** The manager, which handles the game objects */
private GameObjectManager gameObjectManager; private GameObjectManager gameObjectManager;
/** Flag, if the gameobjects were already deleted once */ /** Flag, if the game objects were already deleted once */
private boolean listHasBeenDeleted; private boolean listHasBeenDeleted;
/** Generator for random values */ /** Generator for random values */
private Random random; private Random random;

View File

@ -5,7 +5,7 @@ import de.thdeg.greiner.superpangworld.gameview.GameView;
/** /**
* A Bubble, which moves around on the screen and can be shot by the player. * A Bubble, which moves around on the screen and can be shot by the player.
*/ */
public class Bubble extends GameObject { public abstract class Bubble extends GameObject implements MovingGameObject{
/** Flag, if the bubble flies from left to right */ /** Flag, if the bubble flies from left to right */
private boolean flyFromLeftToRight; private boolean flyFromLeftToRight;

View File

@ -35,25 +35,24 @@ public abstract class GameObject {
position = new Position(0,0); position = new Position(0,0);
} }
/**
* Update the position of the game object.
*/
public void updatePosition(){
}
/** /**
* Add the game object to the canvas. * Add the game object to the canvas.
*/ */
public void addToCanvas(){ public abstract void addToCanvas();
}
/** /**
* Updates the game object's status. * Updates the game object's status.
*/ */
public void updateStatus(){ protected abstract void updateStatus();
/**
* Update the status and the position is applicable.
*/
public void update(){
if(this instanceof MovingGameObject){
((MovingGameObject)this).updatePosition();
}
updateStatus();
} }
/** /**

View File

@ -0,0 +1,13 @@
package de.thdeg.greiner.superpangworld.graphics.base;
/**
* The interface for moving game objects.
*/
public interface MovingGameObject {
/**
* Update the position of a game object.
*/
public void updatePosition();
}

View File

@ -43,4 +43,9 @@ public class Background extends GameObject {
public void addToCanvas() { public void addToCanvas() {
gameView.addBlockImageToCanvas(pixelArt,position.x,position.y,size, rotation); gameView.addBlockImageToCanvas(pixelArt,position.x,position.y,size, rotation);
} }
@Override
public void updateStatus() {
}
} }

View File

@ -35,8 +35,8 @@ public class LevelLabel extends GameObject {
} }
@Override @Override
public void updatePosition() { public void updateStatus() {
super.updatePosition();
} }
@Override @Override

View File

@ -40,8 +40,8 @@ public class LevelProgressBar extends GameObject {
} }
@Override @Override
public void updatePosition() { public void updateStatus() {
super.updatePosition();
} }
@Override @Override

View File

@ -38,4 +38,9 @@ public class LivesIcon extends GameObject {
public void addToCanvas() { public void addToCanvas() {
gameView.addBlockImageToCanvas(ICON,position.x,position.y,size,rotation); gameView.addBlockImageToCanvas(ICON,position.x,position.y,size,rotation);
} }
@Override
public void updateStatus() {
}
} }

View File

@ -33,7 +33,7 @@ public class ScoreLabel extends GameObject {
} }
@Override @Override
public void updatePosition() { public void updateStatus() {
super.updatePosition();
} }
} }

View File

@ -3,11 +3,12 @@ package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.Bubble; import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject; import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject;
/** /**
* A harpoon which can be fired upwards by the player. * A harpoon which can be fired upwards by the player.
*/ */
public class Harpoon extends GameObject { public class Harpoon extends GameObject implements MovingGameObject {
private final static String HARPOON = private final static String HARPOON =
" B \n"+ " B \n"+

View File

@ -30,6 +30,11 @@ public class HexagonalBubble extends Bubble {
gameView.addImageToCanvas("hexagon.png",position.x,position.y,size,rotation); gameView.addImageToCanvas("hexagon.png",position.x,position.y,size,rotation);
} }
@Override
public void updateStatus() {
}
@Override @Override
public void updatePosition() { public void updatePosition() {
super.updatePosition(); super.updatePosition();

View File

@ -2,6 +2,7 @@ package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject; import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject;
import java.awt.*; import java.awt.*;
@ -48,11 +49,6 @@ public class Player extends GameObject {
speedInPixel = 5; speedInPixel = 5;
} }
@Override
public void updatePosition(){
}
@Override @Override
public void addToCanvas(){ public void addToCanvas(){
if(SHOW_X) { if(SHOW_X) {
@ -63,6 +59,11 @@ public class Player extends GameObject {
shooting = false; shooting = false;
} }
@Override
public void updateStatus() {
}
/** Moves the character to the left */ /** Moves the character to the left */
public void left(){ public void left(){
position.left(speedInPixel); position.left(speedInPixel);

View File

@ -45,4 +45,9 @@ public class RoundBubble extends Bubble {
public void addToCanvas(){ public void addToCanvas(){
gameView.addBlockImageToCanvas(RED_BUBBLE, getPosition().x, getPosition().y,size, rotation); gameView.addBlockImageToCanvas(RED_BUBBLE, getPosition().x, getPosition().y,size, rotation);
} }
@Override
public void updateStatus() {
}
} }

View File

@ -42,6 +42,11 @@ public class SpecialBubble extends Bubble {
gameView.addBlockImageToCanvas(GREEN_BUBBLE,position.x,position.y,size, rotation); gameView.addBlockImageToCanvas(GREEN_BUBBLE,position.x,position.y,size, rotation);
} }
@Override
public void updateStatus() {
}
/** /**
* Switches the active effect. * Switches the active effect.
*/ */