shoddybattle
Class BattleField

java.lang.Object
  extended by shoddybattle.BattleField
Direct Known Subclasses:
NetBattleField

public abstract class BattleField
extends java.lang.Object


Nested Class Summary
protected static class BattleField.PokemonWrapper
          A wrapper for a pokemon and a turn.
 
Field Summary
protected  int[] m_active
           
protected  int m_participants
          The number of people who can actually participate.
protected  Pokemon[][] m_pokemon
           
 
Constructor Summary
protected BattleField(BattleMechanics mech)
           
  BattleField(BattleMechanics mech, Pokemon[][] pokemon)
          Creates a new instance of BattleField
 
Method Summary
 void addClause(Clause clause)
          Add a clause to this battle field.
 boolean allowsStatus(StatusEffect eff, Pokemon source, Pokemon target)
          Check whether the clauses present on this battle field permit the application of the given status effect to the given pokemon.
 boolean applyEffect(FieldEffect eff)
          Apply a new FieldEffect to this BattleField.
protected  void attachField()
          Attach this field to all of its pokemon.
 void checkBattleEnd(int i)
          Check if one party has won the battle and inform victory if so.
 void dispose()
          Dispose of this object by breaking all links to other objects, making it easy to the garbage collector to find and free them.
 void executeTurn(BattleTurn[] move)
          Execute a turn.
 Pokemon[] getActivePokemon()
          Get the active pokemon.
 int getAliveCount(int idx)
          Return the number of party members in a given party who are alive.
 FieldEffect getEffectByType(java.lang.Class type)
          Returns the first instance of an effect of a certain class that is applied to the BattleField.
 double getEffectiveness(PokemonType move, PokemonType pokemon, boolean enemy)
          Get the effectiveness of a move against a given pokemon on this field.
 java.util.ArrayList getEffectsByType(java.lang.Class type)
          Returns a list of the effects of a certain class that are applied to this BattleField.
 BattleMechanics getMechanics()
          Get the mechanics used on this battle field.
 Pokemon getOpponent(Pokemon p)
          Get the opponent of the Pokemon passed in.
 Pokemon[] getParty(int idx)
          Get a party.
 int getPokemonTrainer(Pokemon p)
          Get the index of a trainer from one of his pokemon.
 java.util.Random getRandom()
          Return the instance of Random used on this BattleField.
static MoveListEntry getStruggle()
           
abstract  java.lang.String getTrainerName(int idx)
          Get the name of a trainer by number.
abstract  void informPokemonFainted(int trainer, int idx)
          Inform that a pokemon fainted.
abstract  void informPokemonHealthChanged(Pokemon poke, int change)
          Inform that a pokemon's health was changed.
abstract  void informStatusApplied(Pokemon poke, StatusEffect eff)
          Inform that a status was applied to a pokemon.
abstract  void informStatusRemoved(Pokemon poke, StatusEffect eff)
          Inform that a status effect was removed from a pokemon.
abstract  void informSwitchInPokemon(int trainer, Pokemon poke)
          Inform that a pokemon was switched in.
abstract  void informUseMove(Pokemon poke, java.lang.String name)
          Inform that a pokemon used a move.
abstract  void informVictory(int winner)
          Inform that a player has won.
 boolean isNarrationEnabled()
          Return whether narration is enabled.
abstract  void queueMove(int trainer, BattleTurn move)
          Queue a move.
abstract  void refreshActivePokemon()
          Refresh all active pokemon.
 void removeEffect(FieldEffect eff)
          Remove a FieldEffect from this field.
 void replaceFaintedPokemon(int party, int pokemon, boolean search)
          Replace a fainted pokemon.
abstract  void requestAndWaitForSwitch(int party)
          Wait for a player to switch pokemon.
protected abstract  void requestMoves()
          Request moves for the next turn.
protected abstract  void requestPokemonReplacement(int i)
          Obtain a replacement pokemon for the team identified by the parameter.
 void setNarrationEnabled(boolean enabled)
          Set whether to narrate the battle.
protected  void setPokemon(Pokemon[][] pokemon)
           
abstract  void showMessage(java.lang.String message)
          Narrate the battle.
 void switchInPokemon(int trainer, int idx)
          Switch in a pokemon and apply FieldEffects to it.
 void synchroniseFieldEffects()
          Synchronise FieldEffects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_participants

protected final int m_participants
The number of people who can actually participate. This could be four later, but for now it will always be two.

See Also:
Constant Field Values

m_pokemon

protected Pokemon[][] m_pokemon

m_active

protected int[] m_active
Constructor Detail

BattleField

public BattleField(BattleMechanics mech,
                   Pokemon[][] pokemon)
Creates a new instance of BattleField


BattleField

protected BattleField(BattleMechanics mech)
Method Detail

getStruggle

public static MoveListEntry getStruggle()

addClause

