Class Game
java.lang.Object
castle.comp3021.assignment.protocol.Game
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
JesonMor
public abstract class Game
extends java.lang.Object
implements java.lang.Cloneable
The Game class
-
Field Summary
Fields Modifier and Type Field Description protected Piece[][]
board
protected Configuration
configuration
Game configurationprotected Player
currentPlayer
Current player who is supposed to make a move.protected int
numMoves
The current number of moves made by two players -
Constructor Summary
Constructors Constructor Description Game(Configuration configuration)
-
Method Summary
Modifier and Type Method Description Game
clone()
abstract @NotNull Move[]
getAvailableMoves(Player player)
Get all available moves of one player.Place
getCentralPlace()
Configuration
getConfiguration()
Player
getCurrentPlayer()
int
getNumMoves()
@Nullable Piece
getPiece(int x, int y)
@Nullable Piece
getPiece(@NotNull Place place)
Get the piece in the placePlayer[]
getPlayers()
abstract Player
getWinner(Player lastPlayer, Piece lastPiece, Move lastMove)
Get the winner of the game.abstract void
movePiece(@NotNull Move move)
Make a move.void
refreshOutput()
Refresh the output printed in the console, which shows the following things.abstract Player
start()
Start the game Players will take turns according to the order inConfiguration.getPlayers()
to make a move until a player wins.abstract void
updateScore(Player player, Piece piece, Move move)
Update the score of a player according to the piece and corresponding move made by him just now.
-
Field Details
-
configuration
Game configuration -
board
The gameboard, which is a 2-dimensional array ofPiece
, representing all thePlace
(squares) on the board. If there is a piece in somePlace
place(x,y), thenboard[place.x()][place.y()]
will be the piece object, otherwise null. In other words, the board is a 2-D array with length equal to size of the board in both dimensions. -
currentPlayer
Current player who is supposed to make a move. -
numMoves
protected int numMovesThe current number of moves made by two players
-
-
Constructor Details
-
Method Details
-
start
Start the game Players will take turns according to the order inConfiguration.getPlayers()
to make a move until a player wins.- Returns:
- the winner
-
getWinner
Get the winner of the game. If there is no winner yet, return null;- Parameters:
lastPlayer
- the last player who makes a movelastPiece
- the last piece that is moved by the playerlastMove
- the last move made by lastPlayer- Returns:
- the winner if it exists, otherwise return null
-
updateScore
Update the score of a player according to the piece and corresponding move made by him just now.- Parameters:
player
- the player who just makes a movepiece
- the piece that is just movedmove
- the move that is just made
-
movePiece
Make a move.- Parameters:
move
- the move to make
-
getAvailableMoves
Get all available moves of one player.- Parameters:
player
- the player whose available moves to get- Returns:
- an array of available moves
-
refreshOutput
public void refreshOutput()Refresh the output printed in the console, which shows the following things. 1. the gameboard and pieces on it 2. scores of the players 3. other help information -
getPiece
Get the piece in the place- Parameters:
place
- the place of the piece- Returns:
- the piece
-
getPiece
-
getCurrentPlayer
-
getPlayers
-
getNumMoves
public int getNumMoves() -
getConfiguration
-
getCentralPlace
-
clone
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-