public class Game
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private boolean |
autoPlay |
private Board |
board |
private static int |
CHANCE_COLLECT_50 |
private static int |
CHANCE_GO_TO_GO |
private static int |
CHANCE_GO_TO_JAIL |
private static int |
CHANCE_LOSE_50 |
private static int |
CHANCE_PAY_50 |
private static int |
CHANCE_WIN_50 |
private int |
currentPlayer |
private static int |
MONEY_GO |
private static int |
MONEY_JAIL |
private Player[] |
players |
private MonopolyUI |
ui |
| Constructor and Description |
|---|
Game(Player[] players)
Construct a new Game with an array of players.
|
Game(Player[] players,
java.lang.String filename)
Construct a new Game with an array of players and a file that
contains board information.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
buyHouseForProperty(Player player,
Property property)
Player purchases a house for the specified property
|
private void |
buyHouses(Player player)
Builds a list of properties for which a player may purchase houses
and prompts them to purchase on or more houses
|
private Player |
determineWinner()
Determines the winner of the game.
|
void |
enableAutoPlay()
Enables automatic game play.
|
Board |
getBoard()
Get the playing board.
|
Player |
getCurrentPlayer()
Get the current player.
|
Player[] |
getPlayers()
Get an array of all players.
|
private boolean |
hasLoser()
Determines if any player has lost the game.
|
private void |
landedOnChance(Player player)
Handles game play when a player lands on a chance space.
|
private void |
landedOnGoToJail(Player player)
Handles game play when a player lands on "go to jail."
|
private void |
landedOnProperty(Player player,
Property property)
Handles game play when a player lands on a particular property.
|
private void |
movePlayer(Player player,
int distance)
Moves a player a specific number of spaces around the board.
|
private void |
moveToSpace(Player player,
int location) |
void |
play(MonopolyUI ui)
Plays the game.
|
private void |
printNetWorths()
Prints the net worth of the players
|
private int |
rollDice()
Rolls two dice and returns their sum; updates the ui also.
|
private void |
switchToNextPlayer()
Switch game play to the next player's turn.
|
private void |
takeTurn(Player player)
Handles a whole turn for a player.
|
private static final int MONEY_GO
private static final int MONEY_JAIL
private static final int CHANCE_GO_TO_JAIL
private static final int CHANCE_GO_TO_GO
private static final int CHANCE_WIN_50
private static final int CHANCE_LOSE_50
private static final int CHANCE_PAY_50
private static final int CHANCE_COLLECT_50
private Board board
private Player[] players
private int currentPlayer
private MonopolyUI ui
private boolean autoPlay
public Game(Player[] players)
players - The game playerspublic Game(Player[] players,
java.lang.String filename)
players - The game playersfilename - A file containing a description of the boardpublic Board getBoard()
public Player[] getPlayers()
public Player getCurrentPlayer()
public void enableAutoPlay()
public void play(MonopolyUI ui)
Game play continues until a player has lost, at which point a winner is declared.
ui - The user interface for this gameprivate void takeTurn(Player player)
Players may purchase houses for their owned properties at the start of their turn.
Players then roll the dice, move around the board, and may perform actions based on the space on which they land.
player - The current playerprivate void buyHouses(Player player)
player - The current playerprivate void buyHouseForProperty(Player player,
Property property)
player - The current playerproperty - The property to be purchasedprivate int rollDice()
private void movePlayer(Player player,
int distance)
Players collect $200 when the pass the "Go!" space.
player - The current playerdistance - The number of spaces to move around th boardprivate void landedOnProperty(Player player,
Property property)
If a player does not own a property, they must pay rent to the current owner (if there is one), or they may purchase the property (if unowned).
player - The current playerproperty - The landed-on propertyprivate void landedOnGoToJail(Player player)
Player pays $50 fine and is transported to the jail spot, where they wait for their next turn. Because they have paid the fine, they are not considered to be "in jail," they are just visiting.
player - The current playerprivate void moveToSpace(Player player,
int location)
private void landedOnChance(Player player)
player - The current playerprivate void switchToNextPlayer()
private boolean hasLoser()
A player loses when their cash balance drops to or below $0.
private Player determineWinner()
The winner is defined as the player with the highest net worth; however, a player must have a non-negative cash balance to be considered for the winner position.
private void printNetWorths()