Monopoly
Class Monopoly

java.lang.Object
  extended by Monopoly.Monopoly

public class Monopoly
extends java.lang.Object

Invariant: Once created and until destroyed, this instance represents a Monopoly game with its grafical representation.


Field Summary
 GUI board
           
 
Constructor Summary
Monopoly()
          Creates a new Monopoly object.
 
Method Summary
 Player activePlayer()
          Returns the player who is playing (Accessor).
 void bankrupt()
          Removes the active player from the game after having notified him, and made all of his properties available for collection.
 void buyHouse(Street st)
          Notifies the active player that a house purchase request occured.
 void dept(int dept)
          Notifies the user (GUI) that the active player owes.
 Cell[] getCells()
          Returns the Cell Array which contains the cells of the game (Accessor).
 Card getCommandCard()
          Searches and returns the first Command Card (Accessor).
 java.util.Collection<Card> getCommandCards()
          Returns the Collection of the Property Cards (Accessor).
 Card getDecisionCard()
          Searches and returns the first Decision Card (Accessor).
 java.util.Collection<Card> getDecisionCards()
          Returns the Collection of the Decisions Cards (Accessor).
 java.lang.Object[] getHouseNames()
          Get the names of the streets which belong to the active player and can have a house removed from.
 Cell getJail()
          Returns the Jail Cell (Accessor).
 java.lang.Object[] getMortaged()
          Get the names of the properties which belong to the active player and are mortaged.
 Player getPlayer(java.lang.String name)
          Returns a Player with the given name (Accessor).
 java.util.Collection<Player> getPlayers()
          Returns the Players Collection (Accessor).
 java.lang.Object[] getPlayersNames()
          Get the names of all the players apart from the active one.
 Property getProperty(java.lang.String name)
          Returns a Property cell with the given name (Accessor).
 int[] getRoll()
          Returns the result of the roll of the dice (Accessor).
 Street getStreet(java.lang.String name)
          Returns a Street cell with the given name (Accessor).
 java.lang.Object[] getStreetsNames()
          Get the names of the streets which belong to the active player and can be built on.
 java.lang.Object[] getTradable(Player owner)
          Get the names of the properties which belong to the given Player and can be traded.
 java.lang.Object[] getUnmortaged()
          Get the names of the properties which belong to the active player and can be mortaged.
 void mortageProperty(Property pr)
          Notifies the active player that a mortage request occured.
 void movePlayer(int num, int cur, int des)
          Notifies the GUI that the active player has moved.
 void newPlayers(java.util.ArrayList names)
          Initializes the players collection, giving each new Player instance a String name and integer number.
 Player nextPlayer()
          Returns the player who will play after the active player (Accessor).
 void notEnoughMoney()
          Notifies the user (GUI) that he does not have enough money for the action he requested.
 void playTurn()
          Moves the game to the next round.
 boolean purchaseProperty()
          Notifies the user (GUI) that the active player can purchase a property.
 void refresh(int location, java.lang.String name, java.lang.String owner, int price, int rent, int housePrice)
          Notifies the GUI that a change has occured on the popup menus.
 void sellHouse(Street st)
          Notifies the active player that a house sail request occured.
 void showAct()
          Show an action on the GUI Central Window.
 void showAct(Card c)
          Show an action on the GUI Central Window.
 void showAct(Taxes t)
          Show an action on the GUI Central Window.
 void showRent(java.lang.String s)
          Inform the user (GUI) for a rent pay with a window.
 void unmortageProperty(Property pr)
          Notifies the active player that an unmortage request occured.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

board

public GUI board
Constructor Detail

Monopoly

public Monopoly()
Creates a new Monopoly object. Represents a Monopoly game with its grafic representation.

Method Detail

newPlayers

public void newPlayers(java.util.ArrayList names)
Initializes the players collection, giving each new Player instance a String name and integer number.

Parameters:
names - the list of names

getCells

public Cell[] getCells()
Returns the Cell Array which contains the cells of the game (Accessor).

Pre: true
Post: Returns the Cell Array

Returns:
The cells of the game (Cell[])

getRoll

public int[] getRoll()
Returns the result of the roll of the dice (Accessor).

Pre: true
Post: Returns the int Array (the result of the roll)

Returns:
The result of the roll (int[])

getJail

public Cell getJail()
Returns the Jail Cell (Accessor).

Pre: true
Post: Searches for the Jail cell and returns it

Returns:
The Jail cell (Cell)

getPlayers

public java.util.Collection<Player> getPlayers()
Returns the Players Collection (Accessor).

Pre: true
Post: Returns the Players collection

Returns:
The Players collection (Collection)

getDecisionCards

public java.util.Collection<Card> getDecisionCards()
Returns the Collection of the Decisions Cards (Accessor).

Pre: true
Post: Returns the Collection of the Decisions Cards

Returns:
The Collection of the Decisions Cards (Collection)

getDecisionCard

public Card getDecisionCard()
Searches and returns the first Decision Card (Accessor).

Pre: true
Post: Searches and returns the first Decision Card of the Collection of the Cards

Returns:
The first Decision card (Card)

getCommandCards

public java.util.Collection<Card> getCommandCards()
Returns the Collection of the Property Cards (Accessor).

Pre: true
Post: Returns the Collection of the Property Cards

Returns:
The Collection of the Property Cards (Collection)

getCommandCard

public Card getCommandCard()
Searches and returns the first Command Card (Accessor).

