2020-03-10 16:02:34 +01:00
|
|
|
package inf112.fiasko.roborally.objects;
|
|
|
|
|
|
|
|
import inf112.fiasko.roborally.element_properties.RobotID;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* This Class represents a player
|
|
|
|
*/
|
|
|
|
|
2020-03-10 16:02:34 +01:00
|
|
|
public class Player {
|
|
|
|
private final RobotID robotID;
|
|
|
|
private final String name;
|
|
|
|
private boolean powerDownNextRound = false;
|
|
|
|
private ProgrammingCardDeck playerDeck;
|
|
|
|
private List <ProgrammingCard> program = new ArrayList();
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2020-03-10 16:02:34 +01:00
|
|
|
public Player(RobotID robotID, String name, ProgrammingCardDeck playerDeck) {
|
|
|
|
this.robotID = robotID;
|
|
|
|
this.name = name;
|
|
|
|
this.playerDeck = playerDeck;
|
2020-03-12 11:24:20 +01:00
|
|
|
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);
|
2020-03-10 16:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gives you the RobotID of a player
|
|
|
|
* @return An RobotID
|
|
|
|
*/
|
|
|
|
public RobotID getRobotID(){return robotID;}
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* Gives you the Name of the player
|
|
|
|
* @return a player Name
|
|
|
|
*/
|
2020-03-10 16:02:34 +01:00
|
|
|
public String getName() {return name;}
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* Gives you the players program
|
|
|
|
* @return a list<ProgrammingCard>
|
|
|
|
*/
|
2020-03-10 16:02:34 +01:00
|
|
|
public List<ProgrammingCard> getProgram() {return program;}
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* Gives you the player hand/deck
|
|
|
|
* @return a deck
|
|
|
|
*/
|
2020-03-10 16:02:34 +01:00
|
|
|
public ProgrammingCardDeck getPlayerDeck() {return playerDeck;}
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* Gives you the players powerdown status
|
|
|
|
* @return a boolean
|
|
|
|
*/
|
2020-03-10 16:02:34 +01:00
|
|
|
public boolean getPowerDownNextRound() { return powerDownNextRound;}
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* Sets the prowerdown status
|
|
|
|
* @param powerDownStatus the boolean that determines if it goes to a powerdown or not
|
|
|
|
*/
|
2020-03-10 16:02:34 +01:00
|
|
|
public void setPowerDownNextRound(boolean powerDownStatus) { this.powerDownNextRound = powerDownStatus;}
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* Places a card in to the player program
|
|
|
|
* @param card the card that is placed in to the player program
|
|
|
|
*/
|
2020-03-10 16:02:34 +01:00
|
|
|
public void setCardInProgram(ProgrammingCard card) {
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
if (program.get(i) == null) {
|
|
|
|
program.add(i, card);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new IllegalArgumentException("Program deck is full,tried to add to many cards");
|
|
|
|
}
|
|
|
|
|
2020-03-12 11:24:20 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2020-03-10 16:02:34 +01:00
|
|
|
public ProgrammingCard removeProgramCard(int cardNr) {
|
2020-03-12 11:24:20 +01:00
|
|
|
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");
|
|
|
|
|
|
|
|
}
|
2020-03-10 16:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|