All Packages  Class Hierarchy  This Package  Previous  Next  Index
  Class busrider.Player
java.lang.Object
   |
   +----busrider.Indexed
           |
           +----busrider.Item
                   |
                   +----busrider.Player
  -  public class Player
  -  extends Item
This mutable class represents a player.
A player has an amount of cash, a speed, a location, a current Route,
and usually a destination.
Strategies don't have access to Player objects: instead they work with
immutable PlayerView objects.
    -  See Also:
    
-  Location, PlayerView
  Constructor Index
  - 
	Player(String, int, Strategy, Junction)
  
-  creates a player, with the given name, index, strategy, and initial
terminus; cash=INITIAL_CASH; speed=slow;
currentRoute=none.
  Method Index
  - 
	equals(Object)
  
-  compares two objects.
  
- 
	getCash()
  
-  returns the player's cash.
  
- 
	getCurrentRoute()
  
-  returns the player's current Route, or null if none.
  
- 
	getDestination()
  
-  returns the player's destination.
  
- 
	getLocation()
  
-  returns the location of the player.
  
- 
	getOrigin()
  
-  returns the player's origin.
  
- 
	getStrategy()
  
-  returns the player's Strategy.
  
- 
	incrementCash(int)
  
-  adds a value to the player's cash.
  
- 
	initialize(Junction)
  
-  initializes a player, to the given terminus;
cash=INITIAL_CASH; speed=slow; currentRoute=none.
- 
	isFast()
  
-  indicates whether the player is fast (has a Right-of-Way.)
  
- 
	move(int, Route[])
  
-  moves the player toward his destination, according to the
segments chosen by the strategy.
  
- 
	noteArrival(Board)
  
-  notes the players arrival at a destination.
  
- 
	setDestination(Junction)
  
-  sets the player's destination to dest.
- 
	setSpeed(boolean)
  
-  sets the player's speed.
  
- 
	toString()
  
-  returns a string representation of the player.
  Constructors
Player
 public Player(String name,
               int index,
               Strategy stra,
               Junction loc)
  -  creates a player, with the given name, index, strategy, and initial
terminus; cash=INITIAL_CASH; speed=slow;
currentRoute=none.
 
  Methods
equals
 public boolean equals(Object ob)
  -  compares two objects.
   
- 
    -  Overrides:
    
-  equals in class Item
  
 
getStrategy
 public Strategy getStrategy()
  -  returns the player's Strategy.
 
getCash
 public int getCash()
  -  returns the player's cash.
 
isFast
 public boolean isFast()
  -  indicates whether the player is fast (has a Right-of-Way.)
 
getOrigin
 public Junction getOrigin()
  -  returns the player's origin.
 
getDestination
 public Junction getDestination()
  -  returns the player's destination.
But returns null if the player is at a terminus and hasn't
selected his next destination.
 
getCurrentRoute
 public Route getCurrentRoute()
  -  returns the player's current Route, or null if none.
 
toString
 public String toString()
  -  returns a string representation of the player.
It shows name, cash, and destination.
   
- 
    -  Overrides:
    
-  toString in class Object
  
 
initialize
 public void initialize(Junction loc)
  -  initializes a player, to the given terminus;
cash=INITIAL_CASH; speed=slow; currentRoute=none.
 
getLocation
 public Location getLocation()
  -  returns the location of the player. This is a mutator, because
changing the return value alters the player.
 
incrementCash
 public void incrementCash(int amt)
  -  adds a value to the player's cash.
amtmay be negative.
 
setSpeed
 public void setSpeed(boolean fast)
  -  sets the player's speed.
 
setDestination
 public void setDestination(Junction dest)
  -  sets the player's destination to dest.destmay be null.
 
noteArrival
 public void noteArrival(Board bo)
  -  notes the players arrival at a destination.
Updates his cash, nulls his destination and currentRoute.
 
move
 public int move(int distance,
                 Route newRoute[])
  -  moves the player toward his destination, according to the
segments chosen by the strategy.
The player moves distance, or less if he arrives. The return value RV indicates:
 
-  If RV < 0, he arrived at his destination. 
-  If RV == 0, he didn't arrive, and has exhausted his roll. 
-  If RV > 0, he didn't arrive, has RV distance to go, and has
chosen a new route, stored in newRoute[0]. 
   
- 
    -  Parameters:
    
-  distance - the distance to travel
    -  newRoute - result parm: the new route travelled
  
 
 
All Packages  Class Hierarchy  This Package  Previous  Next  Index