Minor changes

This commit is contained in:
Urban Modig
2025-09-03 00:33:07 +02:00
parent c05398201f
commit 9c0a613e4d
4 changed files with 12 additions and 18 deletions

View File

@ -99,12 +99,10 @@ public class Ghost extends BaseAnimated {
private void updatePosition(PacMan pacman, GameMap map) { private void updatePosition(PacMan pacman, GameMap map) {
if (map.isAligned(new Point((int) position.x, (int) position.y))) { if (map.isAligned(new Point((int) position.x, (int) position.y))) {
log.info("Evaluating possible directions");
prevDirection = direction; prevDirection = direction;
direction = chooseDirection( direction = chooseDirection(
prioritize(collisionChecker.calculateDirectionAlternatives(position)), prioritize(collisionChecker.calculateDirectionAlternatives(position)),
currentStrategy.chooseTarget(this, pacman, map)); currentStrategy.chooseTarget(this, pacman, map));
log.info("selecting direction {}", direction);
} }
moveTo(getNewPosition()); moveTo(getNewPosition());

View File

@ -4,7 +4,7 @@ import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import se.urmo.game.state.GameStateManager; import se.urmo.game.state.GameStateManager;
import javax.swing.*; import javax.swing.JFrame;
@Slf4j @Slf4j
public class Game implements Runnable { public class Game implements Runnable {
@ -22,7 +22,7 @@ public class Game implements Runnable {
private final GamePanel gamePanel; private final GamePanel gamePanel;
public Game() { public Game() {
this.gameStateManager = new GameStateManager(this); this.gameStateManager = new GameStateManager();
this.gamePanel = new GamePanel(this, gameStateManager); this.gamePanel = new GamePanel(this, gameStateManager);
} }

View File

@ -1,22 +1,19 @@
package se.urmo.game.state; package se.urmo.game.state;
import lombok.Getter; import lombok.Getter;
import se.urmo.game.main.Game;
import java.awt.*; import java.awt.Graphics2D;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class GameStateManager { public class GameStateManager {
private final Game game; private final Map<GameStateType, GameState> states = new HashMap<>();
private Map<GameStateType, GameState> states = new HashMap<>();
@Getter @Getter
private GameState currentState; private GameState currentState;
public GameStateManager(Game game) { public GameStateManager() {
this.game = game;
GameOverState gameOverState = new GameOverState(this, new HighScoreManager()); 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); states.put(GameStateType.GAME_OVER, gameOverState);
setState(GameStateType.PLAYING); setState(GameStateType.PLAYING);
} }

View File

@ -7,20 +7,19 @@ import se.urmo.game.collision.GhostCollisionChecker;
import se.urmo.game.entities.ghost.Ghost; import se.urmo.game.entities.ghost.Ghost;
import se.urmo.game.entities.ghost.GhostMode; import se.urmo.game.entities.ghost.GhostMode;
import se.urmo.game.entities.pacman.PacMan; import se.urmo.game.entities.pacman.PacMan;
import se.urmo.game.main.Game;
import se.urmo.game.map.GameMap; import se.urmo.game.map.GameMap;
import se.urmo.game.map.MapTile; import se.urmo.game.map.MapTile;
import se.urmo.game.map.TileType; import se.urmo.game.map.TileType;
import se.urmo.game.util.Direction; import se.urmo.game.util.Direction;
import se.urmo.game.util.GameFonts; 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; import java.awt.event.KeyEvent;
@Slf4j @Slf4j
public class PlayingState implements GameState { public class PlayingState implements GameState {
public static final int REMAINING_LIVES = 0;
private final Game game;
private final GameStateManager gameStateManager; private final GameStateManager gameStateManager;
private final GameOverState gameOverState; private final GameOverState gameOverState;
@ -48,8 +47,7 @@ public class PlayingState implements GameState {
private long phaseStartMs = System.currentTimeMillis(); private long phaseStartMs = System.currentTimeMillis();
private boolean deathInProgress; private boolean deathInProgress;
public PlayingState(Game game, GameStateManager gameStateManager, GameOverState gameOverState) { public PlayingState(GameStateManager gameStateManager, GameOverState gameOverState) {
this.game = game;
this.gameStateManager = gameStateManager; this.gameStateManager = gameStateManager;
this.gameOverState = gameOverState; this.gameOverState = gameOverState;
this.map = new GameMap("maps/map1.csv"); this.map = new GameMap("maps/map1.csv");
@ -147,7 +145,8 @@ public class PlayingState implements GameState {
// Phase overlays // Phase overlays
switch (phase) { switch (phase) {
case READY -> drawCenterText(g, "READY!"); 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"); case LIFE_LOST -> drawCenterText(g, "LIFE LOST");
default -> { /* no overlay */ } default -> { /* no overlay */ }
} }