Package dev.davwheat
Class Player
- java.lang.Object
-
- dev.davwheat.Player
-
public class Player extends java.lang.ObjectA Player who is engaged in the current game.
-
-
Field Summary
Fields Modifier and Type Field Description intplayerIdThe player's index in the Game's list of all players.java.lang.StringplayerNameThe player's name.charplayerVisualIdentifierVisual identifier for the player.
-
Method Summary
Modifier and Type Method Description doubleadjustBankBalance(double change)Adjusts the Player's bank balance by a fixed amount.doubleadjustBankBalance(double change, Player reciprocalActionPlayer)Adjusts the Player's bank balance by a fixed amount.doublegetBankBalance()Gets the Player's bank balance.BoardSpacegetBoardSpaceAtPlayerPosition()Get the BoardSpace that the user is currently on.booleanhasLost()Gets if a player has gone bankrupt (negative money).voidmakeMissNextTurn()Makes this player miss their next turn.BoardSpacemovePlayer(int spaces)Moves a player by a specified number of spaces.voidstartTurn()
-
-
-
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 nameplayerId- 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 InsufficientBalanceExceptionAdjusts 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 InsufficientBalanceExceptionAdjusts 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()
-
-