Aufgaben 5
This commit is contained in:
parent
b4d721cdb1
commit
f8b69c9e16
@ -1,10 +1,10 @@
|
|||||||
package de.thdeg.greiner.superpangworld.game;
|
package de.thdeg.greiner.superpangworld.game;
|
||||||
|
|
||||||
import de.thdeg.greiner.superpangworld.objects.*;
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
import de.thdeg.greiner.superpangworld.graphics.*;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.security.Key;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/** Der Manager zur Verwaltung der Spielschleife. */
|
/** Der Manager zur Verwaltung der Spielschleife. */
|
||||||
@ -20,7 +20,7 @@ public class GameLoopManager {
|
|||||||
private LevelLabel levelLabel;
|
private LevelLabel levelLabel;
|
||||||
private ScoreLabel scoreLabel;
|
private ScoreLabel scoreLabel;
|
||||||
|
|
||||||
private Spielfigur spielfigur;
|
private Player player;
|
||||||
|
|
||||||
/** Erzeugt den GameLoopManager mit Standardwerten. */
|
/** Erzeugt den GameLoopManager mit Standardwerten. */
|
||||||
public GameLoopManager() {
|
public GameLoopManager() {
|
||||||
@ -36,7 +36,7 @@ public class GameLoopManager {
|
|||||||
this.levelLabel = new LevelLabel(gameView);
|
this.levelLabel = new LevelLabel(gameView);
|
||||||
this.scoreLabel = new ScoreLabel(gameView);
|
this.scoreLabel = new ScoreLabel(gameView);
|
||||||
|
|
||||||
this.spielfigur = new Spielfigur(gameView);
|
this.player = new Player(gameView);
|
||||||
|
|
||||||
gameView.setColorForBlockImage('k',Color.LIGHT_GRAY);
|
gameView.setColorForBlockImage('k',Color.LIGHT_GRAY);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ public class GameLoopManager {
|
|||||||
levelLabel.addToCanvas();
|
levelLabel.addToCanvas();
|
||||||
scoreLabel.addToCanvas();
|
scoreLabel.addToCanvas();
|
||||||
|
|
||||||
spielfigur.addToCanvas();
|
player.addToCanvas();
|
||||||
|
|
||||||
gameView.printCanvas();
|
gameView.printCanvas();
|
||||||
}
|
}
|
||||||
@ -64,15 +64,15 @@ public class GameLoopManager {
|
|||||||
void updateUserInputs() {
|
void updateUserInputs() {
|
||||||
Integer[] gedruekteTasten = gameView.getKeyCodesOfCurrentlyPressedKeys();
|
Integer[] gedruekteTasten = gameView.getKeyCodesOfCurrentlyPressedKeys();
|
||||||
if(Arrays.stream(gedruekteTasten).anyMatch(k -> k == KeyEvent.VK_SPACE)){
|
if(Arrays.stream(gedruekteTasten).anyMatch(k -> k == KeyEvent.VK_SPACE)){
|
||||||
spielfigur.shoot();
|
player.shoot();
|
||||||
}
|
}
|
||||||
for (int keyCode : gedruekteTasten) {
|
for (int keyCode : gedruekteTasten) {
|
||||||
switch(keyCode) {
|
switch(keyCode) {
|
||||||
case KeyEvent.VK_LEFT:
|
case KeyEvent.VK_LEFT:
|
||||||
spielfigur.left();
|
player.left();
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_RIGHT:
|
case KeyEvent.VK_RIGHT:
|
||||||
spielfigur.right();
|
player.right();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package de.thdeg.greiner.superpangworld.game;
|
package de.thdeg.greiner.superpangworld.gameview;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
@ -0,0 +1,19 @@
|
|||||||
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The background for the game.
|
||||||
|
*/
|
||||||
|
public class Background extends GameObject{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a background object.
|
||||||
|
*
|
||||||
|
* @param gameView the gameView
|
||||||
|
*/
|
||||||
|
protected Background(GameView gameView) {
|
||||||
|
super(gameView);
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
package de.thdeg.greiner.superpangworld.objects;
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
import de.thdeg.greiner.superpangworld.game.GameView;
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
@ -1,6 +1,6 @@
|
|||||||
package de.thdeg.greiner.superpangworld.objects;
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
import de.thdeg.greiner.superpangworld.game.GameView;
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic game object.
|
* A basic game object.
|
@ -1,8 +1,6 @@
|
|||||||
package de.thdeg.greiner.superpangworld.objects;
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
import de.thdeg.greiner.superpangworld.game.GameView;
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A harpoon which can be fired upwards by the player.
|
* A harpoon which can be fired upwards by the player.
|
@ -0,0 +1,18 @@
|
|||||||
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rare hexagonal bubble.
|
||||||
|
*/
|
||||||
|
public class HexagonalBubble extends Bubble{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a hexagonal bubble with default values.
|
||||||
|
*
|
||||||
|
* @param gameView the {@link GameView} to display the bubble
|
||||||
|
*/
|
||||||
|
public HexagonalBubble(GameView gameView) {
|
||||||
|
super(gameView);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package de.thdeg.greiner.superpangworld.objects;
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
import de.thdeg.greiner.superpangworld.game.GameView;
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
@ -1,8 +1,6 @@
|
|||||||
package de.thdeg.greiner.superpangworld.objects;
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
import de.thdeg.greiner.superpangworld.game.GameView;
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The progress bar of a level.
|
* The progress bar of a level.
|
@ -0,0 +1,17 @@
|
|||||||
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The icon to display the remaining lives.
|
||||||
|
*/
|
||||||
|
public class LivesIcon extends GameObject{
|
||||||
|
/**
|
||||||
|
* Create a game object with default values.
|
||||||
|
*
|
||||||
|
* @param gameView the gameView
|
||||||
|
*/
|
||||||
|
protected LivesIcon(GameView gameView) {
|
||||||
|
super(gameView);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The label for the remaining lives count.
|
||||||
|
*/
|
||||||
|
public class LivesLabe extends GameObject{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a lives label with default values.
|
||||||
|
*
|
||||||
|
* @param gameView the gameView
|
||||||
|
*/
|
||||||
|
protected LivesLabe(GameView gameView) {
|
||||||
|
super(gameView);
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,20 @@
|
|||||||
package de.thdeg.greiner.superpangworld.objects;
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
import de.thdeg.greiner.superpangworld.game.GameView;
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The game character controlled by the player.
|
* The game character controlled by the player.
|
||||||
*/
|
*/
|
||||||
public class Spielfigur extends GameObject{
|
public class Player extends GameObject{
|
||||||
|
|
||||||
/** Flag, if the player is shooting */
|
/** Flag, if the player is shooting */
|
||||||
private boolean shooting;
|
private boolean shooting;
|
||||||
/** Debug flag, to display X and O or the real image */
|
/** Debug flag, to display X and O or the real image */
|
||||||
private static boolean SHOW_X = false;
|
private static final boolean SHOW_X = false;
|
||||||
/** The pixel art of the character */
|
/** The pixel art of the character */
|
||||||
private static String SPIELFIGUR =
|
private static final String SPIELFIGUR =
|
||||||
" kkk \n"+
|
" kkk \n"+
|
||||||
" BBBBk \n"+
|
" BBBBk \n"+
|
||||||
" BBBBBB \n"+
|
" BBBBBB \n"+
|
||||||
@ -37,7 +37,7 @@ public class Spielfigur extends GameObject{
|
|||||||
* Create the game character with default values
|
* Create the game character with default values
|
||||||
* @param gameView the {@link GameView} to display the character
|
* @param gameView the {@link GameView} to display the character
|
||||||
*/
|
*/
|
||||||
public Spielfigur(GameView gameView){
|
public Player(GameView gameView){
|
||||||
super(gameView);
|
super(gameView);
|
||||||
position.setTo(GameView.WIDTH/2, GameView.HEIGHT/2);
|
position.setTo(GameView.WIDTH/2, GameView.HEIGHT/2);
|
||||||
shooting = false;
|
shooting = false;
|
@ -1,4 +1,4 @@
|
|||||||
package de.thdeg.greiner.superpangworld.objects;
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die Position eines Objekts auf einem Fenster anhand zweidimensionaler Koordinaten.
|
* Die Position eines Objekts auf einem Fenster anhand zweidimensionaler Koordinaten.
|
@ -0,0 +1,19 @@
|
|||||||
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The classic red, round bubble.
|
||||||
|
*/
|
||||||
|
public class RoundBubble extends Bubble{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a round bubble with default values.
|
||||||
|
*
|
||||||
|
* @param gameView the {@link GameView} to display the bubble
|
||||||
|
*/
|
||||||
|
public RoundBubble(GameView gameView) {
|
||||||
|
super(gameView);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package de.thdeg.greiner.superpangworld.objects;
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
import de.thdeg.greiner.superpangworld.game.GameView;
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
package de.thdeg.greiner.superpangworld.graphics;
|
||||||
|
|
||||||
|
import de.thdeg.greiner.superpangworld.gameview.GameView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The green bubble with special abilities.
|
||||||
|
*/
|
||||||
|
public class SpecialBubble extends Bubble{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a special bubble with default values.
|
||||||
|
*
|
||||||
|
* @param gameView the {@link GameView} to display the bubble
|
||||||
|
*/
|
||||||
|
public SpecialBubble(GameView gameView) {
|
||||||
|
super(gameView);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user