Class BoardScene
java.lang.Object
application.BoardScene
Map phase screen displaying the 11x11 grid along with HP bars for both players
and an inventory panel on each side.
Whenever the model changes, GameController calls methods here to update the UI.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate javafx.scene.image.ImageBackground image for the map phase.private javafx.scene.media.MediaPlayerBGM media player.private javafx.scene.image.ImageImage for chest (item) tiles.private static final doubleSize of player/goblin sprites in pixels.private static final doubleX offset to centre the sprite within a tile.private static final doubleY offset to centre the sprite within a tile.private javafx.scene.layout.PaneLayer for placing player and goblin sprites on top of the grid.private javafx.scene.layout.GridPaneGrid containing all tiles.private javafx.scene.image.ImageInventory slot image.private javafx.scene.image.ImageImage for lava (shrinking zone) tiles.private javafx.scene.layout.StackPaneRoot container that stacks the background and layout.private javafx.scene.layout.StackPaneStackPane layering the gridPane and entityPane.private javafx.scene.image.ImageImage for normal tiles.private javafx.scene.text.TextTemporary notification text that fades out automatically after 2.5 seconds.private final StringClass of P1 (e.g.private javafx.scene.control.ProgressBarHP bar for P1.private javafx.scene.image.ImageViewSprite for P1 on the map.private javafx.scene.layout.VBoxInventory panel for P1 on the left side.private final StringName of P1.private javafx.scene.text.TextStat text for P1.private final StringClass of P2.private javafx.scene.control.ProgressBarHP bar for P2.private javafx.scene.image.ImageViewSprite for P2 on the map.private javafx.scene.layout.VBoxInventory panel for P2 on the right side.private final StringName of P2.private javafx.scene.text.TextStat text for P2.private javafx.scene.image.ImageImage for river tiles.private javafx.scene.layout.BorderPaneMain layout.private javafx.scene.text.TextText displaying the current round.private javafx.scene.SceneMain JavaFX Scene for this screen.private javafx.scene.image.ImageImage for rock tiles.private static final intSize of each tile on the map in pixels.private javafx.scene.image.ImageImage for tree tiles.private javafx.scene.text.TextText displaying the current turn.private javafx.scene.image.ImageVS image for the top panel.private javafx.scene.media.AudioClipWalking sound effect. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate javafx.scene.layout.HBoxCreates the bottom bar displaying the current turn and round.private javafx.scene.layout.VBoxcreateInventoryPanel(String title, String cls, String[] items) Creates an inventory panel for one player showing slots up to maxInventorySize.private javafx.scene.layout.HBoxcreateProfile(String name, String cls, double hp, double maxHp, int atk, int def, boolean isLeft) Creates a profile card for one player (avatar + name + HP bar + stats).private javafx.scene.layout.BorderPanecreateTopPanel(String n1, String c1, double hp1, double maxHp1, int atk1, int def1, String n2, String c2, double hp2, double maxHp2, int atk2, int def2) Creates the top panel showing HP bars and stats for both players.private StringResolves the image path for a character based on class name and action.javafx.scene.media.MediaPlayerReturns the BGM MediaPlayer.javafx.scene.ScenegetScene()Returns the Scene for this screen.private voidinitPlayerSprites(String p1Class, String p2Class) create sprite for P1 and P2 on mapprivate voidLoads all tile and UI images.private voidLoad Walking sound effect and BGMvoidmovePlayer(int playerNum, int targetCol, int targetRow, String direction) Moves a player's sprite to a new position with animation and sound.private javafx.scene.image.ImageViewoverlay(javafx.scene.image.Image img) Creates a tile-sized ImageView to overlay on a base tile (e.g.voidRe-renders the entire map from the model, used when the map changes.private voidrenderFromModel(MapGrid map) Re-renders the entire map from the given model, used when the map changes (item pickup, zone shrink).voidsetRoundText(String text) Updates the round text at the bottom.voidsetTurnText(String text) Updates the turn text at the bottom.voidshowNotification(String msg) Shows a temporary on-screen notification that disappears automatically after 2.5 seconds.voidupdateInventory(int playerNum, String[] items) Updates a player's inventory panel with the latest item list.voidupdatePlayerStats(int playerNum, double hp, double maxHp, int atk, int def) Updates the HP bar and stat text for a player.
-
Field Details
-
TILE_SIZE
private static final int TILE_SIZESize of each tile on the map in pixels.- See Also:
-
ENTITY_SIZE
private static final double ENTITY_SIZESize of player/goblin sprites in pixels.- See Also:
-
ENTITY_X_OFF
private static final double ENTITY_X_OFFX offset to centre the sprite within a tile.- See Also:
-
ENTITY_Y_OFF
private static final double ENTITY_Y_OFFY offset to centre the sprite within a tile.- See Also:
-
scene
private javafx.scene.Scene sceneMain JavaFX Scene for this screen. -
mainRoot
private javafx.scene.layout.StackPane mainRootRoot container that stacks the background and layout. -
rootPane
private javafx.scene.layout.BorderPane rootPaneMain layout. -
mapStack
private javafx.scene.layout.StackPane mapStackStackPane layering the gridPane and entityPane. -
gridPane
private javafx.scene.layout.GridPane gridPaneGrid containing all tiles. -
entityPane
private javafx.scene.layout.Pane entityPaneLayer for placing player and goblin sprites on top of the grid. -
p1HpBar
private javafx.scene.control.ProgressBar p1HpBarHP bar for P1. -
p2HpBar
private javafx.scene.control.ProgressBar p2HpBarHP bar for P2. -
p1StatText
private javafx.scene.text.Text p1StatTextStat text for P1. -
p2StatText
private javafx.scene.text.Text p2StatTextStat text for P2. -
p1InventoryBox
private javafx.scene.layout.VBox p1InventoryBoxInventory panel for P1 on the left side. -
p2InventoryBox
private javafx.scene.layout.VBox p2InventoryBoxInventory panel for P2 on the right side. -
p1ImageView
private javafx.scene.image.ImageView p1ImageViewSprite for P1 on the map. -
p2ImageView
private javafx.scene.image.ImageView p2ImageViewSprite for P2 on the map. -
turnText
private javafx.scene.text.Text turnTextText displaying the current turn. -
roundText
private javafx.scene.text.Text roundTextText displaying the current round. -
notificationText
private javafx.scene.text.Text notificationTextTemporary notification text that fades out automatically after 2.5 seconds. -
normalImg
private javafx.scene.image.Image normalImgImage for normal tiles. -
stoneImg
private javafx.scene.image.Image stoneImgImage for rock tiles. -
treeImg
private javafx.scene.image.Image treeImgImage for tree tiles. -
riverImg
private javafx.scene.image.Image riverImgImage for river tiles. -
chestImg
private javafx.scene.image.Image chestImgImage for chest (item) tiles. -
lavaImg
private javafx.scene.image.Image lavaImgImage for lava (shrinking zone) tiles. -
vsImg
private javafx.scene.image.Image vsImgVS image for the top panel. -
inventoryImg
private javafx.scene.image.Image inventoryImgInventory slot image. -
bgImg
private javafx.scene.image.Image bgImgBackground image for the map phase. -
walkSound
private javafx.scene.media.AudioClip walkSoundWalking sound effect. -
bgmPlayer
private javafx.scene.media.MediaPlayer bgmPlayerBGM media player. -
p1Name
Name of P1. -
p2Name
Name of P2. -
p1Class
Class of P1 (e.g. "knight"). -
p2Class
Class of P2.
-
-
Constructor Details
-
BoardScene
public BoardScene(String p1Class, String p2Class, MapGrid initialMap, String p1Name, String p2Name, double p1Hp, double p1MaxHp, int p1Atk, int p1Def, double p2Hp, double p2MaxHp, int p2Atk, int p2Def) Creates the Board Scene with the initial map and player stat data.- Parameters:
p1Class- Class of P1p2Class- Class of P2.initialMap- Initial map to displayp1Name- Name of P1.p2Name- Name of P2.p1Hp- Current HP of P1p1MaxHp- Maximum HP of P1p1Atk- ATK of P1p1Def- DEF of P1p2Hp- Current HP of P2p2MaxHp- Maximum HP of P2p2Atk- ATK of P2p2Def- DEF of P2
-
-
Method Details
-
loadImages
private void loadImages()Loads all tile and UI images. -
loadSounds
private void loadSounds()Load Walking sound effect and BGM -
initPlayerSprites
-
renderFromModel
Re-renders the entire map from the given model, used when the map changes (item pickup, zone shrink).- Parameters:
map- Current map from the model
-
overlay
private javafx.scene.image.ImageView overlay(javafx.scene.image.Image img) Creates a tile-sized ImageView to overlay on a base tile (e.g. rock, tree).- Parameters:
img- Image to overlay- Returns:
- A resized ImageView
-
createTopPanel
-
createProfile
private javafx.scene.layout.HBox createProfile(String name, String cls, double hp, double maxHp, int atk, int def, boolean isLeft) Creates a profile card for one player (avatar + name + HP bar + stats).- Parameters:
name- Player namecls- Character classhp- Current HPmaxHp- Maximum HPatk- Attack powerdef- DefenseisLeft-trueif this is P1 (left side)- Returns:
- The profile card as an HBox
-
createBottomBar
private javafx.scene.layout.HBox createBottomBar()Creates the bottom bar displaying the current turn and round.- Returns:
- The bottom bar as an HBox
-
createInventoryPanel
Creates an inventory panel for one player showing slots up to maxInventorySize.- Parameters:
title- Panel titlecls- Player's class (determines the number of slots)items- Array of item names currently held- Returns:
- The inventory panel as a VBox
-
dirImg
-
getScene
public javafx.scene.Scene getScene()Returns the Scene for this screen.- Returns:
- The Board Scene
-
getBgmPlayer
public javafx.scene.media.MediaPlayer getBgmPlayer()Returns the BGM MediaPlayer.- Returns:
- The MediaPlayer
-
movePlayer
Moves a player's sprite to a new position with animation and sound.- Parameters:
playerNum- Player number (1 or 2)targetCol- Destination columntargetRow- Destination rowdirection- Direction used to select the sprite, e.g. "up", "down", "left", "right"
-
updatePlayerStats
public void updatePlayerStats(int playerNum, double hp, double maxHp, int atk, int def) Updates the HP bar and stat text for a player.- Parameters:
playerNum- Player number (1 or 2)hp- Current HPmaxHp- Maximum HPatk- Attack powerdef- Defense
-
updateInventory
Updates a player's inventory panel with the latest item list.- Parameters:
playerNum- Player number (1 or 2)items- Array of current item names
-
refreshMapFromModel
Re-renders the entire map from the model, used when the map changes.- Parameters:
map- Current map from the model
-
setTurnText
Updates the turn text at the bottom.- Parameters:
text- Text to display, e.g. "P1 Turn (WASD)"
-
setRoundText
Updates the round text at the bottom.- Parameters:
text- Text to display, e.g. "Round 3"
-
showNotification
Shows a temporary on-screen notification that disappears automatically after 2.5 seconds.- Parameters:
msg- Message to display
-