rails.game
Class City

java.lang.Object
  extended by rails.game.City
All Implemented Interfaces:
MoveableHolder, TokenHolder

public class City
extends java.lang.Object
implements TokenHolder

A City object represents any junction on the map that is relevant for establishing train run length and revenue calculation. A City object is bound to (1) a MapHex, (2) to a Station object on the current Tile laid on that MapHex, and (3) any tokens laid on that tile and station.

Each City has a unique ID, that is derived from the MapHex name and the City number. The initial City numbers are derived from the Station numbers of the preprinted tile of that hex.

Please note, that during upgrades the Station numbers related to a city on a multiple-city hex may change: city 1 on one tile may be numbered 2 on its upgrade, depending on the rotation of the upgrading tile. However, the City numbers will not change, unless cities are merged during upgrades; but even then it is attempted to retain the old city numbers as much as possible.

Author:
Erik Vos

Field Summary
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
City(MapHex mapHex, int number, Station station)
           
 
Method Summary
 boolean addObject(Moveable object, int[] position)
          Add an object to its list at a certain position.
 boolean addToken(TokenI token, int position)
           
 MapHex getHolder()
           
 int[] getListIndex(Moveable object)
           
 java.lang.String getName()
          Each station must have a name, which includes the tile Id (if on a tile) or the hex name (if on a MapHex).
 int getNumber()
           
 Station getRelatedStation()
           
 int getSlots()
           
 java.util.List<TokenI> getTokens()
           
 int getTokenSlotsLeft()
           
 java.lang.String getTrackEdges()
           
 java.lang.String getUniqueId()
           
 boolean hasTokenOf(PublicCompanyI company)
           
 boolean hasTokenOf(java.lang.String companyName)
           
 boolean hasTokens()
          Do we have any tokens?
 boolean hasTokenSlotsLeft()
           
 boolean removeObject(Moveable object)
           
 boolean removeToken(TokenI token)
          Remove a token.
 void setRelatedStation(Station relatedStation)
           
 void setSlots(int slots)
           
 void setTokens(java.util.ArrayList<TokenI> tokens)
           
 void setTrackEdges(java.lang.String trackEdges)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static org.apache.log4j.Logger log
Constructor Detail

City

public City(MapHex mapHex,
            int number,
            Station station)
Method Detail

getName

public java.lang.String getName()
Description copied from interface: TokenHolder
Each station must have a name, which includes the tile Id (if on a tile) or the hex name (if on a MapHex).

Specified by:
getName in interface MoveableHolder
Specified by:
getName in interface TokenHolder

getHolder

public MapHex getHolder()
Returns:
Returns the holder.

getNumber

public int getNumber()

getRelatedStation

public Station getRelatedStation()

setRelatedStation

public void setRelatedStation(Station relatedStation)

setSlots

public void setSlots(int slots)

getUniqueId

public java.lang.String getUniqueId()
Returns:
Returns the id.

addToken

public boolean addToken(TokenI token,
                        int position)
Specified by:
addToken in interface TokenHolder

addObject

public boolean addObject(Moveable object,
                         int[] position)
Description copied from interface: MoveableHolder
Add an object to its list at a certain position.

Specified by:
addObject in interface MoveableHolder
Parameters:
object - The Moveable object to be added.
position - Position to insert object at. O: at front, -1, at end, >0: at that position.
Returns:
True if successful.

removeObject

public boolean removeObject(Moveable object)
Specified by:
removeObject in interface MoveableHolder

getTokens

public java.util.List<TokenI> getTokens()
Specified by:
getTokens in interface TokenHolder
Returns:
ArrayList of all tokens we have.

hasTokens

public boolean hasTokens()
Description copied from interface: TokenHolder
Do we have any tokens?

Specified by:
hasTokens in interface TokenHolder
Returns:
Boolean

getSlots

public int getSlots()

hasTokenSlotsLeft

public boolean hasTokenSlotsLeft()

getTokenSlotsLeft

public int getTokenSlotsLeft()

removeToken

public boolean removeToken(TokenI token)
Description copied from interface: TokenHolder
Remove a token. Subclasses may override this method to implement side effects.

Specified by:
removeToken in interface TokenHolder
Parameters:
token - The token object to remove.
Returns:
True if successful.

hasTokenOf

public boolean hasTokenOf(PublicCompanyI company)
Parameters:
company -
Returns:
true if this City already contains an instance of the specified company's token. Do this by calling the hasTokenOf with Company Name. Using a tokens.contains(company) fails since the tokens are a ArrayList of TokenI not a ArrayList of PublicCompanyI.

hasTokenOf

public boolean hasTokenOf(java.lang.String companyName)

getListIndex

public int[] getListIndex(Moveable object)
Specified by:
getListIndex in interface MoveableHolder

setTokens

public void setTokens(java.util.ArrayList<TokenI> tokens)

getTrackEdges

public java.lang.String getTrackEdges()

setTrackEdges

public void setTrackEdges(java.lang.String trackEdges)

toString

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