Class BattlePresenter

java.lang.Object
com.mg105.interface_adapters.battle.BattlePresenter
All Implemented Interfaces:
BattlePresenterInterface

public class BattlePresenter extends Object implements BattlePresenterInterface
Class communicating between BattleMenuInterface view and BattleInteractor. Follows MVP pattern; contains a reference to the view and interacts with BattleInteractor.
  • Constructor Details

    • BattlePresenter

      public BattlePresenter(BattleInteractor interactor, Toggler toggler)
      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

      public void setView(BattleMenuInterface view)
      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

      public boolean givenCharacterFainted(String name)
      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

      public int givenCharacterHealth(String name)
      Returns the current health of the BattleCharacter with the given name.
      Parameters:
      name - the desired character.
      Returns:
      the desired BattleCharacter's current health.
    • givenCharacterDamage

      public int givenCharacterDamage(String name)
      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

      public int[] givenCharacterMoveStats(String name)
      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

      public String[] givenCharacterMoveNames(String name)
      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

      public String 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

      public ArrayList<String> retrieveTargets(int moveNum, String casterName)
      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

      public void executeTurn(int moveNum, String casterName, String targetName)
      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

      public void setViewNames(String[] partyNames, String[] opponentNames)
      Set the characters in the view.
      Specified by:
      setViewNames in interface BattlePresenterInterface
      Parameters:
      partyNames - the name strings of the party characters.
      opponentNames - the name strings of the opponent characters.
    • updateViewCharacter

      public void updateViewCharacter(String targetName)
      Call on the BattleMenuInterface to update the displayed information for the given character.
      Specified by:
      updateViewCharacter in interface BattlePresenterInterface
      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