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

 o 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

 o equals(Object)
compares two objects.
 o getCash()
returns the player's cash.
 o getCurrentRoute()
returns the player's current Route, or null if none.
 o getDestination()
returns the player's destination.
 o getLocation()
returns the location of the player.
 o getOrigin()
returns the player's origin.
 o getStrategy()
returns the player's Strategy.
 o incrementCash(int)
adds a value to the player's cash.
 o initialize(Junction)
initializes a player, to the given terminus; cash=INITIAL_CASH; speed=slow; currentRoute=none.
 o isFast()
indicates whether the player is fast (has a Right-of-Way.)
 o move(int, Route[])
moves the player toward his destination, according to the segments chosen by the strategy.
 o noteArrival(Board)
notes the players arrival at a destination.
 o setDestination(Junction)
sets the player's destination to dest.
 o setSpeed(boolean)
sets the player's speed.
 o toString()
returns a string representation of the player.

Constructors

 o 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

 o equals
 public boolean equals(Object ob)
compares two objects.

Overrides:
equals in class Item
 o getStrategy
 public Strategy getStrategy()
returns the player's Strategy.

 o getCash
 public int getCash()
returns the player's cash.

 o isFast
 public boolean isFast()
indicates whether the player is fast (has a Right-of-Way.)

 o getOrigin
 public Junction getOrigin()
returns the player's origin.

 o 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.

 o getCurrentRoute
 public Route getCurrentRoute()
returns the player's current Route, or null if none.

 o toString
 public String toString()
returns a string representation of the player. It shows name, cash, and destination.

Overrides:
toString in class Object
 o initialize
 public void initialize(Junction loc)
initializes a player, to the given terminus; cash=INITIAL_CASH; speed=slow; currentRoute=none.

 o getLocation
 public Location getLocation()
returns the location of the player. This is a mutator, because changing the return value alters the player.

 o incrementCash
 public void incrementCash(int amt)
adds a value to the player's cash. amt may be negative.

 o setSpeed
 public void setSpeed(boolean fast)
sets the player's speed.

 o setDestination
 public void setDestination(Junction dest)
sets the player's destination to dest. dest may be null.

 o noteArrival
 public void noteArrival(Board bo)
notes the players arrival at a destination. Updates his cash, nulls his destination and currentRoute.

 o 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:


All Packages  Class Hierarchy  This Package  Previous  Next  Index