rails.game
Class StockSpace

java.lang.Object
  extended by java.util.Observable
      extended by rails.game.model.ModelObject
          extended by rails.game.StockSpace
All Implemented Interfaces:
StockSpaceI

public class StockSpace
extends ModelObject
implements StockSpaceI

Objects of this class represent a square on the StockMarket.


Field Summary
protected  boolean belowLedge
           
protected  boolean closesCompany
           
protected  java.lang.String colour
           
protected  int column
           
protected  boolean endsGame
           
protected  java.util.ArrayList<PublicCompanyI> fixedStartPrices
           
protected  boolean leftOfLedge
           
protected static org.apache.log4j.Logger log
           
protected  java.lang.String name
           
protected  int price
           
protected  int row
           
protected  boolean start
           
protected  java.util.ArrayList<PublicCompanyI> tokens
           
protected  StockSpaceTypeI type
           
 
Fields inherited from class rails.game.model.ModelObject
dependents, option
 
Fields inherited from interface rails.game.StockSpaceI
BELOW_LEDGE_TAG, CLOSES_COMPANY_TAG, ELEMENT_ID, GAME_OVER_TAG, LEFT_OF_LEDGE_TAG, NAME_TAG, PRICE_TAG, START_SPACE_TAG, TYPE_TAG
 
Constructor Summary
StockSpace(java.lang.String name, int price)
           
