|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcore.Game
public class Game
A mutable class containing all the information about a game. This keeps track of game stuff that generally isn't game specific (like time, move history etc.)
game_state
: Object // the current state of the board and related
data
players
: set // the 2 players playing the game and corresponding
colors
current_player
: player // the current player to move next
move_history
: list // the previous moves in this game
time_for_players
: ints // the amount of time left for each player
winner
: enum // if there is a winner, who it is
win_reason
: enum // if someone won, how they won
xml
: string // an xml representation of the board
timed
: boolean // wether or not the game is timed
Abstract Invariant: Constructor Summary | |
---|---|
Game(Player player1,
int player1Time,
Player player2,
int player2Time)
Creates a new Game instance with Players and starting times. |
|
Game(Player player1,
int player1Time,
Player player2,
int player2Time,
String powerups)
|
|
Game(Player player1,
Player player2)
Creates a new Game instance with Players and no times. |
Method Summary | |
---|---|
Player |
getCurrentPlayer()
Gives the current player to move. |
GameState |
getGameState()
Returns a mutable copy of the gamestate (changing it will change the game). |
List<Move> |
getMoveHistory()
History of moves that have been made so far, from first to last. |
Player |
getPlayerByColor(Color color)
A mapping from colors to players |
List<Player> |
getPlayers()
Gives an immutable list of the players, with first player first |
int |
getTimeLeftForPlayer(Player player)
A mapping from a player to the time left for that player |
Color |
getWinner()
Gives the winner if there is one. |
GameOver |
getWinReason()
Gives the reason for winning if there is one. |
String |
getXML()
Returns the XML for the game as a string. |
static Game |
loadGame(Player player1,
Player player2,
File xmlFile)
Loads a game given an xml file and the initial players. |
static Game |
loadGame(Player player1,
Player player2,
String xmlString)
Loads a game given an xml string and the initial players. |
void |
makeMove(Move move)
Makes a move (if it is valid), also saving it the move history (if it is not a pass). |
void |
setTime(Player player,
int t)
Sets the time for a player. |
void |
subtractTimeLeftForPlayer(Player player,
int amount)
Subtracts amount from current time of the player (calls setTime, so updated winner if needed). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Game(Player player1, Player player2)
player1
- the player that goes first, must have Color WHITEplayer2
- the player that goes second, must have Color BLACKpublic Game(Player player1, int player1Time, Player player2, int player2Time)
player1
- the player that goes first, must have Color WHITEplayer1Time
- time for player1player2
- the player that goes second, must have Color BLACKplayer2Time
- time for player2public Game(Player player1, int player1Time, Player player2, int player2Time, String powerups)
Method Detail |
---|
public static Game loadGame(Player player1, Player player2, File xmlFile) throws GameLoadException
player1
- white playerplayer2
- black playerxmlFile
- file with file format linked to above
GameLoadException
- contains a user intended error messagepublic static Game loadGame(Player player1, Player player2, String xmlString) throws GameLoadException
player1
- white playerplayer2
- black playerxmlString
- string with format linked to above
GameLoadException
- contains a user intended error messagepublic String getXML()
public void makeMove(Move move)
move
- the move to make
RuntimeException
- if the move is invalidpublic GameState getGameState()
public List<Move> getMoveHistory()
public Color getWinner()
public GameOver getWinReason()
public void setTime(Player player, int t)
player
- The player whose time to changet
- The new timepublic void subtractTimeLeftForPlayer(Player player, int amount)
player
- The player whose time to changeamount
- The new timepublic int getTimeLeftForPlayer(Player player)
player
- player to get the time ofpublic Player getPlayerByColor(Color color)
color
- the color of the player to getpublic List<Player> getPlayers()
public Player getCurrentPlayer()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |