From 4f9d58152c4611928acbdd25c0e34af433b9bf72 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 12 Mar 2020 11:24:20 +0100 Subject: [PATCH] Added comments to Player --- .../fiasko/roborally/objects/Player.java | 60 ++++++++++++++++--- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Player.java b/src/main/java/inf112/fiasko/roborally/objects/Player.java index 7e28586..75908b3 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Player.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Player.java @@ -5,6 +5,10 @@ import inf112.fiasko.roborally.element_properties.RobotID; import java.util.ArrayList; import java.util.List; +/** + * This Class represents a player + */ + public class Player { private final RobotID robotID; private final String name; @@ -12,11 +16,21 @@ public class Player { private ProgrammingCardDeck playerDeck; private List program = new ArrayList(); - // Constructor for the player class, it get assigned a Robot, a player nam and a deck + /** + * Instantiates a new player + * @param robotID the global identifier of the robot + * @param name the unique name of the player + * @param playerDeck the hand of cards dealt to the player + */ public Player(RobotID robotID, String name, ProgrammingCardDeck playerDeck) { this.robotID = robotID; this.name = name; this.playerDeck = playerDeck; + program.add(0, null); //sets the initial values in program to null + program.add(1, null); + program.add(2, null); + program.add(3, null); + program.add(4, null); } /** @@ -25,22 +39,42 @@ public class Player { */ public RobotID getRobotID(){return robotID;} + /** + * Gives you the Name of the player + * @return a player Name + */ public String getName() {return name;} + /** + * Gives you the players program + * @return a list + */ public List getProgram() {return program;} + /** + * Gives you the player hand/deck + * @return a deck + */ public ProgrammingCardDeck getPlayerDeck() {return playerDeck;} + /** + * Gives you the players powerdown status + * @return a boolean + */ public boolean getPowerDownNextRound() { return powerDownNextRound;} + /** + * Sets the prowerdown status + * @param powerDownStatus the boolean that determines if it goes to a powerdown or not + */ public void setPowerDownNextRound(boolean powerDownStatus) { this.powerDownNextRound = powerDownStatus;} + /** + * Places a card in to the player program + * @param card the card that is placed in to the player program + */ public void setCardInProgram(ProgrammingCard card) { for (int i = 0; i < 5; i++) { - if (program.size() == 0) { - program.add(i, card); - return; - } if (program.get(i) == null) { program.add(i, card); return; @@ -49,10 +83,20 @@ public class Player { throw new IllegalArgumentException("Program deck is full,tried to add to many cards"); } - + /** + * Removes a card by the given index from the player program and returns it. + * @param cardNr the index of the card that is being removed + * @return the card that was removed from the program + */ public ProgrammingCard removeProgramCard(int cardNr) { - program.add(cardNr, null); - return program.remove(cardNr+1); + if(cardNr<5 && cardNr>-1) { + program.add(cardNr, null); + return program.remove(cardNr + 1); + } + else{ + throw new IllegalArgumentException("cant remove more then index 4 or remove negatives"); + + } } }