public void addClause(Clause clause)
Add a clause to this battle field.

Parameters:
clause - the clause to add

isNarrationEnabled

public boolean isNarrationEnabled()
Return whether narration is enabled.


setNarrationEnabled

public void setNarrationEnabled(boolean enabled)
Set whether to narrate the battle.


getEffectiveness

public double getEffectiveness(PokemonType move,
                               PokemonType pokemon,
                               boolean enemy)
Get the effectiveness of a move against a given pokemon on this field.


allowsStatus

public boolean allowsStatus(StatusEffect eff,
                            Pokemon source,
                            Pokemon target)
Check whether the clauses present on this battle field permit the application of the given status effect to the given pokemon.


dispose

public void dispose()
Dispose of this object by breaking all links to other objects, making it easy to the garbage collector to find and free them.


getMechanics

public BattleMechanics getMechanics()
Get the mechanics used on this battle field.


getRandom

public java.util.Random getRandom()
Return the instance of Random used on this BattleField.


setPokemon

protected void setPokemon(Pokemon[][] pokemon)

getParty

public Pokemon[] getParty(int idx)
                   throws java.lang.IllegalArgumentException
Get a party.

Throws:
java.lang.IllegalArgumentException

attachField

protected void attachField()
Attach this field to all of its pokemon.


getActivePokemon

public Pokemon[] getActivePokemon()
Get the active pokemon.


applyEffect

public boolean applyEffect(FieldEffect eff)
Apply a new FieldEffect to this BattleField. Note that the actual effect passed in is not used -- it is cloned via eff.getFieldCopy(), not eff.clone(), the latter of which should return the same object.


synchroniseFieldEffects

public void synchroniseFieldEffects()
Synchronise FieldEffects.


removeEffect

public void removeEffect(FieldEffect eff)
Remove a FieldEffect from this field.


getEffectByType

public FieldEffect getEffectByType(java.lang.Class type)
Returns the first instance of an effect of a certain class that is applied to the BattleField.


getEffectsByType

public java.util.ArrayList getEffectsByType(java.lang.Class type)
Returns a list of the effects of a certain class that are applied to this BattleField.


requestPokemonReplacement

protected abstract void requestPokemonReplacement(int i)
Obtain a replacement pokemon for the team identified by the parameter.


showMessage

public abstract void showMessage(java.lang.String message)
Narrate the battle.


refreshActivePokemon

public abstract void refreshActivePokemon()
Refresh all active pokemon. The exact meaning of this is for the implementation to decide.


getPokemonTrainer

public int getPokemonTrainer(Pokemon p)
Get the index of a trainer from one of his pokemon.

Parameters:
p - a Pokemon who with 100% certainty belongs to one of the clients

getTrainerName

public abstract java.lang.String getTrainerName(int idx)
Get the name of a trainer by number.


requestMoves

protected abstract void requestMoves()
Request moves for the next turn.


informPokemonHealthChanged

public abstract void informPokemonHealthChanged(Pokemon poke,
                                                int change)
Inform that a pokemon's health was changed.


informStatusApplied

public abstract void informStatusApplied(Pokemon poke,
                                         StatusEffect eff)
Inform that a status was applied to a pokemon.


informStatusRemoved

public abstract void informStatusRemoved(Pokemon poke,
                                         StatusEffect eff)
Inform that a status effect was removed from a pokemon.


informSwitchInPokemon

public abstract void informSwitchInPokemon(int trainer,
                                           Pokemon poke)
Inform that a pokemon was switched in.


informPokemonFainted

public abstract void informPokemonFainted(int trainer,
                                          int idx)
Inform that a pokemon fainted.


informUseMove

public abstract void informUseMove(Pokemon poke,
                                   java.lang.String name)
Inform that a pokemon used a move.

Parameters:
poke - the pokemon who used the move
name - the name of the move that was used

switchInPokemon

public void switchInPokemon(int trainer,
                            int idx)
Switch in a pokemon and apply FieldEffects to it.


informVictory

public abstract void informVictory(int winner)
Inform that a player has won.


queueMove

public abstract void queueMove(int trainer,
                               BattleTurn move)
                        throws MoveQueueException
Queue a move.

Throws:
MoveQueueException

requestAndWaitForSwitch

public abstract void requestAndWaitForSwitch(int party)
Wait for a player to switch pokemon.


getOpponent

public Pokemon getOpponent(Pokemon p)
Get the opponent of the Pokemon passed in.


replaceFaintedPokemon

public void replaceFaintedPokemon(int party,
                                  int pokemon,
                                  boolean search)
Replace a fainted pokemon.


getAliveCount

public int getAliveCount(int idx)
Return the number of party members in a given party who are alive.


checkBattleEnd

public void checkBattleEnd(int i)
Check if one party has won the battle and inform victory if so.


executeTurn

public void executeTurn(BattleTurn[] move)
Execute a turn.