jezuch.utils.starmapper2
Class Player

java.lang.Object
  |
  +--jezuch.utils.starmapper2.Player
All Implemented Interfaces:
java.io.Serializable

public class Player
extends java.lang.Object
implements java.io.Serializable

Class Player encapsulates a Stars! player; the main attribute of a player is name, and is the only one exposed as public final. Once created, Player can't change it's name. Also there are some supplemental attributes that are used by Starmapper, that is player's color, and a flag if this player plays an AR (Alternate Reality) race and if so, also a map of starbases used by this player to their types. This distinction is necessary, because AR races are treated very differently by Stars! and in reports (other players can't see their population). All attributes besides name are modifiable.

Since:
2.0
Version:
2.0
Author:
Krzysztof Sobolewski
See Also:
Serialized Form

Field Summary
 java.lang.String name
          Player's name.
 
Constructor Summary
Player(java.lang.String name)
          Construncts a Player with a name, default color and as non-AR race.
Player(java.lang.String name, boolean ar)
          Constructs a Player with specified name and as AR or non-AR race.
Player(java.lang.String name, boolean ar, java.awt.Color color)
          Constructs a player with all parameters, except starbase map, which is configured separately.
Player(java.lang.String name, java.awt.Color color)
          Constructs a player with specified name and color and as non-AR race.
 
Method Summary
 void addStarbaseMapping(java.lang.String baseName, int population)
          Adds a starbase mapping to population.
 void addStarbaseMapping(java.lang.String baseName, java.lang.String mapTo)
          Adds a starbase mapping to another stabase.
 void clearStarbaseMapping()
          Removes all starbase mapping from this Player.
 java.awt.Color getColor()
           
 int getStarbaseMapping(java.lang.String baseName)
          Returns a population that is mapped to a starbase name.
 boolean isAR()
           
 void setAR(boolean ar)
           
 void setColor(java.awt.Color color)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public final java.lang.String name
Player's name.

Constructor Detail

Player

public Player(java.lang.String name)
Construncts a Player with a name, default color and as non-AR race.

Parameters:
name - Player's name

Player

public Player(java.lang.String name,
              boolean ar)
Constructs a Player with specified name and as AR or non-AR race.

Parameters:
name - Player's name
ar - flag indicating if the Player is an AR race

Player

public Player(java.lang.String name,
              boolean ar,
              java.awt.Color color)
Constructs a player with all parameters, except starbase map, which is configured separately.

Parameters:
name - Player's name
ar - flag indicating if the Player is an AR race
color - Player's color; can be null (default)
See Also:
Color

Player

public Player(java.lang.String name,
              java.awt.Color color)
Constructs a player with specified name and color and as non-AR race.

Parameters:
name - Player's name
color - Player's color; can be null (default)
See Also:
Color
Method Detail

addStarbaseMapping

public void addStarbaseMapping(java.lang.String baseName,
                               int population)
Adds a starbase mapping to population. Only effective for AR races (although you can set the maping for non-AR race and then switch it to AR and all maping will be valid).

Parameters:
baseName - starbase name
population - population to assume for planets with that starbase
Throws:
java.lang.IllegalArgumentException - thrown if baseName is null or population to map is less than zero

addStarbaseMapping

public void addStarbaseMapping(java.lang.String baseName,
                               java.lang.String mapTo)
Adds a starbase mapping to another stabase. Only effective for AR races (although you can set the maping for non-AR race and then switch it to AR and all maping will be valid).

Parameters:
baseName - starbase name
mapTo - another starbase name that baseName is mapped to; has to be defined as valid mapping.
Throws:
java.lang.IllegalArgumentException - thrown if either of stabase names is null, or mapTo doesn't exist in mapping.

clearStarbaseMapping

public void clearStarbaseMapping()
Removes all starbase mapping from this Player.


getColor

public java.awt.Color getColor()
Returns:
Player's color
See Also:
Color

getStarbaseMapping

public int getStarbaseMapping(java.lang.String baseName)
Returns a population that is mapped to a starbase name. Valid for both AR and non-AR races, but Starmapper will never call it for non-AR race. Mapping is followed until a population is found; if there's no mapping defined for starbase it returns -1.

Parameters:
baseName - name of starbase to check
Returns:
mapped population or -1 if there's no mapping for that starbase
Throws:
java.lang.IllegalArgumentException - thrown if baseName is null

isAR

public boolean isAR()
Returns:
boolean flag indicating if the Player is an AR race

setAR

public void setAR(boolean ar)
Parameters:
ar - flag indicating if the Player is an AR race

setColor

public void setColor(java.awt.Color color)
Parameters:
color - new Player's color, or null (default)
See Also:
Color

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object