Refactor Pacman state handling to use setState method.
Centralized Pacman state transitions into a new `setState` method to improve clarity and consistency. Removed redundant `reset` and `startDeathAnimation` methods, merging their logic into state management. Adjusted game state transitions to align with the new approach.
This commit is contained in:
@ -93,7 +93,7 @@ public class PlayingState implements GameState {
|
||||
case LIFE_LOST -> {
|
||||
// Freeze, then reset round (keep dot state)
|
||||
if (phaseElapsed() >= LIFE_LOST_MS) {
|
||||
pacman.reset();
|
||||
pacman.setState(PacMan.PacmanState.ALIVE);
|
||||
deathInProgress = false;
|
||||
ghostManager.setFrozen(false);
|
||||
setPhase(RoundPhase.READY);
|
||||
@ -111,7 +111,7 @@ public class PlayingState implements GameState {
|
||||
map.reset();
|
||||
ghostManager.reset();
|
||||
fruitManager.reset();
|
||||
pacman.reset();
|
||||
pacman.setState(PacMan.PacmanState.ALIVE);
|
||||
dotsEaten = 0;
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ public class PlayingState implements GameState {
|
||||
ghost.setMode(GhostMode.EATEN);
|
||||
} else {
|
||||
ghostManager.setFrozen(true);
|
||||
pacman.startDeathAnimation();
|
||||
pacman.setState(PacMan.PacmanState.DYING);
|
||||
deathInProgress = true;
|
||||
// Pac-Man loses a life
|
||||
lives--;
|
||||
|
||||
Reference in New Issue
Block a user