Class BattleScene
java.lang.Object
application.BattleScene
Battle phase screen displaying sprites for both sides, HP bars, and action buttons.
GameController calls methods here to play animations and update the UI after each turn.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate javafx.scene.layout.HBoxHBox holding the action buttons at the bottomprivate javafx.scene.media.AudioClipSound effect played on attackprivate javafx.scene.control.ButtonAttack Buttonprivate javafx.scene.text.TextBattle log text displayed at the center of the screenprivate javafx.scene.image.Imagebackground battle sceneprivate javafx.scene.media.MediaPlayerBGM media player for the battleprivate javafx.scene.control.ButtonDefend buttonprivate final doubleX position of fighter 1's spriteprivate final doubleY position of fighter 1's spriteprivate intAttack power of fighter 1private StringClass of fighter 1, e.g.private intDefense of fighter 1private doubleCurrent HP of fighter 1private javafx.scene.control.ProgressBarHP bar for fighter 1.private javafx.scene.image.ImageViewSprite for fighter 1private doubleMaximum HP of fighter 1private Stringfighter 1 nameprivate javafx.scene.text.TextStat text for fighter 1private final doubleX position of fighter 2's spriteprivate final doubleY position of fighter 2's spriteprivate intAttack power of fighter 2private StringClass of fighter 2, e.g.private intDefense of fighter 2private doubleCurrent HP of fighter 2private javafx.scene.control.ProgressBarHP bar for fighter 2.private javafx.scene.image.ImageViewSprite for fighter 2private doubleMaximum HP of fighter 2private StringFighter 2 nameprivate javafx.scene.text.TextStat text for fighter 2private javafx.scene.image.ImageInventory slot imageprivate javafx.scene.control.ButtonUse Item buttonprivate javafx.scene.layout.StackPaneRoot container.private javafx.scene.media.AudioClipSound effect played when drinking a potionprivate javafx.scene.layout.BorderPaneMain layout.private javafx.scene.SceneMain JavaFX Scene for this screen.private javafx.scene.control.ButtonUse Skill buttonprivate javafx.scene.text.TextText indicating whose turn it isprivate javafx.scene.image.ImageVS image displayed at the center of the screen -
Constructor Summary
ConstructorsConstructorDescriptionBattleScene(String f1Name, String f1Class, double f1Hp, double f1MaxHp, int f1Atk, int f1Def, String f2Name, String f2Class, double f2Hp, double f2MaxHp, int f2Atk, int f2Def) Creates the Battle Scene with data for both fighters. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidbuildUI()Builds all UI components for the battle screen.private StringResolves the resource path for a character sprite based on class name and action.private javafx.scene.layout.HBoxCreates the action menu container with all 4 buttons (attack, defend, item, skill).private javafx.scene.layout.StackPaneCreates the battle log box that displays the result of the latest turn.private javafx.scene.layout.PaneCreates the center pane containing sprites for both fighters facing each other.private javafx.scene.layout.HBoxcreateFighterProfile(String name, String cls, double hp, double maxHp, int atk, int def, boolean isLeft) Creates a profile card for one fighter in the top panel.private javafx.scene.control.ButtoncreateImgBtn(String path) Creates an image-based button with a hover effect.private javafx.scene.layout.BorderPaneCreates the top panel showing HP bars and stats for both fighters.voidHides all action buttons while an animation is playing.javafx.scene.control.Buttonjavafx.scene.media.MediaPlayerjavafx.scene.control.Buttonjavafx.scene.control.Buttonjavafx.scene.ScenegetScene()javafx.scene.control.Buttonprivate voidLoads background and UI images.private voidLoads sound effects and BGM.voidopenItemSelectionMenu(String[] items, Consumer<Integer> onItemClicked) Switches the action menu to display item selection slots from the inventory.voidplayActionAnimation(boolean isF1, String actionType, String attackerName, String defenderName, int dmgAmount, Runnable onFinished) Plays a normal attack animation: swaps the sprite, shakes the target, then invokes the callback when done.voidplayDefendEffect(String name) Displays a message indicating the fighter is taking a defensive stance.voidplayItemAnimation(boolean isF1, String itemName, Runnable onFinished) Plays an item-use animation: switches to the potion-drinking pose, then invokes the callback.voidplaySkillAnimation(boolean isF1, String skillName, String attackerName, String defenderName, int dmgAmount, Runnable onFinished) Plays a skill animation, handling attack skills and heal skills separately.voidsetLogText(String msg) Sets the battle log text.voidsetTurnIndicator(boolean isF1, String name) Updates the turn indicator text with the appropriate color for the active side.voidShows all 4 main action buttons.voidupdateHP(boolean isF1, double hp, double maxHp, int atk, int def) Updates the HP bar and stat text for the specified fighter.
-
Field Details
-
F1_POS_X
private final double F1_POS_XX position of fighter 1's sprite- See Also:
-
F1_POS_Y
private final double F1_POS_YY position of fighter 1's sprite- See Also:
-
F2_POS_X
private final double F2_POS_XX position of fighter 2's sprite- See Also:
-
F2_POS_Y
private final double F2_POS_YY position of fighter 2's sprite- See Also:
-
scene
private javafx.scene.Scene sceneMain JavaFX Scene for this screen. -
mainRoot
private javafx.scene.layout.StackPane mainRootRoot container. -
rootPane
private javafx.scene.layout.BorderPane rootPaneMain layout. -
actionMenuBox
private javafx.scene.layout.HBox actionMenuBoxHBox holding the action buttons at the bottom -
f1HpBar
private javafx.scene.control.ProgressBar f1HpBarHP bar for fighter 1. -
f2HpBar
private javafx.scene.control.ProgressBar f2HpBarHP bar for fighter 2. -
f1StatText
private javafx.scene.text.Text f1StatTextStat text for fighter 1 -
f2StatText
private javafx.scene.text.Text f2StatTextStat text for fighter 2 -
f1ImgView
private javafx.scene.image.ImageView f1ImgViewSprite for fighter 1 -
f2ImgView
private javafx.scene.image.ImageView f2ImgViewSprite for fighter 2 -
battleLogText
private javafx.scene.text.Text battleLogTextBattle log text displayed at the center of the screen -
turnIndicatorText
private javafx.scene.text.Text turnIndicatorTextText indicating whose turn it is -
attackBtn
private javafx.scene.control.Button attackBtnAttack Button -
skillBtn
private javafx.scene.control.Button skillBtnUse Skill button -
itemBtn
private javafx.scene.control.Button itemBtnUse Item button -
defendBtn
private javafx.scene.control.Button defendBtnDefend button -
f1Name
fighter 1 name -
f1Class
Class of fighter 1, e.g. "knight", "archer" -
f1Hp
private double f1HpCurrent HP of fighter 1 -
f1MaxHp
private double f1MaxHpMaximum HP of fighter 1 -
f1Atk
private int f1AtkAttack power of fighter 1 -
f1Def
private int f1DefDefense of fighter 1 -
f2Name
Fighter 2 name -
f2Class
Class of fighter 2, e.g. "goblin", "alien" -
f2Hp
private double f2HpCurrent HP of fighter 2 -
f2MaxHp
private double f2MaxHpMaximum HP of fighter 2 -
f2Atk
private int f2AtkAttack power of fighter 2 -
f2Def
private int f2DefDefense of fighter 2 -
bgImg
private javafx.scene.image.Image bgImgbackground battle scene -
vsImg
private javafx.scene.image.Image vsImgVS image displayed at the center of the screen -
inventoryImg
private javafx.scene.image.Image inventoryImgInventory slot image -
atkSound
private javafx.scene.media.AudioClip atkSoundSound effect played on attack -
potionSound
private javafx.scene.media.AudioClip potionSoundSound effect played when drinking a potion -
bgmPlayer
private javafx.scene.media.MediaPlayer bgmPlayerBGM media player for the battle
-
-
Constructor Details
-
BattleScene
public BattleScene(String f1Name, String f1Class, double f1Hp, double f1MaxHp, int f1Atk, int f1Def, String f2Name, String f2Class, double f2Hp, double f2MaxHp, int f2Atk, int f2Def) Creates the Battle Scene with data for both fighters.- Parameters:
f1Name- Name of fighter 1f1Class- Class of fighter 1f1Hp- Current HP of fighter 1f1MaxHp- Maximum HP of fighter 1f1Atk- ATK of fighter 1f1Def- DEF of fighter 1f2Name- Name of fighter 2f2Class- Class of fighter 2f2Hp- Current HP of fighter 2f2MaxHp- Maximum HP of fighter 2f2Atk- ATK of fighter 2f2Def- DEF of fighter 2
-
-
Method Details
-
buildUI
private void buildUI()Builds all UI components for the battle screen. -
loadImages
private void loadImages()Loads background and UI images. -
loadSounds
private void loadSounds()Loads sound effects and BGM. -
charImg
-
createTopPanel
private javafx.scene.layout.BorderPane createTopPanel()Creates the top panel showing HP bars and stats for both fighters.- Returns:
- The top panel as a BorderPane
-
createFighterProfile
private javafx.scene.layout.HBox createFighterProfile(String name, String cls, double hp, double maxHp, int atk, int def, boolean isLeft) Creates a profile card for one fighter in the top panel.- Parameters:
name- Display namecls- Character classhp- Current HPmaxHp- Maximum HPatk- Attack powerdef- DefenseisLeft-trueif this is fighter 1 (left side)- Returns:
- The profile card as an HBox
-
createCenterBattle
private javafx.scene.layout.Pane createCenterBattle()Creates the center pane containing sprites for both fighters facing each other.- Returns:
- The center pane with both sprites
-
createBattleLog
private javafx.scene.layout.StackPane createBattleLog()Creates the battle log box that displays the result of the latest turn.- Returns:
- The battle log as a StackPane
-
createActionMenuContainer
private javafx.scene.layout.HBox createActionMenuContainer()Creates the action menu container with all 4 buttons (attack, defend, item, skill).- Returns:
- The action menu as an HBox
-
createImgBtn
Creates an image-based button with a hover effect.- Parameters:
path- Resource path for the button image- Returns:
- A Button using an image instead of text
-
getScene
public javafx.scene.Scene getScene()- Returns:
- The Scene for the battle screen
-
getBgmPlayer
public javafx.scene.media.MediaPlayer getBgmPlayer()- Returns:
- The BGM MediaPlayer for the battle
-
getAttackBtn
public javafx.scene.control.Button getAttackBtn()- Returns:
- The Attack button
-
getDefendBtn
public javafx.scene.control.Button getDefendBtn()- Returns:
- Defend button
-
getItemBtn
public javafx.scene.control.Button getItemBtn()- Returns:
- Use Item button
-
getSkillBtn
public javafx.scene.control.Button getSkillBtn()- Returns:
- Use Skill button
-
showMainActionMenu
public void showMainActionMenu()Shows all 4 main action buttons. -
disableAllActionButtons
public void disableAllActionButtons()Hides all action buttons while an animation is playing. -
setTurnIndicator
Updates the turn indicator text with the appropriate color for the active side.- Parameters:
isF1-trueif it is fighter 1's turnname- Name of the active fighter
-
setLogText
-
updateHP
public void updateHP(boolean isF1, double hp, double maxHp, int atk, int def) Updates the HP bar and stat text for the specified fighter.- Parameters:
isF1-trueto update fighter 1hp- Current HPmaxHp- Maximum HPatk- Attack powerdef- Defense
-
playDefendEffect
Displays a message indicating the fighter is taking a defensive stance.- Parameters:
name- Name of the defending fighter
-
playActionAnimation
public void playActionAnimation(boolean isF1, String actionType, String attackerName, String defenderName, int dmgAmount, Runnable onFinished) Plays a normal attack animation: swaps the sprite, shakes the target, then invokes the callback when done.- Parameters:
isF1-trueif fighter 1 is attackingactionType- Action name shown in the logattackerName- Name of the attackerdefenderName- Name of the defenderdmgAmount- Damage dealtonFinished- Callback invoked after the animation finishes
-
playSkillAnimation
public void playSkillAnimation(boolean isF1, String skillName, String attackerName, String defenderName, int dmgAmount, Runnable onFinished) Plays a skill animation, handling attack skills and heal skills separately.- Parameters:
isF1-trueif fighter 1 is using the skillskillName- Name of the skillattackerName- Name of the skill userdefenderName- Name of the targetdmgAmount- Damage dealt (ignored for heal skills)onFinished- Callback invoked after the animation finishes
-
playItemAnimation
Plays an item-use animation: switches to the potion-drinking pose, then invokes the callback.- Parameters:
isF1-trueif fighter 1 is using the itemitemName- Name of the itemonFinished- Callback invoked after the animation finishes
-
openItemSelectionMenu
Switches the action menu to display item selection slots from the inventory. If the inventory is empty, a warning message is shown instead.- Parameters:
items- Array of item names in the inventoryonItemClicked- Callback that receives the index of the selected item
-