Class BattlePresenter
java.lang.Object
com.mg105.interface_adapters.battle.BattlePresenter
- All Implemented Interfaces:
BattlePresenterInterface
Class communicating between BattleMenuInterface view and BattleInteractor.
Follows MVP pattern; contains a reference to the view and interacts with BattleInteractor.
-
Constructor Summary
ConstructorDescriptionBattlePresenter
(BattleInteractor interactor, Toggler toggler) Creates a new BattlePresenter with reference to a given BattleInteractor, and sets the interactor to refer to this instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Makes the appropriate calls to change the state in the case of a battle being lost or won and then Makes the appropriate updates to change the view in the of a battle being won or lostvoid
executeTurn
(int moveNum, String casterName, String targetName) Use one of (given) the given caster's moves on the given target.int
givenCharacterDamage
(String name) Returns the current damage stat of the BattleCharacter with the given name.boolean
givenCharacterFainted
(String name) Returns whether the given name is associated with a fainted character.int
givenCharacterHealth
(String name) Returns the current health of the BattleCharacter with the given name.String[]
Returns the names of the BattleCharacter with the given name's moves.int[]
Returns the stats of the BattleCharacter with the given name's moves.retrieveTargets
(int moveNum, String casterName) Returns the name of every BattleCharacter which can be targeted by the given move.Starts a round of the encounter.void
setView
(BattleMenuInterface view) Sets the view attribute.void
setViewNames
(String[] partyNames, String[] opponentNames) Set the characters in the view.void
Creates a new encounter with random opponents and sets it as the current encounter in GameStatevoid
updateViewCharacter
(String targetName) Call on the BattleMenuInterface to update the displayed information for the given character.
-
Constructor Details
-
BattlePresenter
Creates a new BattlePresenter with reference to a given BattleInteractor, and sets the interactor to refer to this instance.- Parameters:
interactor
- the BattleInteractor to be referred to.toggler
- the toggler used to change windows.
-
-
Method Details
-
setView
Sets the view attribute.- Parameters:
view
- the BattleMenuInterface instance to set the view attribute to.
-
startBattle
public void startBattle()Creates a new encounter with random opponents and sets it as the current encounter in GameState -
givenCharacterFainted
Returns whether the given name is associated with a fainted character. Assumes that the inputted name corresponds to a character who was in the encounter at some point.- Parameters:
name
- the name of the character being checked.- Returns:
- whether the given name corresponds to a fainted character.
-
givenCharacterHealth
Returns the current health of the BattleCharacter with the given name.- Parameters:
name
- the desired character.- Returns:
- the desired BattleCharacter's current health.
-
givenCharacterDamage
Returns the current damage stat of the BattleCharacter with the given name.- Parameters:
name
- the desired character.- Returns:
- the desired BattleCharacter's current damage.
-
givenCharacterMoveStats
Returns the stats of the BattleCharacter with the given name's moves. Stats order: Move1 health change, Move1 damage change, Move2 health change, Move2 damage change.- Parameters:
name
- the desired character's name- Returns:
- the desired BattleCharacter's move stats.
-
givenCharacterMoveNames
Returns the names of the BattleCharacter with the given name's moves. Stats order: Move1 name, Move2 name.- Parameters:
name
- the desired character's name- Returns:
- the desired BattleCharacter's move names.
-
roundStart
Starts a round of the encounter. If battle ended last round, end the encounter/the run depending on the result. If encounter is still in progress, get the next moving character. If opponent is moving, choose a random move and random target and use it. returns null iff the battle has ended- Returns:
- a String of the name of the moving character
-
retrieveTargets
Returns the name of every BattleCharacter which can be targeted by the given move. Note: Function should only be called from view when caster is friendly, so method does not accommodate for case where caster is an opponent.- Parameters:
moveNum
- integer representing which of the two Moves is being used.casterName
- String representing the name of the given moving BattleCharacter.- Returns:
- ArrayList of Strings representing the names of every possible target BattleCharacter.
-
executeTurn
Use one of (given) the given caster's moves on the given target.- Parameters:
moveNum
- integer representing which of the two moves is being used.casterName
- String representing the name of the caster BattleCharacter.targetName
- String representing the name of the target BattleCharacter.
-
setViewNames
Set the characters in the view.- Specified by:
setViewNames
in interfaceBattlePresenterInterface
- Parameters:
partyNames
- the name strings of the party characters.opponentNames
- the name strings of the opponent characters.
-
updateViewCharacter
Call on the BattleMenuInterface to update the displayed information for the given character.- Specified by:
updateViewCharacter
in interfaceBattlePresenterInterface
- Parameters:
targetName
- the name String of the character whose information displayed on the view needs to be updated.
-
endBattle
public void endBattle()Makes the appropriate calls to change the state in the case of a battle being lost or won and then Makes the appropriate updates to change the view in the of a battle being won or lost
-