Class BattleInteractor

java.lang.Object
com.mg105.use_cases.battle.BattleInteractor

public class BattleInteractor extends Object
This class interacts with the Battle entity.

It is responsible for modifying Battle related entities and for the processing needed during combat encounters.

  • Constructor Details

    • BattleInteractor

      public BattleInteractor(GameState state, InventoryInteractor inventoryInteractor, Saver saver)
      Creates a new BattleInteractor with a reference to the GameState.
      Parameters:
      state - the GameState to be referred to.
      inventoryInteractor - the inventoryInteractor to be referred to.
      saver - an instance of Saver used to save data.
  • Method Details

    • setPresenter

      public void setPresenter(BattlePresenterInterface presenter)
      Sets the presenter attribute.
      Parameters:
      presenter - the BattlePresenterInterface instance to set the presenter attribute to.
    • createEncounter

      public void createEncounter()
      Creates a new encounter with random opponents and sets it as the current encounter in GameState.
    • isCharacterFainted

      public boolean isCharacterFainted(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.
    • getCharacterHealth

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

      public int getCharacterDamage(String name)
      Returns the current damage stat of the BattleCharacter with the given name.
      Parameters:
      name - the name of the character.
      Returns:
      the desired BattleCharacter's current damage.
    • getCharacterMoveStats

      public int[] getCharacterMoveStats(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 name of the character.
      Returns:
      the desired BattleCharacter's move stats.
    • getCharacterMoveNames

      public String[] getCharacterMoveNames(String name)
      Returns the names of the BattleCharacter with the given name's moves. Stats order: Move1 name, Move2 name.
      Parameters:
      name - the name of the character.
      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.
    • endBattle

      public boolean endBattle()
      Method makes changes that represent an ended battle in the state of the game (won or lost) The method also save the game for user
      Returns:
      true iff the battle was won