Class GameManager
java.lang.Object
model.game.GameManager
Central controller for the entire game, managing flow from start to finish.
The UI communicates with GameManager via method calls and receives events back through GameEventListener.
Flow ของเกม:
startGame() → selectCharacter(1) → selectCharacter(2) → [MAP_PHASE] movePlayer(1/2, row, col) ซ้ำ ๆ → [BATTLE_PHASE] submitBattleAction(1/2, action) ซ้ำ ๆ → [GAME_OVER]
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BattleManagerCurrent battle manager (null if not in a battle).private GameEventListenerListener registered by the UI to receive events.private MapGridCurrent map.private intCurrent map round.private booleanWhether player 1 has moved this round.private booleanWhether player 2 has moved this round.private CellThe goblin cell currently being fought (used to remove the goblin after the battle).private PlayerPlayer 1.private PlayerPlayer 2.private CharacterTypeCharacter type selected by player 1.private CharacterTypeCharacter type selected by player 2.private GameStateCurrent game state.private ZoneManagerShrinking zone system. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidChecks whether any player has died from zone damage and handles game over if so.private voidEnds a map round: increments the round counter, checks for zone shrink, applies zone damage, and checks for deaths.getMap()intgetState()private voidhandleBattleOver(BattleResult result) Handles the outcome after a battle ends: removes the goblin from the map and distributes a tome or triggers game over.voidmovePlayer(int playerIndex, int newRow, int newCol) Moves a player to the specified cell after validating the move.voidselectCharacter(int playerIndex, CharacterType type) Selects a character for the given player.voidsetListener(GameEventListener listener) Registers the listener that will receive events from GameManager.private voidChanges the game state and notifies the listener.private voidstartBattle(Entity entityA, Entity entityB, BattleManager.BattleMode mode) Starts a new battle between entityA and entityB.voidStarts a new game by loading a random map and navigating to the character selection screen.voidsubmitBattleAction(int playerIndex, BattleAction action) Submits a battle action from a player.
-
Field Details
-
state
Current game state. -
player1
Player 1. -
player2
Player 2. -
selectedType1
Character type selected by player 1. -
selectedType2
Character type selected by player 2. -
map
Current map. -
zoneManager
Shrinking zone system. -
battleManager
Current battle manager (null if not in a battle). -
mapRound
private int mapRoundCurrent map round. -
p1MovedThisRound
private boolean p1MovedThisRoundWhether player 1 has moved this round. -
p2MovedThisRound
private boolean p2MovedThisRoundWhether player 2 has moved this round. -
pendingGoblinCell
The goblin cell currently being fought (used to remove the goblin after the battle). -
listener
Listener registered by the UI to receive events.
-
-
Constructor Details
-
GameManager
public GameManager()Creates a new GameManager, starting at MAIN_MENU.
-
-
Method Details
-
setListener
Registers the listener that will receive events from GameManager.- Parameters:
listener- UI component implementing GameEventListener
-
startGame
public void startGame()Starts a new game by loading a random map and navigating to the character selection screen. -
selectCharacter
Selects a character for the given player. Once both players have selected, the game automatically enters MAP_PHASE.- Parameters:
playerIndex- Player number (1 or 2)type- The chosen character type
-
movePlayer
public void movePlayer(int playerIndex, int newRow, int newCol) Moves a player to the specified cell after validating the move. Items are picked up automatically; landing on a Goblin or the other player starts a battle.- Parameters:
playerIndex- Player number (1 or 2)newRow- Destination rownewCol- Destination column
-
submitBattleAction
Submits a battle action from a player. Once both sides have submitted, the turn resolves automatically.- Parameters:
playerIndex- Player number (1 or 2)action- The chosen action
-
startBattle
Starts a new battle between entityA and entityB.- Parameters:
entityA- Entity on side AentityB- Entity on side Bmode- PvP or vs Goblin mode
-
handleBattleOver
Handles the outcome after a battle ends: removes the goblin from the map and distributes a tome or triggers game over.- Parameters:
result- The battle result
-
endMapRound
private void endMapRound()Ends a map round: increments the round counter, checks for zone shrink, applies zone damage, and checks for deaths. -
checkGameOver
private void checkGameOver()Checks whether any player has died from zone damage and handles game over if so. -
setState
Changes the game state and notifies the listener.- Parameters:
newState- The new state
-
getState
- Returns:
- Current game state.
-
getPlayer1
- Returns:
- Player 1.
-
getPlayer2
- Returns:
- Player 2.
-
getMap
- Returns:
- Current map.
-
getZoneManager
- Returns:
- The ZoneManager for this game
-
getBattleManager
- Returns:
- Current BattleManager (null if not in a battle)
-
getMapRound
public int getMapRound()- Returns:
- Current map round.
-