StockSpace(java.lang.String name, int price, StockSpaceTypeI type)
           
 
Method Summary
 void addFixedStartPrice(PublicCompanyI company)
           
 boolean addToken(PublicCompanyI company)
          Add a token at the end of the array (i.e.
 boolean addTokenAtStackPosition(PublicCompanyI company, int stackPosition)
           
 boolean closesCompany()
           
 boolean endsGame()
           
 java.awt.Color getColour()
           
 int getColumn()
           
 java.util.List<PublicCompanyI> getFixedStartPrices()
           
 java.lang.String getName()
           
 int getPrice()
           
 int getRow()
           
 int getStackPosition(PublicCompanyI company)
          Find the stack position of a company token
 java.lang.String getText()
          The object that is sent to the Observer along with a notification.
 java.util.List<PublicCompanyI> getTokens()
           
 StockSpaceTypeI getType()
           
 boolean hasTokens()
           
 boolean isBelowLedge()
           
 boolean isLeftOfLedge()
           
 boolean isNoBuyLimit()
           
 boolean isNoCertLimit()
           
 boolean isNoHoldLimit()
           
 boolean isStart()
           
 boolean removeToken(PublicCompanyI company)
          Remove a token from the pile.
 void setBelowLedge(boolean b)
           
 void setClosesCompany(boolean b)
           
 void setEndsGame(boolean b)
           
 void setLeftOfLedge(boolean b)
           
 void setStart(boolean b)
           
 java.lang.String toString()
           
 
Methods inherited from class rails.game.model.ModelObject
addDependent, addObserver, getUpdate, removeDependent, resetOption, setOption, update
 
Methods inherited from class java.util.Observable
clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

row

protected int row

column

protected int column

price

protected int price

colour

protected java.lang.String colour

belowLedge

protected boolean belowLedge

leftOfLedge

protected boolean leftOfLedge

closesCompany

protected boolean closesCompany

endsGame

protected boolean endsGame

start

protected boolean start

type

protected StockSpaceTypeI type

tokens

protected java.util.ArrayList<PublicCompanyI> tokens

fixedStartPrices

protected java.util.ArrayList<PublicCompanyI> fixedStartPrices

log

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

StockSpace

public StockSpace(java.lang.String name,
                  int price,
                  StockSpaceTypeI type)

StockSpace

public StockSpace(java.lang.String name,
                  int price)
Method Detail

addToken

public boolean addToken(PublicCompanyI company)
Add a token at the end of the array (i.e. at the bottom of the pile) Always returns true;

Specified by:
addToken in interface StockSpaceI
Parameters:
company - The company object to add.

addTokenAtStackPosition

public boolean addTokenAtStackPosition(PublicCompanyI company,
                                       int stackPosition)
Specified by:
addTokenAtStackPosition in interface StockSpaceI

removeToken

public boolean removeToken(PublicCompanyI company)
Remove a token from the pile.

Specified by:
removeToken in interface StockSpaceI
Parameters:
company - The company object to remove.
Returns:
False if the token was not found.

getTokens

public java.util.List<PublicCompanyI> getTokens()
Specified by:
getTokens in interface StockSpaceI
Returns:

getStackPosition

public int getStackPosition(PublicCompanyI company)
Find the stack position of a company token

Specified by:
getStackPosition in interface StockSpaceI
Returns:
Stock position: 0 = top, increasing towards the bottom. -1 if not found.

addFixedStartPrice

public void addFixedStartPrice(PublicCompanyI company)
Specified by:
addFixedStartPrice in interface StockSpaceI

getFixedStartPrices

public java.util.List<PublicCompanyI> getFixedStartPrices()
Specified by:
getFixedStartPrices in interface StockSpaceI

isBelowLedge

public boolean isBelowLedge()
Specified by:
isBelowLedge in interface StockSpaceI
Returns:
TRUE is the square is just above a ledge.

closesCompany

public boolean closesCompany()
Specified by:
closesCompany in interface StockSpaceI
Returns:
TRUE if the square closes companies landing on it.

getColour

public java.awt.Color getColour()
Specified by:
getColour in interface StockSpaceI
Returns:
The square's colour.

endsGame

public boolean endsGame()
Specified by:
endsGame in interface StockSpaceI
Returns:
TRUE if the rails.game ends if a company lands on this square.

getPrice

public int getPrice()
Specified by:
getPrice in interface StockSpaceI
Returns:
The stock price associated with the square.

getColumn

public int getColumn()
Specified by:
getColumn in interface StockSpaceI
Returns:

getName

public java.lang.String getName()
Specified by:
getName in interface StockSpaceI
Returns:

getType

public StockSpaceTypeI getType()
Specified by:
getType in interface StockSpaceI
Returns:

getRow

public int getRow()
Specified by:
getRow in interface StockSpaceI
Returns:

isStart

public boolean isStart()
Specified by:
isStart in interface StockSpaceI
Returns:

isLeftOfLedge

public boolean isLeftOfLedge()
Specified by:
isLeftOfLedge in interface StockSpaceI
Returns:

isNoBuyLimit

public boolean isNoBuyLimit()
Specified by:
isNoBuyLimit in interface StockSpaceI
Returns:

isNoCertLimit

public boolean isNoCertLimit()
Specified by:
isNoCertLimit in interface StockSpaceI
Returns:

isNoHoldLimit

public boolean isNoHoldLimit()
Specified by:
isNoHoldLimit in interface StockSpaceI
Returns:

setBelowLedge

public void setBelowLedge(boolean b)
Specified by:
setBelowLedge in interface StockSpaceI
Parameters:
b - See isAboveLedge.

setClosesCompany

public void setClosesCompany(boolean b)
Specified by:
setClosesCompany in interface StockSpaceI
Parameters:
b - See isClosesCompany.

setEndsGame

public void setEndsGame(boolean b)
Specified by:
setEndsGame in interface StockSpaceI
Parameters:
b - See isEndsGame.

setStart

public void setStart(boolean b)
Specified by:
setStart in interface StockSpaceI
Parameters:
set - space as a starting space

setLeftOfLedge

public void setLeftOfLedge(boolean b)
Specified by:
setLeftOfLedge in interface StockSpaceI
Parameters:
set - if token is left of ledge

hasTokens

public boolean hasTokens()
Specified by:
hasTokens in interface StockSpaceI
Returns:
Returns if the space hasTokens.

getText

public java.lang.String getText()
Description copied from class: ModelObject
The object that is sent to the Observer along with a notification. The default result is the Observable's toString(), but it can be overridden where needed.

Specified by:
getText in class ModelObject
Returns:

toString

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