Pre: true
Post: Searches and returns the first Command Card of the Collection of the Cards

Returns:
The first Command Card (Card)

activePlayer

public Player activePlayer()
Returns the player who is playing (Accessor).

Pre: true
Post: Returns the Player who is playing - if there are no players the active Player is null

Returns:
The player who is playing -
or null if there are no players

nextPlayer

public Player nextPlayer()
Returns the player who will play after the active player (Accessor).

Pre: true
Post: Returns the next player - if there are no players the next player is null

Returns:
The player who will play after the active player -
or null if there are no players

getStreet

public Street getStreet(java.lang.String name)
Returns a Street cell with the given name (Accessor).

Pre: name must be different than zero
Post: if the street is found it is returned - else null is returned

Returns:
The Street with the given name (Street)-
or null if it is not found

getProperty

public Property getProperty(java.lang.String name)
Returns a Property cell with the given name (Accessor).

Pre: name must be different than zero
Post: if the property cell is found it is returned - else null is returned

Returns:
The Property with the given name (Property)-
or null if it is not found

getPlayer

public Player getPlayer(java.lang.String name)
Returns a Player with the given name (Accessor).

Pre: name must be different than zero
Post: if the Player is found he is returned - else null is returned

Returns:
The Player with the given name (Player)-
or null if it is not found

getTradable

public java.lang.Object[] getTradable(Player owner)
Get the names of the properties which belong to the given Player and can be traded.

Parameters:
owner - the player whose tradable properties will be returned
Returns:
an Object array containing the names as String objects
Precondition:
Always valid
Postcondition:
The names returned belong to Collectable objects
which have the parameter as owner and if they are Street
objects don't have any houses on them

getUnmortaged

public java.lang.Object[] getUnmortaged()
Get the names of the properties which belong to the active player and can be mortaged.

Returns:
an Object array containing the names as String objects
Precondition:
Always valid
Postcondition:
The names returned belong to Property objects
which are not mortaged and if they are Street
objects don't have any houses on them

getStreetsNames

public java.lang.Object[] getStreetsNames()
Get the names of the streets which belong to the active player and can be built on.

Returns:
an Object array containing the names as String objects
Precondition:
Always valid
Postcondition:
The names returned belong to Street objects
which are not mortaged and if a house where
to be built, it would not affect the housing
rule.

getHouseNames

public java.lang.Object[] getHouseNames()
Get the names of the streets which belong to the active player and can have a house removed from.

Returns:
an Object array containing the names as String objects
Precondition:
Always valid
Postcondition:
The names returned belong to Street objects
that have houses and removing a house from them
would not affect the housing rule.

getMortaged

public java.lang.Object[] getMortaged()
Get the names of the properties which belong to the active player and are mortaged.

Returns:
an Object array containing the names as String objects
Precondition:
Always valid
Postcondition:
The names returned belong to Property objects which are mortaged.

getPlayersNames

public java.lang.Object[] getPlayersNames()
Get the names of all the players apart from the active one.

Returns:
an Object array containing the names as String objects
Precondition:
Always valid
Postcondition:
The names returned belong to Player objects which are
valid players of this game and are not the active player.

buyHouse

public void buyHouse(Street st)
Notifies the active player that a house purchase request occured. If the player does not buy the house (because of money shortage) the "NOT ENOUGH MONEY" window notifies the user (GUI).

Parameters:
st - the Street to add the house to

sellHouse

public void sellHouse(Street st)
Notifies the active player that a house sail request occured.

Parameters:
st - the Street to remove the house from

mortageProperty

public void mortageProperty(Property pr)
Notifies the active player that a mortage request occured.

Parameters:
pr - the Property to mortage

unmortageProperty

public void unmortageProperty(Property pr)
Notifies the active player that an unmortage request occured. If the player does not unmortage the property (because of money shortage) the "NOT ENOUGH MONEY" window notifies the user (GUI).

Parameters:
pr - the Property to unmortage

purchaseProperty

public boolean purchaseProperty()
Notifies the user (GUI) that the active player can purchase a property.

Returns:
true if the user answered positively; false otherwise.

bankrupt

public void bankrupt()
Removes the active player from the game after having notified him, and made all of his properties available for collection.


dept

public void dept(int dept)
Notifies the user (GUI) that the active player owes.

Parameters:
dept - the amount he owes

notEnoughMoney

public void notEnoughMoney()
Notifies the user (GUI) that he does not have enough money for the action he requested.


movePlayer

public void movePlayer(int num,
                       int cur,
                       int des)
Notifies the GUI that the active player has moved.

Parameters:
num - the cardinal number of the player who moved
cur - the initial position on the board
des - the destination

refresh

public void refresh(int location,
                    java.lang.String name,
                    java.lang.String owner,
                    int price,
                    int rent,
                    int housePrice)
Notifies the GUI that a change has occured on the popup menus.

Parameters:
location - the number of the Cell that changed
name - the name of the Cell
owner -
price -
rent -
housePrice -

showAct

public void showAct()
Show an action on the GUI Central Window.


showAct

public void showAct(Card c)
Show an action on the GUI Central Window.


showAct

public void showAct(Taxes t)
Show an action on the GUI Central Window.


showRent

public void showRent(java.lang.String s)
Inform the user (GUI) for a rent pay with a window.


playTurn

public void playTurn()
Moves the game to the next round. Checks whether the game has finished, moves to the next player and proceeds according to whether he is in prison or no.