diff --git a/docs/team/referater/referat_12_03_2020.md b/docs/team/referater/referat_12_03_2020.md new file mode 100644 index 0000000..eae6cdd --- /dev/null +++ b/docs/team/referater/referat_12_03_2020.md @@ -0,0 +1,5 @@ +## Oppmøte +Alle i teamet var tilstede. + +## Gjennomgått +Vi har jobbet med parprogrammering. \ No newline at end of file diff --git a/pom.xml b/pom.xml index 267c8f9..b8996ba 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,13 @@ 1.8 + + + clojars + http://clojars.org/repo/ + + + @@ -53,6 +60,18 @@ natives-desktop + + com.esotericsoftware + kryo + 5.0.0-RC5 + + + + kryonet + kryonet + 2.21 + + junit junit diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 3414d49..5ab22dc 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -251,7 +251,7 @@ public class Board { * @param position The position to check * @return The robot id of the robot on the position or null if there is no robot there */ - private RobotID getRobotOnPosition(Position position) { + RobotID getRobotOnPosition(Position position) { for (RobotID robotID : robots.keySet()) { Robot robot = robots.get(robotID); if (position.equals(robot.getPosition())) { @@ -266,7 +266,7 @@ public class Board { * @param position The position to check * @return True if there is a robot on the specified position */ - private boolean hasRobotOnPosition(Position position) { + boolean hasRobotOnPosition(Position position) { return getRobotOnPosition(position) != null; } diff --git a/src/main/java/inf112/fiasko/roborally/objects/Deck.java b/src/main/java/inf112/fiasko/roborally/objects/Deck.java index 9988b04..4d0b8dc 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Deck.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Deck.java @@ -18,6 +18,9 @@ public abstract class Deck implements IDeck { this.cardList = new ArrayList<>(cardList); } + /** + * Randomises the order of the deck + */ @Override public void shuffle() { Random randomGenerator = new Random(); @@ -31,12 +34,21 @@ public abstract class Deck implements IDeck { } } + /** + * Draws one card from the other deck + * @param other The deck to draw the card from + */ @Override public void draw(IDeck other) { Deck otherDeck = (Deck) other; cardList.add(otherDeck.cardList.remove(0)); } + /** + * Draws multiple cards from the other deck + * @param other The other deck to draw from + * @param n The number of cards to draw + */ @Override public void draw(IDeck other, int n) { Deck otherDeck = (Deck) other; @@ -48,27 +60,47 @@ public abstract class Deck implements IDeck { } } + /** + * Empty the entire deck into the other deck + * @param other The deck to move this deck's cards into + */ @Override public void emptyInto(IDeck other) { Deck otherDeck = (Deck) other; otherDeck.draw(this, this.size()); } + /** + * Checks if the deck is empty + * @return Boolean for if the deck is empty + */ @Override public boolean isEmpty() { return cardList.isEmpty(); } + /** + * Gets the size of the deck + * @return int size of the deck + */ @Override public int size() { return cardList.size(); } + /** + * Gets a list of all the cards in the deck + * @return ArrayList of cards from the deck + */ @Override public List getCards() { return new ArrayList<>(cardList); } + /** + * Gets the card from the deck in String format + * @return String the cards from the deck + */ @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -78,11 +110,19 @@ public abstract class Deck implements IDeck { return builder.toString(); } + /** + * Looks at the top card in the deck + * @return ProgrammingCard the first card in the deck + */ @Override public T peekTop() { return cardList.get(0); } + /** + * Looks at the bottom card of the deck + * @return ProgrammingCard the last card in the deck + */ @Override public T peekBottom() { return cardList.get(size()-1); 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"); + + } } } diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index f56c624..24a80ea 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -3,6 +3,7 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.Action; import inf112.fiasko.roborally.element_properties.Position; import inf112.fiasko.roborally.element_properties.RobotID; +import inf112.fiasko.roborally.element_properties.TileType; import inf112.fiasko.roborally.utility.BoardLoaderUtil; import java.io.IOException; @@ -141,14 +142,14 @@ public class RoboRallyGame implements IDrawableGame { sleep(); switch (action) { case MOVE_1: - moveForward(robotID); + gameBoard.moveRobotForward(robotID); break; case MOVE_2: - moveForward(robotID); + gameBoard.moveRobotForward(robotID); moveForward(robotID); break; case MOVE_3: - moveForward(robotID); + gameBoard.moveRobotForward(robotID); moveForward(robotID); moveForward(robotID); break; @@ -182,4 +183,28 @@ public class RoboRallyGame implements IDrawableGame { sleep(); gameBoard.moveRobotForward(robotID); } -} + + /** + * Rotates all robots that are standing on cogWheel tiles on the board. + * @throws InterruptedException If interrupted while sleeping. + */ + private void rotateCogwheels() throws InterruptedException { + List> cogWheelsLeft = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT); + List> cogWheelsRight = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT); + + for (BoardElementContainer cogLeft : cogWheelsLeft) { + if (!gameBoard.hasRobotOnPosition(cogLeft.getPosition())) { + return; + } + sleep(); + makeMove(gameBoard.getRobotOnPosition(cogLeft.getPosition()), Action.ROTATE_LEFT); + } + for (BoardElementContainer cogRight : cogWheelsRight) { + if (!gameBoard.hasRobotOnPosition(cogRight.getPosition())) { + return; + } + sleep(); + makeMove(gameBoard.getRobotOnPosition(cogRight.getPosition()), Action.ROTATE_RIGHT); + } + } +} \ No newline at end of file diff --git a/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java b/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java index 5e4e00b..90e9cce 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java @@ -40,4 +40,70 @@ public class PlayerTest { playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction()); } + @Test + public void addMultipuleCards(){ + playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); + playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2)); + playerTest.setCardInProgram(new ProgrammingCard(23452342,Action.MOVE_3)); + assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction()); + assertEquals(Action.MOVE_2,playerTest.getProgram().get(1).getAction()); + assertEquals(Action.MOVE_3,playerTest.getProgram().get(2).getAction()); + } + @Test(expected = IllegalArgumentException.class) + public void addTooManyCardsGetsAError() { + playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); + playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2)); + playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3)); + playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3)); + playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3)); + playerTest.setCardInProgram(new ProgrammingCard(234523242,Action.MOVE_3)); + } + @Test + public void removeCardsFromPlayerProgram() { + playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); + playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2)); + playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3)); + playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3)); + playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3)); + assertEquals(Action.MOVE_3,playerTest.getProgram().get(4).getAction()); + playerTest.removeProgramCard(4); + assertEquals(null,playerTest.getProgram().get(4)); + } + @Test + public void removeAllCardsFromPlayerProgram() { + playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); + playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2)); + playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3)); + playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3)); + playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3)); + assertEquals(Action.MOVE_3,playerTest.getProgram().get(4).getAction()); + assertEquals(Action.MOVE_3,playerTest.getProgram().get(3).getAction()); + assertEquals(Action.MOVE_3,playerTest.getProgram().get(2).getAction()); + assertEquals(Action.MOVE_2,playerTest.getProgram().get(1).getAction()); + assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction()); + playerTest.removeProgramCard(4); + playerTest.removeProgramCard(3); + playerTest.removeProgramCard(2); + playerTest.removeProgramCard(1); + playerTest.removeProgramCard(0); + assertEquals(null,playerTest.getProgram().get(4)); + assertEquals(null,playerTest.getProgram().get(3)); + assertEquals(null,playerTest.getProgram().get(2)); + assertEquals(null,playerTest.getProgram().get(1)); + assertEquals(null,playerTest.getProgram().get(0)); + } + + @Test(expected = IllegalArgumentException.class) + public void getErrorIfYouRemoveMoreThenIndexFive(){ + playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); + playerTest.removeProgramCard(5); + + } + @Test(expected = IllegalArgumentException.class) + public void getErrorIfYouRemoveANegativIndex(){ + playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1)); + playerTest.removeProgramCard(-1); + + } + }