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 Details

    • configuration

      protected Configuration configuration
      Game configuration
    • board

      protected Piece[][] board
      The gameboard, which is a 2-dimensional array of Piece, representing all the Place (squares) on the board. If there is a piece in some Place place(x,y), then board[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

      protected Player currentPlayer
      Current player who is supposed to make a move.
    • numMoves

      protected int numMoves
      The current number of moves made by two players
  • Constructor Details

  • Method Details

    • start

      public abstract Player start()
      Start the game Players will take turns according to the order in Configuration.getPlayers() to make a move until a player wins.
      Returns:
      the winner
    • getWinner

      public abstract Player getWinner​(Player lastPlayer, Piece lastPiece, Move lastMove)
      Get the winner of the game. If there is no winner yet, return null;
      Parameters:
      lastPlayer - the last player who makes a move
      lastPiece - the last piece that is moved by the player
      lastMove - the last move made by lastPlayer
      Returns:
      the winner if it exists, otherwise return null
    • updateScore

      public 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.
      Parameters:
      player - the player who just makes a move
      piece - the piece that is just moved
      move - the move that is just made
    • movePiece

      public abstract void movePiece​(@NotNull @NotNull Move move)
      Make a move.
      Parameters:
      move - the move to make
    • getAvailableMoves

      @NotNull public abstract @NotNull Move[] getAvailableMoves​(Player player)
      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

      @Nullable public @Nullable Piece getPiece​(@NotNull @NotNull Place place)
      Get the piece in the place
      Parameters:
      place - the place of the piece
      Returns:
      the piece
    • getPiece

      @Nullable public @Nullable Piece getPiece​(int x, int y)
    • getCurrentPlayer

      public Player getCurrentPlayer()
    • getPlayers

      public Player[] getPlayers()
    • getNumMoves

      public int getNumMoves()
    • getConfiguration

      public Configuration getConfiguration()
    • getCentralPlace

      public Place getCentralPlace()
    • clone

      public Game clone() throws java.lang.CloneNotSupportedException
      Overrides:
      clone in class java.lang.Object
      Throws:
      java.lang.CloneNotSupportedException