mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
commit
4d309d4321
58
src/main/java/inf112/fiasko/roborally/objects/Player.java
Normal file
58
src/main/java/inf112/fiasko/roborally/objects/Player.java
Normal file
@ -0,0 +1,58 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Player {
|
||||
private final RobotID robotID;
|
||||
private final String name;
|
||||
private boolean powerDownNextRound = false;
|
||||
private ProgrammingCardDeck playerDeck;
|
||||
private List <ProgrammingCard> program = new ArrayList();
|
||||
|
||||
// Constructor for the player class, it get assigned a Robot, a player nam and a deck
|
||||
public Player(RobotID robotID, String name, ProgrammingCardDeck playerDeck) {
|
||||
this.robotID = robotID;
|
||||
this.name = name;
|
||||
this.playerDeck = playerDeck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives you the RobotID of a player
|
||||
* @return An RobotID
|
||||
*/
|
||||
public RobotID getRobotID(){return robotID;}
|
||||
|
||||
public String getName() {return name;}
|
||||
|
||||
public List<ProgrammingCard> getProgram() {return program;}
|
||||
|
||||
public ProgrammingCardDeck getPlayerDeck() {return playerDeck;}
|
||||
|
||||
public boolean getPowerDownNextRound() { return powerDownNextRound;}
|
||||
|
||||
public void setPowerDownNextRound(boolean powerDownStatus) { this.powerDownNextRound = powerDownStatus;}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Program deck is full,tried to add to many cards");
|
||||
}
|
||||
|
||||
|
||||
public ProgrammingCard removeProgramCard(int cardNr) {
|
||||
program.add(cardNr, null);
|
||||
return program.remove(cardNr+1);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package inf112.fiasko.roborally.objects;
|
||||
|
||||
import inf112.fiasko.roborally.element_properties.Action;
|
||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PlayerTest {
|
||||
private Player playerTest;
|
||||
@Before
|
||||
public void setUp() {
|
||||
List<ProgrammingCard> cards = new ArrayList();
|
||||
cards.add(new ProgrammingCard(10, Action.MOVE_1));
|
||||
cards.add(new ProgrammingCard(20, Action.MOVE_2));
|
||||
cards.add(new ProgrammingCard(30, Action.MOVE_3));
|
||||
cards.add(new ProgrammingCard(40, Action.BACK_UP));
|
||||
cards.add(new ProgrammingCard(50, Action.ROTATE_LEFT));
|
||||
ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards);
|
||||
playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" ,playerDeck);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPowerDownStatusToTrue() {
|
||||
playerTest.setPowerDownNextRound(true);
|
||||
assertEquals(true, playerTest.getPowerDownNextRound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPowerDownStatusToFalse() {
|
||||
playerTest.setPowerDownNextRound(false);
|
||||
assertEquals(false, playerTest.getPowerDownNextRound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cardGetsInsertedIntoProgram() {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user