Class BoardScene

java.lang.Object
application.BoardScene

public class BoardScene extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private javafx.scene.image.Image
    Background image for the map phase.
    private javafx.scene.media.MediaPlayer
    BGM media player.
    private javafx.scene.image.Image
    Image for chest (item) tiles.
    private static final double
    Size of player/goblin sprites in pixels.
    private static final double
    X offset to centre the sprite within a tile.
    private static final double
    Y offset to centre the sprite within a tile.
    private javafx.scene.layout.Pane
    Layer for placing player and goblin sprites on top of the grid.
    private javafx.scene.layout.GridPane
    Grid containing all tiles.
    private javafx.scene.image.Image
    Inventory slot image.
    private javafx.scene.image.Image
    Image for lava (shrinking zone) tiles.
    private javafx.scene.layout.StackPane
    Root container that stacks the background and layout.
    private javafx.scene.layout.StackPane
    StackPane layering the gridPane and entityPane.
    private javafx.scene.image.Image
    Image for normal tiles.
    private javafx.scene.text.Text
    Temporary notification text that fades out automatically after 2.5 seconds.
    private final String
    Class of P1 (e.g.
    private javafx.scene.control.ProgressBar
    HP bar for P1.
    private javafx.scene.image.ImageView
    Sprite for P1 on the map.
    private javafx.scene.layout.VBox
    Inventory panel for P1 on the left side.
    private final String
    Name of P1.
    private javafx.scene.text.Text
    Stat text for P1.
    private final String
    Class of P2.
    private javafx.scene.control.ProgressBar
    HP bar for P2.
    private javafx.scene.image.ImageView
    Sprite for P2 on the map.
    private javafx.scene.layout.VBox
    Inventory panel for P2 on the right side.
    private final String
    Name of P2.
    private javafx.scene.text.Text
    Stat text for P2.
    private javafx.scene.image.Image
    Image for river tiles.
    private javafx.scene.layout.BorderPane
    Main layout.
    private javafx.scene.text.Text
    Text displaying the current round.
    private javafx.scene.Scene
    Main JavaFX Scene for this screen.
    private javafx.scene.image.Image
    Image for rock tiles.
    private static final int
    Size of each tile on the map in pixels.
    private javafx.scene.image.Image
    Image for tree tiles.
    private javafx.scene.text.Text
    Text displaying the current turn.
    private javafx.scene.image.Image
    VS image for the top panel.
    private javafx.scene.media.AudioClip
    Walking sound effect.
  • Constructor Summary

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    private javafx.scene.layout.HBox
    Creates the bottom bar displaying the current turn and round.
    private javafx.scene.layout.VBox
    createInventoryPanel(String title, String cls, String[] items)
    Creates an inventory panel for one player showing slots up to maxInventorySize.
    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).
    private javafx.scene.layout.BorderPane
    createTopPanel(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 String
    dirImg(String cls, String action)
    Resolves the image path for a character based on class name and action.
    javafx.scene.media.MediaPlayer
    Returns the BGM MediaPlayer.
    javafx.scene.Scene
    Returns the Scene for this screen.
    private void
    initPlayerSprites(String p1Class, String p2Class)
    create sprite for P1 and P2 on map
    private void
    Loads all tile and UI images.
    private void
    Load Walking sound effect and BGM
    void
    movePlayer(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.ImageView
    overlay(javafx.scene.image.Image img)
    Creates a tile-sized ImageView to overlay on a base tile (e.g.
    void
    Re-renders the entire map from the model, used when the map changes.
    private void
    Re-renders the entire map from the given model, used when the map changes (item pickup, zone shrink).
    void
    Updates the round text at the bottom.
    void
    Updates the turn text at the bottom.
    void
    Shows a temporary on-screen notification that disappears automatically after 2.5 seconds.
    void
    updateInventory(int playerNum, String[] items)
    Updates a player's inventory panel with the latest item list.
    void
    updatePlayerStats(int playerNum, double hp, double maxHp, int atk, int def)
    Updates the HP bar and stat text for a player.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TILE_SIZE

      private static final int TILE_SIZE
      Size of each tile on the map in pixels.
      See Also:
    • ENTITY_SIZE

      private static final double ENTITY_SIZE
      Size of player/goblin sprites in pixels.
      See Also:
    • ENTITY_X_OFF

      private static final double ENTITY_X_OFF
      X offset to centre the sprite within a tile.
      See Also:
    • ENTITY_Y_OFF

      private static final double ENTITY_Y_OFF
      Y offset to centre the sprite within a tile.
      See Also:
    • scene

      private javafx.scene.Scene scene
      Main JavaFX Scene for this screen.
    • mainRoot

      private javafx.scene.layout.StackPane mainRoot
      Root container that stacks the background and layout.
    • rootPane

      private javafx.scene.layout.BorderPane rootPane
      Main layout.
    • mapStack

      private javafx.scene.layout.StackPane mapStack
      StackPane layering the gridPane and entityPane.
    • gridPane

      private javafx.scene.layout.GridPane gridPane
      Grid containing all tiles.
    • entityPane

      private javafx.scene.layout.Pane entityPane
      Layer for placing player and goblin sprites on top of the grid.
    • p1HpBar

      private javafx.scene.control.ProgressBar p1HpBar
      HP bar for P1.
    • p2HpBar

      private javafx.scene.control.ProgressBar p2HpBar
      HP bar for P2.
    • p1StatText

      private javafx.scene.text.Text p1StatText
      Stat text for P1.
    • p2StatText

      private javafx.scene.text.Text p2StatText
      Stat text for P2.
    • p1InventoryBox

      private javafx.scene.layout.VBox p1InventoryBox
      Inventory panel for P1 on the left side.
    • p2InventoryBox

      private javafx.scene.layout.VBox p2InventoryBox
      Inventory panel for P2 on the right side.
    • p1ImageView

      private javafx.scene.image.ImageView p1ImageView
      Sprite for P1 on the map.
    • p2ImageView

      private javafx.scene.image.ImageView p2ImageView
      Sprite for P2 on the map.
    • turnText

      private javafx.scene.text.Text turnText
      Text displaying the current turn.
    • roundText

      private javafx.scene.text.Text roundText
      Text displaying the current round.
    • notificationText

      private javafx.scene.text.Text notificationText
      Temporary notification text that fades out automatically after 2.5 seconds.
    • normalImg

      private javafx.scene.image.Image normalImg
      Image for normal tiles.
    • stoneImg

      private javafx.scene.image.Image stoneImg
      Image for rock tiles.
    • treeImg

      private javafx.scene.image.Image treeImg
      Image for tree tiles.
    • riverImg

      private javafx.scene.image.Image riverImg
      Image for river tiles.
    • chestImg

      private javafx.scene.image.Image chestImg
      Image for chest (item) tiles.
    • lavaImg

      private javafx.scene.image.Image lavaImg
      Image for lava (shrinking zone) tiles.
    • vsImg

      private javafx.scene.image.Image vsImg
      VS image for the top panel.
    • inventoryImg

      private javafx.scene.image.Image inventoryImg
      Inventory slot image.
    • bgImg

      private javafx.scene.image.Image bgImg
      Background image for the map phase.
    • walkSound

      private javafx.scene.media.AudioClip walkSound
      Walking sound effect.
    • bgmPlayer

      private javafx.scene.media.MediaPlayer bgmPlayer
      BGM media player.
    • p1Name

      private final String p1Name
      Name of P1.
    • p2Name

      private final String p2Name
      Name of P2.
    • p1Class

      private final String p1Class
      Class of P1 (e.g. "knight").
    • p2Class

      private final String 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 P1
      p2Class - Class of P2.
      initialMap - Initial map to display
      p1Name - Name of P1.
      p2Name - Name of P2.
      p1Hp - Current HP of P1
      p1MaxHp - Maximum HP of P1
      p1Atk - ATK of P1
      p1Def - DEF of P1
      p2Hp - Current HP of P2
      p2MaxHp - Maximum HP of P2
      p2Atk - ATK of P2
      p2Def - 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

      private void initPlayerSprites(String p1Class, String p2Class)
      create sprite for P1 and P2 on map
      Parameters:
      p1Class - class of P1 for loading image
      p2Class - Class of P2 for loading image
    • renderFromModel

      private void renderFromModel(MapGrid map)
      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

      private javafx.scene.layout.BorderPane createTopPanel(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.
    • 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 name
      cls - Character class
      hp - Current HP
      maxHp - Maximum HP
      atk - Attack power
      def - Defense
      isLeft - true if 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

      private javafx.scene.layout.VBox createInventoryPanel(String title, String cls, String[] items)
      Creates an inventory panel for one player showing slots up to maxInventorySize.
      Parameters:
      title - Panel title
      cls - Player's class (determines the number of slots)
      items - Array of item names currently held
      Returns:
      The inventory panel as a VBox
    • dirImg

      private String dirImg(String cls, String action)
      Resolves the image path for a character based on class name and action.
      Parameters:
      cls - Class name
      action - Action name, e.g. "stand", "atk"
      Returns:
      Resource path for the image
    • 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

      public void movePlayer(int playerNum, int targetCol, int targetRow, String direction)
      Moves a player's sprite to a new position with animation and sound.
      Parameters:
      playerNum - Player number (1 or 2)
      targetCol - Destination column
      targetRow - Destination row
      direction - 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 HP
      maxHp - Maximum HP
      atk - Attack power
      def - Defense
    • updateInventory

      public void updateInventory(int playerNum, String[] items)
      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

      public void refreshMapFromModel(MapGrid map)
      Re-renders the entire map from the model, used when the map changes.
      Parameters:
      map - Current map from the model
    • setTurnText

      public void setTurnText(String text)
      Updates the turn text at the bottom.
      Parameters:
      text - Text to display, e.g. "P1 Turn (WASD)"
    • setRoundText

      public void setRoundText(String text)
      Updates the round text at the bottom.
      Parameters:
      text - Text to display, e.g. "Round 3"
    • showNotification

      public void showNotification(String msg)
      Shows a temporary on-screen notification that disappears automatically after 2.5 seconds.
      Parameters:
      msg - Message to display