Package dev.davwheat

Class Player


  • public class Player
    extends java.lang.Object
    A Player who is engaged in the current game.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int playerId
      The player's index in the Game's list of all players.
      java.lang.String playerName
      The player's name.
      char playerVisualIdentifier
      Visual identifier for the player.
    • Constructor Summary

      Constructors 
      Constructor Description
      Player​(java.lang.String name, int playerId, Game game, char playerVisualIdentifier)
      Create a new instance of Player.
    • Method Summary

      Modifier and Type Method Description
      double adjustBankBalance​(double change)
      Adjusts the Player's bank balance by a fixed amount.
      double adjustBankBalance​(double change, Player reciprocalActionPlayer)
      Adjusts the Player's bank balance by a fixed amount.
      double getBankBalance()
      Gets the Player's bank balance.
      BoardSpace getBoardSpaceAtPlayerPosition()
      Get the BoardSpace that the user is currently on.
      boolean hasLost()
      Gets if a player has gone bankrupt (negative money).
      void makeMissNextTurn()
      Makes this player miss their next turn.
      BoardSpace movePlayer​(int spaces)
      Moves a player by a specified number of spaces.
      void startTurn()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • playerId

        public final int playerId
        The player's index in the Game's list of all players.

        Starts at 0.

      • playerName

        public final java.lang.String playerName
        The player's name.
      • playerVisualIdentifier

        public final char playerVisualIdentifier
        Visual identifier for the player. Acts as a way to identify the player on the game board.
    • Constructor Detail

      • Player

        public Player​(java.lang.String name,
                      int playerId,
                      Game game,
                      char playerVisualIdentifier)
        Create a new instance of Player.
        Parameters:
        name - The Player's name
        playerId - The Player's ID (0-index in game's list of players)
        game - The current game instance.
        playerVisualIdentifier - The visual identifier to use to show the player on the game board.
    • Method Detail

      • movePlayer

        public BoardSpace movePlayer​(int spaces)
        Moves a player by a specified number of spaces.
        Parameters:
        spaces - Number of spaces to move.
        Returns:
        The new board space the player is at.
      • getBoardSpaceAtPlayerPosition

        public BoardSpace getBoardSpaceAtPlayerPosition()
        Get the BoardSpace that the user is currently on.
        Returns:
        The board space that the player is located on.
      • getBankBalance

        public double getBankBalance()
        Gets the Player's bank balance.
        Returns:
        bank balance
      • adjustBankBalance

        public double adjustBankBalance​(double change,
                                        Player reciprocalActionPlayer)
                                 throws InsufficientBalanceException
        Adjusts the Player's bank balance by a fixed amount.

        You can also pass another Player here to adjust their balance by the opposite amount!

        For example... "adjustBankBalance(5, player2);" will add £5 to this player, removes £5 from player2.

        Parameters:
        change - Amount to change the balance by (+/-)
        reciprocalActionPlayer - An player to perform the opposite change on.
        Returns:
        New player balance.
        Throws:
        InsufficientBalanceException
      • adjustBankBalance

        public double adjustBankBalance​(double change)
                                 throws InsufficientBalanceException
        Adjusts the Player's bank balance by a fixed amount.

        You can also pass another Player here to adjust their balance by the opposite amount!

        For example... "adjustBankBalance(5, player2);" will add £5 to this player, removes £5 from player2.

        Parameters:
        change - Amount to change the balance by (+/-)
        Returns:
        New player balance.
        Throws:
        InsufficientBalanceException
      • hasLost

        public boolean hasLost()
        Gets if a player has gone bankrupt (negative money).

        £0 is not bankrupt, as they could earn money from someone landing on their animal.

        Returns:
        Player has lost
      • makeMissNextTurn

        public void makeMissNextTurn()
        Makes this player miss their next turn.
      • startTurn

        public void startTurn()