Minor changes
This commit is contained in:
@ -99,12 +99,10 @@ public class Ghost extends BaseAnimated {
|
||||
|
||||
private void updatePosition(PacMan pacman, GameMap map) {
|
||||
if (map.isAligned(new Point((int) position.x, (int) position.y))) {
|
||||
log.info("Evaluating possible directions");
|
||||
prevDirection = direction;
|
||||
direction = chooseDirection(
|
||||
prioritize(collisionChecker.calculateDirectionAlternatives(position)),
|
||||
currentStrategy.chooseTarget(this, pacman, map));
|
||||
log.info("selecting direction {}", direction);
|
||||
}
|
||||
|
||||
moveTo(getNewPosition());
|
||||
|
||||
@ -4,7 +4,7 @@ import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import se.urmo.game.state.GameStateManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
@Slf4j
|
||||
public class Game implements Runnable {
|
||||
@ -22,7 +22,7 @@ public class Game implements Runnable {
|
||||
private final GamePanel gamePanel;
|
||||
|
||||
public Game() {
|
||||
this.gameStateManager = new GameStateManager(this);
|
||||
this.gameStateManager = new GameStateManager();
|
||||
this.gamePanel = new GamePanel(this, gameStateManager);
|
||||
}
|
||||
|
||||
|
||||
@ -1,22 +1,19 @@
|
||||
package se.urmo.game.state;
|
||||
|
||||
import lombok.Getter;
|
||||
import se.urmo.game.main.Game;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GameStateManager {
|
||||
private final Game game;
|
||||
private Map<GameStateType, GameState> states = new HashMap<>();
|
||||
private final Map<GameStateType, GameState> states = new HashMap<>();
|
||||
@Getter
|
||||
private GameState currentState;
|
||||
|
||||
public GameStateManager(Game game) {
|
||||
this.game = game;
|
||||
public GameStateManager() {
|
||||
GameOverState gameOverState = new GameOverState(this, new HighScoreManager());
|
||||
states.put(GameStateType.PLAYING, new PlayingState(game, this, gameOverState));
|
||||
states.put(GameStateType.PLAYING, new PlayingState(this, gameOverState));
|
||||
states.put(GameStateType.GAME_OVER, gameOverState);
|
||||
setState(GameStateType.PLAYING);
|
||||
}
|
||||
|
||||
@ -7,20 +7,19 @@ import se.urmo.game.collision.GhostCollisionChecker;
|
||||
import se.urmo.game.entities.ghost.Ghost;
|
||||
import se.urmo.game.entities.ghost.GhostMode;
|
||||
import se.urmo.game.entities.pacman.PacMan;
|
||||
import se.urmo.game.main.Game;
|
||||
import se.urmo.game.map.GameMap;
|
||||
import se.urmo.game.map.MapTile;
|
||||
import se.urmo.game.map.TileType;
|
||||
import se.urmo.game.util.Direction;
|
||||
import se.urmo.game.util.GameFonts;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
@Slf4j
|
||||
public class PlayingState implements GameState {
|
||||
public static final int REMAINING_LIVES = 0;
|
||||
private final Game game;
|
||||
private final GameStateManager gameStateManager;
|
||||
private final GameOverState gameOverState;
|
||||
|
||||
@ -48,8 +47,7 @@ public class PlayingState implements GameState {
|
||||
private long phaseStartMs = System.currentTimeMillis();
|
||||
private boolean deathInProgress;
|
||||
|
||||
public PlayingState(Game game, GameStateManager gameStateManager, GameOverState gameOverState) {
|
||||
this.game = game;
|
||||
public PlayingState(GameStateManager gameStateManager, GameOverState gameOverState) {
|
||||
this.gameStateManager = gameStateManager;
|
||||
this.gameOverState = gameOverState;
|
||||
this.map = new GameMap("maps/map1.csv");
|
||||
@ -147,7 +145,8 @@ public class PlayingState implements GameState {
|
||||
// Phase overlays
|
||||
switch (phase) {
|
||||
case READY -> drawCenterText(g, "READY!");
|
||||
case LEVEL_COMPLETE -> drawCenterText(g, "LEVEL COMPLETE!");
|
||||
case LEVEL_COMPLETE ->
|
||||
drawCenterText(g, "LEVEL " + levelManager.getCurrentLevel().getLevel() + " COMPLETE!");
|
||||
case LIFE_LOST -> drawCenterText(g, "LIFE LOST");
|
||||
default -> { /* no overlay */ }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user