diff --git a/src/main/java/inf112/fiasko/roborally/objects/AbstractDeck.java b/src/main/java/inf112/fiasko/roborally/objects/AbstractDeck.java new file mode 100644 index 0000000..c0a6b6a --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/objects/AbstractDeck.java @@ -0,0 +1,145 @@ +package inf112.fiasko.roborally.objects; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * This class represents a deck of cards + */ +public abstract class AbstractDeck implements Deck { + private final List cardList; + + public AbstractDeck() { + this.cardList = new ArrayList<>(); + } + + /** + * Initializes the deck with cards + * + * @param cardList list of cards + */ + public AbstractDeck(List cardList) { + this.cardList = new ArrayList<>(cardList); + } + + /** + * Randomises the order of the deck + */ + @Override + public void shuffle() { + Random randomGenerator = new Random(); + int deckSize = cardList.size(); + int halfDeckSize = deckSize / 2; + int timesToShuffle = 30 * deckSize; + for (int i = 0; i < timesToShuffle; i++) { + int oldPosition = randomGenerator.nextInt(halfDeckSize); + int newPosition = randomGenerator.nextInt(deckSize - halfDeckSize) + halfDeckSize; + cardList.add(newPosition, cardList.remove(oldPosition)); + } + } + + /** + * Draws one card from the other deck + * + * @param other The deck to draw the card from + */ + @Override + public void draw(Deck other) { + AbstractDeck otherDeck = (AbstractDeck) 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(Deck other, int n) { + AbstractDeck otherDeck = (AbstractDeck) other; + if (n < 0 || n > otherDeck.size()) { + throw new IllegalArgumentException("n can't be below 0 or over the size of the other card deck"); + } + for (int i = 0; i < n; i++) { + draw(other); + } + } + + /** + * Empty the entire deck into the other deck + * + * @param other The deck to move this deck's cards into + */ + @Override + public void emptyInto(Deck other) { + AbstractDeck otherDeck = (AbstractDeck) 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(); + for (T card : cardList) { + builder.append(card.toString()).append("\n"); + } + 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/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 7dc41b4..cffdddf 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -18,20 +18,21 @@ import java.util.Map; public class Board { private int boardHeight; private int boardWidth; - private IGrid walls; - private IGrid tiles; - private IGrid particles; + private Grid walls; + private Grid tiles; + private Grid particles; private Map robots; private List deadRobots; private List realDeadRobots; /** * Initializes the board - * @param tiles A grid containing all tiles - * @param walls A grid containing all walls + * + * @param tiles A grid containing all tiles + * @param walls A grid containing all walls * @param robots A list of all robots in the game */ - public Board(IGrid tiles, IGrid walls, List robots) { + public Board(Grid tiles, Grid walls, List robots) { if (walls.getWidth() != tiles.getWidth() || walls.getHeight() != tiles.getHeight()) { throw new IllegalArgumentException("The grids in the input don't have the same dimensions."); } @@ -46,19 +47,23 @@ public class Board { this.boardHeight = tiles.getHeight(); this.walls = walls; this.tiles = tiles; - this.particles = new Grid<>(tiles.getWidth(), tiles.getHeight()); + this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight()); this.deadRobots = new ArrayList<>(); this.realDeadRobots = new ArrayList<>(); } /** * All the Real dead player's robots. + * * @return A list of Robots. */ - public List getRealDeadRobots() { return realDeadRobots; } + public List getRealDeadRobots() { + return realDeadRobots; + } /** * Gets the height of the board + * * @return The height of the board */ public int getBoardHeight() { @@ -67,6 +72,7 @@ public class Board { /** * Gets the width of the board + * * @return The width of the board */ public int getBoardWidth() { @@ -75,6 +81,7 @@ public class Board { /** * Gets all alive robots from the board + * * @return A list of alive robots */ public List getAliveRobots() { @@ -85,6 +92,7 @@ public class Board { /** * Gets all the tiles from the board + * * @return A list of all tiles on the board */ public List getTiles() { @@ -93,6 +101,7 @@ public class Board { /** * Gets all the walls from the board + * * @return A list of all the walls on the board */ public List getWalls() { @@ -101,6 +110,7 @@ public class Board { /** * Gets all the particles from the board + * * @return A list of all the particles on the board */ public List getParticles() { @@ -109,6 +119,7 @@ public class Board { /** * Rotates a robot to the right + * * @param robotID The id of the robot to rotate */ public void rotateRobotLeft(RobotID robotID) { @@ -119,6 +130,7 @@ public class Board { /** * Rotates a robot to the left + * * @param robotID The id of the robot to rotate */ public void rotateRobotRight(RobotID robotID) { @@ -129,6 +141,7 @@ public class Board { /** * Moves a robot one unit forward according to the direction it's currently facing + * * @param robotID The robot to move */ public void moveRobotForward(RobotID robotID) { @@ -137,6 +150,7 @@ public class Board { /** * Moves a robot one unit backwards according to the direction it's currently facing + * * @param robotID The robot to move */ public void reverseRobot(RobotID robotID) { @@ -145,7 +159,8 @@ public class Board { /** * Sets the power down status of the robot - * @param robotID The robot id of the robot + * + * @param robotID The robot id of the robot * @param powerdown The status of the powerdown */ public void setPowerDown(RobotID robotID, Boolean powerdown) { @@ -154,6 +169,7 @@ public class Board { /** * Gets the power down status of the robot + * * @param robotID The robot id of the robot */ public boolean getPowerDown(RobotID robotID) { @@ -162,6 +178,7 @@ public class Board { /** * removes one damage for a given robot given that it has taken som damage before + * * @param robotID the ID of the robot */ public void repairRobotOnTile(RobotID robotID) { @@ -183,6 +200,7 @@ public class Board { /** * Get the damage of a specific robot + * * @param robot The RobotID of a robot * @return The amount of damage the robot has currently */ @@ -192,7 +210,8 @@ public class Board { /** * Moves a robot one unit in a specified direction - * @param robotID ID of the robot to move + * + * @param robotID ID of the robot to move * @param direction The direction to move the robot * @return True if the robot moved away from its old position */ @@ -224,6 +243,7 @@ public class Board { /** * Checks whether a given tile is a conveyor belt + * * @param tile The tile to check * @return True if the tile is a conveyor belt */ @@ -253,11 +273,11 @@ public class Board { /** * Teleports a robot to some position without verification * - * Be quite careful about using this method. No validation will me done. The robot will magically disappear from + *

Be quite careful about using this method. No validation will me done. The robot will magically disappear from * one position and appear on another, hence the name. This method should only be used when the new position has - * been confirmed available. + * been confirmed available.

* - * @param robotID The id of the robot to teleport + * @param robotID The id of the robot to teleport * @param newPosition The position the robot should teleport to */ public void teleportRobot(RobotID robotID, Position newPosition) { @@ -266,8 +286,9 @@ public class Board { /** * Checks whether a given conveyor belt is able to move in its direction + * * @param conveyorBelt The conveyor belt to move - * @param iterations The number of recursive calls already executed + * @param iterations The number of recursive calls already executed * @return True if nothing is blocking its movement */ public boolean conveyorBeltCanMove(BoardElementContainer conveyorBelt, int iterations) { @@ -293,7 +314,7 @@ public class Board { //The tile in front of the robot is not a conveyor belt and has something on it stopping the conveyor belt if (!isConveyorBelt(tileInFront) && hasFrontConflict(conveyorBeltPosition, positionInFront, conveyorBeltDirection)) { - return false; + return false; } //There is another robot trying to enter the same crossing if (hasCrossingConflict(positionInFront, conveyorBeltDirection)) { @@ -308,8 +329,9 @@ public class Board { /** * Checks whether a conveyor belt has anything in front of it preventing it from moving forward - * @param conveyorBeltPosition The position of the conveyor belt - * @param positionInFront The position in front of the conveyor belt + * + * @param conveyorBeltPosition The position of the conveyor belt + * @param positionInFront The position in front of the conveyor belt * @param conveyorBeltDirection The direction of the conveyor belt * @return True if the conveyor belt cannot move forward */ @@ -321,7 +343,8 @@ public class Board { /** * Checks whether a conveyor belt has a conflict in a crossing - * @param crossingPosition The position of the crossing + * + * @param crossingPosition The position of the crossing * @param conveyorBeltDirection The direction of the conveyor belt * @return True if there is a conflict. False otherwise */ @@ -356,8 +379,7 @@ public class Board { robot.setFacingDirection(Direction.NORTH); robot.setDamageTaken(2); robots.put(robot.getRobotId(), robot); - } - else { + } else { realDeadRobots.add(robot.getRobotId()); } } @@ -366,6 +388,7 @@ public class Board { /** * Returns a robot id for a robot on a specific position if such a robot exists + * * @param position The position to check * @return The robot id of the robot on the position or null if there is no robot there */ @@ -381,6 +404,7 @@ public class Board { /** * Checks if a specific robot is currently alive on the board + * * @param robot the ID of the robot you want to check * @return True/False based on if the robot was found. */ @@ -390,8 +414,9 @@ public class Board { /** * Updates the flag of the robot if it stands on the correct flag. + * * @param robotID The RobotID of a robot - * @param flagID TileType of the flag we check + * @param flagID TileType of the flag we check */ public void updateFlagOnRobot(RobotID robotID, TileType flagID) { Robot robot = robots.get(robotID); @@ -403,8 +428,9 @@ public class Board { /** * Gets the position 1 unit in a specific direction from another position + * * @param oldPosition The old/current position of the element - * @param direction The direction to move the element + * @param direction The direction to move the element * @return The new position of the element */ public Position getNewPosition(Position oldPosition, Direction direction) { @@ -428,8 +454,8 @@ public class Board { public void fireAllLasers() { List> listOfWallLasers = getPositionsOfWallOnBoard(WallType.WALL_LASER_SINGLE, WallType.WALL_LASER_DOUBLE); - for (Robot robot:robots.values()) { - fireRobotLaser(robot.getPosition(),robot.getFacingDirection()); + for (Robot robot : robots.values()) { + fireRobotLaser(robot.getPosition(), robot.getFacingDirection()); } for (BoardElementContainer laser : listOfWallLasers) { fireWallLaser(laser); @@ -440,12 +466,13 @@ public class Board { * Does necessary cleanup after lasers have been fired */ public void doLaserCleanup() { - this.particles = new Grid<>(tiles.getWidth(), tiles.getHeight()); + this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight()); killAllHeavilyDamagedRobots(); } /** * Gets the tile on a specific position + * * @param position The position to get a tile from * @return The tile on the given position */ @@ -458,10 +485,11 @@ public class Board { /** * Gets a list of BoardElementContainers, containing all tiles and positions of given tile types + * * @param tiles The tiles you want all positions for * @return A list of BoardElementContainers */ - public List> getPositionsOfTileOnBoard(TileType ... tiles) { + public List> getPositionsOfTileOnBoard(TileType... tiles) { List> combinedList = new ArrayList<>(); for (TileType tile : tiles) { combinedList.addAll(makeTileList(tile, this.tiles)); @@ -471,6 +499,7 @@ public class Board { /** * Gets a list of BoardElementContainers, containing all tiles and positions of given wall types + * * @param walls The walls you want all positions for * @return A list of BoardElementContainers */ @@ -484,6 +513,7 @@ public class Board { /** * Checks whether there exists a robot on a specific position + * * @param position The position to check * @return True if there is a robot on the specified position */ @@ -493,18 +523,20 @@ public class Board { /** * Checks if a potential move would be blocked by a wall + * * @param robotPosition The current position of whatever is trying to move - * @param newPosition The position something is trying to move to - * @param direction The direction something is going + * @param newPosition The position something is trying to move to + * @param direction The direction something is going * @return True if a wall would stop its path */ private boolean moveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) { - return hasWallFacing(robotPosition, direction) || (isValidPosition(newPosition) && - hasWallFacing(newPosition, Direction.getReverseDirection(direction))); + return hasWallFacing(robotPosition, direction) || (isValidPosition(newPosition) && + hasWallFacing(newPosition, Direction.getReverseDirection(direction))); } /** * Checks whether a given position is valid + * * @param position The position to test * @return True if the position is valid. False otherwise */ @@ -517,7 +549,8 @@ public class Board { /** * Checks if the robot is about to step outside of the board, and kills it if it does - * @param robot The robot attempting to move + * + * @param robot The robot attempting to move * @param newPosition The position the robot is attempting to move to * @return True if the robot was killed for leaving the board */ @@ -531,7 +564,8 @@ public class Board { /** * Checks the tile the robot is about to step on and kills it if the tile is dangerous - * @param robot The robot attempting to move + * + * @param robot The robot attempting to move * @param newPosition The position the robot is attempting to move to */ private void killRobotIfStepsOnDangerousTile(Robot robot, Position newPosition) { @@ -555,8 +589,8 @@ public class Board { /** * Kills the robot * - * If the robot steps outside of the board, steps on a hole or takes too much damage, this method should be used to - * properly dispose of the robot until the next round. + *

If the robot steps outside of the board, steps on a hole or takes too much damage, this method should be used to + * properly dispose of the robot until the next round.

* * @param robot The robot to kill */ @@ -568,7 +602,8 @@ public class Board { /** * Checks whether a position has a wall facing a specific direction - * @param position The position to check + * + * @param position The position to check * @param direction The direction of the wall to check for * @return True if there is a wall on the position facing the input direction */ @@ -588,11 +623,12 @@ public class Board { /** * Gets all elements on a grid + * * @param grid The grid to get elements from - * @param The type of the elements int the grid + * @param The type of the elements int the grid * @return A list containing all the elements in the grid */ - private List getAllElementsFromGrid(IGrid grid) { + private List getAllElementsFromGrid(Grid grid) { List elements = new ArrayList<>(); for (int y = grid.getHeight() - 1; y >= 0; y--) { for (int x = 0; x < grid.getWidth(); x++) { @@ -604,13 +640,14 @@ public class Board { /** * Finds all tiles/walls with a certain type + * * @param type The type of tile/wall to look for * @param grid The grid to look through - * @param Type of the type to look for - * @param Type of the grid + * @param Type of the type to look for + * @param Type of the grid * @return List of BoardElementContainers */ - private List> makeTileList(K type, IGrid grid) { + private List> makeTileList(K type, Grid grid) { List> objList = new ArrayList<>(); for (int y = grid.getHeight() - 1; y >= 0; y--) { @@ -628,7 +665,7 @@ public class Board { objList.add(new BoardElementContainer<>(gridElement, new Position(x, y))); } } else { - throw new IllegalArgumentException("Grid has unknown type."); + throw new IllegalArgumentException("ListGrid has unknown type."); } } } @@ -640,7 +677,7 @@ public class Board { * Kills all robots that have taken too much damage */ private void killAllHeavilyDamagedRobots() { - for (Robot robot:robots.values()) { + for (Robot robot : robots.values()) { if (robot.getDamageTaken() >= 10) { killRobot(robot); } @@ -649,6 +686,7 @@ public class Board { /** * Fires one wall laser + * * @param wallLaser The wall laser being fired */ private void fireWallLaser(BoardElementContainer wallLaser) { @@ -665,11 +703,12 @@ public class Board { /** * Fires one robot laser - * @param robotPosition The position of the robot firing the laser + * + * @param robotPosition The position of the robot firing the laser * @param robotDirection The direction the robot is facing */ private void fireRobotLaser(Position robotPosition, Direction robotDirection) { - Position positionInFront = getNewPosition(robotPosition,robotDirection); + Position positionInFront = getNewPosition(robotPosition, robotDirection); if (!isValidPosition(positionInFront) || moveIsStoppedByWall(robotPosition, positionInFront, robotDirection)) { return; } @@ -685,8 +724,9 @@ public class Board { /** * Applies the damage form the laser to the robot the laser hit + * * @param laserType The type of laser that hit the robot - * @param robot The robot getting hit by the robot + * @param robot The robot getting hit by the robot */ private void applyLaserDamage(WallType laserType, Robot robot) { robot.setDamageTaken(robot.getDamageTaken() + laserType.getWallTypeID() - 2); @@ -694,9 +734,10 @@ public class Board { /** * Gets all the positions the laser fires at - * @param direction The direction of the laser + * + * @param direction The direction of the laser * @param startPosition The start position of the laser - * @param targets The list to update with target positions + * @param targets The list to update with target positions */ private void getLaserTarget(Direction direction, Position startPosition, List targets) { Position newPosition = getNewPosition(startPosition, direction); @@ -714,9 +755,10 @@ public class Board { /** * Adds any lasers in the targets list to the grid displaying lasers - * @param laserTargets The tiles the laser will hit + * + * @param laserTargets The tiles the laser will hit * @param laserDirection The direction of the laser - * @param laserType The type of the laser + * @param laserType The type of the laser */ private void updateLaserDisplay(List laserTargets, Direction laserDirection, WallType laserType) { for (Position laserTarget : laserTargets) { @@ -726,9 +768,10 @@ public class Board { /** * Updates a laser beam on the particle grid - * @param addPosition The position of the beam + * + * @param addPosition The position of the beam * @param laserDirection The direction of the beam - * @param laserType The type of the laser shooting + * @param laserType The type of the laser shooting */ private void updateLaserBeamOnParticleGrid(Position addPosition, Direction laserDirection, WallType laserType) { int positionX = addPosition.getXCoordinate(); @@ -758,6 +801,7 @@ public class Board { /** * Gets the int corresponding to the flag a robot has last visited + * * @param robotID The robot to be checked * @return The flag last visited in a number */ @@ -767,7 +811,8 @@ public class Board { /** * Sets a boolean for if the robot has touched a flag this turn - * @param robotID The robot to be checked + * + * @param robotID The robot to be checked * @param hasTouched If the robot has touched a flag this turn */ public void setHasTouchedFlagThisTurnFromRobotID(RobotID robotID, boolean hasTouched) { @@ -776,6 +821,7 @@ public class Board { /** * Checks a boolean for if the robot has touched a flag this turn + * * @param robotID The robot to be checked * @return If the robot has touched a flag this turn */ diff --git a/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java b/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java index 11ab2af..f84a75d 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java +++ b/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java @@ -4,15 +4,17 @@ import inf112.fiasko.roborally.elementproperties.Position; /** * This class represents a board element and its position + * * @param The type of element */ -public class BoardElementContainer { +public class BoardElementContainer { private final K element; private final Position position; /** * Initializes the BoardElementContainer - * @param element The element + * + * @param element The element * @param position The position */ BoardElementContainer(K element, Position position) { @@ -22,6 +24,7 @@ public class BoardElementContainer { /** * Gets the element + * * @return The element */ public K getElement() { @@ -30,6 +33,7 @@ public class BoardElementContainer { /** * Gets the position + * * @return The position */ public Position getPosition() { diff --git a/src/main/java/inf112/fiasko/roborally/objects/Deck.java b/src/main/java/inf112/fiasko/roborally/objects/Deck.java index 78d5139..53096db 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Deck.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Deck.java @@ -1,134 +1,76 @@ package inf112.fiasko.roborally.objects; -import java.util.ArrayList; import java.util.List; -import java.util.Random; /** - * This class represents a deck of cards + * Describes a deck + * + *

Any card stored in the deck is assumed to be immutable. If it's not, the integrity of the deck cannot be + * guaranteed.

*/ -public abstract class Deck implements IDeck { - private final List cardList; +public interface Deck { - public Deck (){ - this.cardList=new ArrayList<>(); - } /** - * Initializes the deck with cards - * @param cardList list of cards + * Shuffles the order of the cards in the deck */ - public Deck (List cardList) { - this.cardList = new ArrayList<>(cardList); - } + void shuffle(); /** - * Randomises the order of the deck - */ - @Override - public void shuffle() { - Random randomGenerator = new Random(); - int deckSize = cardList.size(); - int halfDeckSize = deckSize / 2; - int timesToShuffle = 30 * deckSize; - for (int i = 0; i < timesToShuffle; i++) { - int oldPosition = randomGenerator.nextInt(halfDeckSize); - int newPosition = randomGenerator.nextInt(deckSize - halfDeckSize) + halfDeckSize; - cardList.add(newPosition, cardList.remove(oldPosition)); - } - } - - /** - * Draws one card from the other deck + * Draws one card from the top of another 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)); - } + void draw(Deck other); /** - * Draws multiple cards from the other deck + * Draws n cards from the top of another deck + * * @param other The other deck to draw from - * @param n The number of cards to draw + * @param n The number of cards to draw */ - @Override - public void draw(IDeck other, int n) { - Deck otherDeck = (Deck) other; - if (n < 0 || n > otherDeck.size()) { - throw new IllegalArgumentException("n can't be below 0 or over the size of the other card deck"); - } - for (int i = 0; i < n; i++) { - draw(other); - } - } + void draw(Deck other, int n); /** - * Empty the entire deck into the other deck + * Moves all cards in this deck into another 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()); - } + void emptyInto(Deck other); /** - * Checks if the deck is empty - * @return Boolean for if the deck is empty + * Whether this deck is empty + * + * @return True if this deck is currently empty */ - @Override - public boolean isEmpty() { - return cardList.isEmpty(); - } + boolean isEmpty(); /** - * Gets the size of the deck - * @return int size of the deck + * Gets the number of cards currently in this deck + * + * @return The number of cards in this deck */ - @Override - public int size() { - return cardList.size(); - } + int size(); /** - * Gets a list of all the cards in the deck - * @return ArrayList of cards from the deck + * Takes a peek at the card currently at the top of the deck + * + * @return The card at the top of the deck */ - @Override - public List getCards() { - return new ArrayList<>(cardList); - } + T peekTop(); /** - * Gets the card from the deck in String format - * @return String the cards from the deck + * Takes a peek at the card currently at the bottom of the deck + * + * @return The card at the bottom of the deck */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - for (T card : cardList) { - builder.append(card.toString()).append("\n"); - } - return builder.toString(); - } + T peekBottom(); /** - * Looks at the top card in the deck - * @return ProgrammingCard the first card in the deck + * Gets a list of all cards in this deck + * + *

The list should have the correct order according to the actual order within the deck.

+ * + * @return A list of all cards in this 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); - } + List getCards(); } - diff --git a/src/main/java/inf112/fiasko/roborally/objects/IDrawableGame.java b/src/main/java/inf112/fiasko/roborally/objects/DrawableGame.java similarity index 65% rename from src/main/java/inf112/fiasko/roborally/objects/IDrawableGame.java rename to src/main/java/inf112/fiasko/roborally/objects/DrawableGame.java index bede67e..b506062 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/IDrawableGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/DrawableGame.java @@ -5,16 +5,18 @@ import java.util.List; /** * This interface describes a game drawable using libgdx */ -public interface IDrawableGame { +public interface DrawableGame { /** * Gets the number of tiles in the x direction + * * @return A positive integer */ int getWidth(); /** * Gets the number of tiles in the y direction + * * @return A positive integer */ int getHeight(); @@ -22,8 +24,8 @@ public interface IDrawableGame { /** * Gets a list of all the tiles to be drawn * - * Should return a list readable from top-left to top-right and so on. In other words, the first getWidth() tiles - * should be drawn on the top row from left to right. + *

Should return a list readable from top-left to top-right and so on. In other words, the first getWidth() tiles + * should be drawn on the top row from left to right.

* * @return A list of tiles */ @@ -32,8 +34,8 @@ public interface IDrawableGame { /** * Gets a list of all the walls to be drawn * - * Should return a list readable from top-left to top-right and so on. In other words, the first getWidth() walls - * should be drawn on the top row from left to right. + *

Should return a list readable from top-left to top-right and so on. In other words, the first getWidth() walls + * should be drawn on the top row from left to right.

* * @return A list of walls */ @@ -42,8 +44,8 @@ public interface IDrawableGame { /** * Gets a list of all the particles to be drawn * - * Should return a list readable from top-left to top-right and so on. In other words, the first getWidth() - * particles should be drawn on the top row from left to right. + *

Should return a list readable from top-left to top-right and so on. In other words, the first getWidth() + * particles should be drawn on the top row from left to right.

* * @return A list of particles */ @@ -51,6 +53,7 @@ public interface IDrawableGame { /** * Gets a list of all robots to draw + * * @return A list of all robots to draw */ List getRobotsToDraw(); diff --git a/src/main/java/inf112/fiasko/roborally/objects/DrawableObject.java b/src/main/java/inf112/fiasko/roborally/objects/DrawableObject.java index c5fb69a..050a064 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/DrawableObject.java +++ b/src/main/java/inf112/fiasko/roborally/objects/DrawableObject.java @@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; /** * This class represents an object that can be drawn using libgdx */ -public class DrawableObject implements IDrawableObject { +public class DrawableObject { private final TextureRegion texture; private final int xPos; private final int yPos; @@ -17,14 +17,15 @@ public class DrawableObject implements IDrawableObject { /** * Initializes a drawable object - * @param texture The texture to use for drawing the element - * @param xPos The pixel to start drawing on for the x axis - * @param yPos The pixel to start drawing on for the y axis - * @param width The width of the element - * @param height The height of the element + * + * @param texture The texture to use for drawing the element + * @param xPos The pixel to start drawing on for the x axis + * @param yPos The pixel to start drawing on for the y axis + * @param width The width of the element + * @param height The height of the element * @param rotation The amount of degrees to rotate the element counterclockwise - * @param flipX Whether to flip/mirror the element over the x axis - * @param flipY Whether to flip/mirror the element over the y axis + * @param flipX Whether to flip/mirror the element over the x axis + * @param flipY Whether to flip/mirror the element over the y axis */ public DrawableObject(TextureRegion texture, int xPos, int yPos, int width, int height, int rotation, boolean flipX, boolean flipY) { @@ -40,11 +41,12 @@ public class DrawableObject implements IDrawableObject { /** * Initializes a drawable object - * @param texture The texture to use for drawing the element - * @param xPos The pixel to start drawing on for the x axis - * @param yPos The pixel to start drawing on for the y axis - * @param width The width of the element - * @param height The height of the element + * + * @param texture The texture to use for drawing the element + * @param xPos The pixel to start drawing on for the x axis + * @param yPos The pixel to start drawing on for the y axis + * @param width The width of the element + * @param height The height of the element * @param rotation The amount of degrees to rotate the element counterclockwise */ public DrawableObject(TextureRegion texture, int xPos, int yPos, int width, int height, int rotation) { @@ -58,9 +60,10 @@ public class DrawableObject implements IDrawableObject { /** * Initializes a new drawable object + * * @param texture The texture to use for drawing the element - * @param xPos The pixel to start drawing on for the x axis - * @param yPos The pixel to start drawing on for the y axis + * @param xPos The pixel to start drawing on for the x axis + * @param yPos The pixel to start drawing on for the y axis */ public DrawableObject(TextureRegion texture, int xPos, int yPos) { this.xPos = xPos; @@ -68,42 +71,80 @@ public class DrawableObject implements IDrawableObject { this.texture = texture; } - @Override + /** + * Gets the texture to use for drawing the object + * + * @return The texture of the object + */ public TextureRegion getTexture() { return texture; } - @Override + /** + * Gets the x position the object should be drawn on + * + *

The x position should be in terms of the actual pixel position on the rendered game, not the position according + * to the game tile. E.g. (128,64) not (2,1).

+ * + * @return An x position libgdx + */ public int getXPosition() { return xPos; } - @Override + /** + * Gets the y position the object should be drawn on + * + *

The y position should be in terms of the actual pixel position on the rendered game, not the position according + * to the game tile. E.g. (128,64) not (2,1).

+ * + * @return An x position libgdx + */ public int getYPosition() { return yPos; } - @Override + /** + * Gets the width of the object + * + * @return A positive integer + */ public int getWidth() { return width; } - @Override + /** + * Gets the height of the object + * + * @return A positive integer + */ public int getHeight() { return height; } - @Override + /** + * Gets the number of degrees to rotate the texture counterclockwise when rendering + * + * @return An integer + */ public int getRotation() { return rotation; } - @Override + /** + * Whether to flip the texture on the x-axis when rendering + * + * @return True if the texture is to be flipped. False otherwise + */ public boolean flipX() { return flipX; } - @Override + /** + * Whether to flip the texture on the y-axis when rendering + * + * @return True if the texture is to be flipped. False otherwise + */ public boolean flipY() { return flipY; } diff --git a/src/main/java/inf112/fiasko/roborally/objects/Grid.java b/src/main/java/inf112/fiasko/roborally/objects/Grid.java index fda120c..d70a220 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Grid.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Grid.java @@ -1,83 +1,42 @@ package inf112.fiasko.roborally.objects; -import java.util.ArrayList; -import java.util.List; - /** - * This class represents a grid which can store anything - * @param The type of element the grid should store + * This Interface describes a grid + * + * @param The type of element the grid is to store */ -public class Grid implements IGrid { - - private final int height; - private final int width; - private final List> grid = new ArrayList<>(); +public interface Grid { /** - * Initializes an empty grid - * @param width The width of the grid - * @param height The height of the grid + * Gets the width of the grid + * + * @return The width of the grid */ - public Grid(int width, int height) { - this.width = width; - this.height = height; - for (int y = 0; y < height; y++) { - ArrayList row = new ArrayList<>(); - for(int x = 0; x < width; x++) { - row.add(null); - } - this.grid.add(row); - } - } + int getWidth(); /** - * Initializes a grid filled with standard tiles. - * @param height sets the height of the grid - * @param width sets the width of the grid - * @param tile gives the TileType the grid is to be filled with + * Gets height of the grid + * + * @return The height of the grid */ - public Grid(int width, int height, K tile) { - this.width = width; - this.height = height; - for (int y = 0; y < height; y++) { - ArrayList row = new ArrayList<>(); - for(int x = 0; x < width; x++) { - row.add(tile); - } - this.grid.add(row); - } - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public K getElement(int x, int y) throws IllegalArgumentException { - makeSureCoordinatesAreWithinBounds(x, y); - return grid.get(y).get(x); - } - - @Override - public void setElement(int x, int y, K element) throws IllegalArgumentException { - makeSureCoordinatesAreWithinBounds(x, y); - grid.get(y).set(x, element); - } + int getHeight(); /** - * Throws an exception if input coordinates are out of bounds - * @param x The x coordinate to check - * @param y The y coordinate to check + * Gets the element in a given x and y coordinate + * + * @param x Coordinate in the grid + * @param y Coordinate in the grid + * @return Element in the x and y coordinate + * @throws IllegalArgumentException Throws an exception if the coordinates are outside of the grid */ - private void makeSureCoordinatesAreWithinBounds(int x, int y) { - if (x < 0 || x >= width || y < 0 || y >= height) { - throw new IllegalArgumentException("Coordinates are outside the bounds of the board."); - } - } + K getElement(int x, int y) throws IllegalArgumentException; + + /** + * Places the element on the given x and y coordinate + * + * @param x Coordinate in the grid + * @param y Coordinate in the grid + * @param element The element to place in the grid + */ + void setElement(int x, int y, K element) throws IllegalArgumentException; } diff --git a/src/main/java/inf112/fiasko/roborally/objects/IDeck.java b/src/main/java/inf112/fiasko/roborally/objects/IDeck.java deleted file mode 100644 index 8e65b34..0000000 --- a/src/main/java/inf112/fiasko/roborally/objects/IDeck.java +++ /dev/null @@ -1,69 +0,0 @@ -package inf112.fiasko.roborally.objects; - -import java.util.List; - -/** - * Describes a deck - * - * Any card stored in the deck is assumed to be immutable. If it's not, the integrity of the deck cannot be - * guaranteed. - */ -public interface IDeck { - - /** - * Shuffles the order of the cards in the deck - */ - void shuffle(); - - /** - * Draws one card from the top of another deck - * @param other The deck to draw the card from - */ - void draw(IDeck other); - - /** - * Draws n cards from the top of another deck - * @param other The other deck to draw from - * @param n The number of cards to draw - */ - void draw(IDeck other, int n); - - /** - * Moves all cards in this deck into another deck - * @param other The deck to move this deck's cards into - */ - void emptyInto(IDeck other); - - /** - * Whether this deck is empty - * @return True if this deck is currently empty - */ - boolean isEmpty(); - - /** - * Gets the number of cards currently in this deck - * @return The number of cards in this deck - */ - int size(); - - /** - * Takes a peek at the card currently at the top of the deck - * @return The card at the top of the deck - */ - T peekTop(); - - /** - * Takes a peek at the card currently at the bottom of the deck - * @return The card at the bottom of the deck - */ - T peekBottom(); - - /** - * Gets a list of all cards in this deck - * - * The list should have the correct order according to the actual order within the deck. - * - * @return A list of all cards in this deck - */ - List getCards(); -} diff --git a/src/main/java/inf112/fiasko/roborally/objects/IDrawableObject.java b/src/main/java/inf112/fiasko/roborally/objects/IDrawableObject.java deleted file mode 100644 index 4e5c982..0000000 --- a/src/main/java/inf112/fiasko/roborally/objects/IDrawableObject.java +++ /dev/null @@ -1,66 +0,0 @@ -package inf112.fiasko.roborally.objects; - -import com.badlogic.gdx.graphics.g2d.TextureRegion; - -/** - * This interface describes an object drawable using libgdx - */ -public interface IDrawableObject { - - /** - * Gets the texture to use for drawing the object - * @return The texture of the object - */ - TextureRegion getTexture(); - - /** - * Gets the x position the object should be drawn on - * - * The x position should be in terms of the actual pixel position on the rendered game, not the position according - * to the game tile. E.g. (128,64) not (2,1). - * - * @return An x position libgdx - */ - int getXPosition(); - - /** - * Gets the y position the object should be drawn on - * - * The y position should be in terms of the actual pixel position on the rendered game, not the position according - * to the game tile. E.g. (128,64) not (2,1). - * - * @return An x position libgdx - */ - int getYPosition(); - - /** - * Gets the width of the object - * @return A positive integer - */ - int getWidth(); - - /** - * Gets the height of the object - * @return A positive integer - */ - int getHeight(); - - /** - * Gets the number of degrees to rotate the texture counterclockwise when rendering - * @return An integer - */ - int getRotation(); - - /** - * Whether to flip the texture on the x-axis when rendering - * @return True if the texture is to be flipped. False otherwise - */ - boolean flipX(); - - /** - * Whether to flip the texture on the y-axis when rendering - * @return True if the texture is to be flipped. False otherwise - */ - boolean flipY(); - -} diff --git a/src/main/java/inf112/fiasko/roborally/objects/IGrid.java b/src/main/java/inf112/fiasko/roborally/objects/IGrid.java deleted file mode 100644 index e8c4fd8..0000000 --- a/src/main/java/inf112/fiasko/roborally/objects/IGrid.java +++ /dev/null @@ -1,37 +0,0 @@ -package inf112.fiasko.roborally.objects; - -/** - * This Interface describes a grid - * @param The type of element the grid is to store - */ -public interface IGrid { - - /** - * Gets the width of the grid - * @return The width of the grid - */ - int getWidth(); - - /** - * Gets height of the grid - * @return The height of the grid - */ - int getHeight(); - - /** - * Gets the element in a given x and y coordinate - * @param x Coordinate in the grid - * @param y Coordinate in the grid - * @return Element in the x and y coordinate - * @throws IllegalArgumentException Throws an exception if the coordinates are outside of the grid - */ - K getElement(int x,int y) throws IllegalArgumentException; - - /** - * Places the element on the given x and y coordinate - * @param x Coordinate in the grid - * @param y Coordinate in the grid - * @param element The element to place in the grid - */ - void setElement(int x, int y, K element) throws IllegalArgumentException; -} diff --git a/src/main/java/inf112/fiasko/roborally/objects/IRoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/IRoboRallyGame.java deleted file mode 100644 index 06c334f..0000000 --- a/src/main/java/inf112/fiasko/roborally/objects/IRoboRallyGame.java +++ /dev/null @@ -1,3 +0,0 @@ -package inf112.fiasko.roborally.objects; - -public interface IRoboRallyGame extends IDrawableGame, IInteractableGame {} diff --git a/src/main/java/inf112/fiasko/roborally/objects/IInteractableGame.java b/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java similarity index 89% rename from src/main/java/inf112/fiasko/roborally/objects/IInteractableGame.java rename to src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java index 5f873b0..9268cb8 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/IInteractableGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java @@ -1,7 +1,7 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.elementproperties.GameState; -import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.PowerDownContainer; import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import java.util.List; @@ -9,27 +9,31 @@ import java.util.List; /** * This interface describes */ -public interface IInteractableGame { +public interface InteractableGame { /** * Gets the current state og the game + * * @return The state the game is currently in */ GameState getGameState(); /** * Sets the state of the game + * * @param gameState The new state of the game */ void setGameState(GameState gameState); /** * Gets the name of the player who won + * * @return A string of the player name */ String getWinningPlayerName(); /** * Continues turn when programs for all players are received from the server + * * @param programs The programs container received from the server * @throws InterruptedException If interrupted during sleep */ @@ -37,36 +41,42 @@ public interface IInteractableGame { /** * Continues turn when stay in power down is received from all players + * * @param powerDowns The power down container received from the server */ - void receiveStayInPowerDown(PowerdownContainer powerDowns); + void receiveStayInPowerDown(PowerDownContainer powerDowns); /** * Gets the hand of this player + * * @return The hand of this player */ ProgrammingCardDeck getPlayerHand(); /** * Sets the hand of this player + * * @param playerHand The new hand of this player */ void setPlayerHand(ProgrammingCardDeck playerHand); /** * Gets the amount of cards the player can choose for their program + * * @return The size of the player's next program */ int getProgramSize(); /** * Gets the program of this player + * * @return The program of this player */ List getProgram(); /** * Sets the program of this player + * * @param program The program of this player */ void setProgram(List program); diff --git a/src/main/java/inf112/fiasko/roborally/objects/ListGrid.java b/src/main/java/inf112/fiasko/roborally/objects/ListGrid.java new file mode 100644 index 0000000..dac3a55 --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/objects/ListGrid.java @@ -0,0 +1,87 @@ +package inf112.fiasko.roborally.objects; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class represents a grid which can store anything + * + * @param The type of element the grid should store + */ +public class ListGrid implements Grid { + + private final int height; + private final int width; + private final List> grid = new ArrayList<>(); + + /** + * Initializes an empty grid + * + * @param width The width of the grid + * @param height The height of the grid + */ + public ListGrid(int width, int height) { + this.width = width; + this.height = height; + for (int y = 0; y < height; y++) { + ArrayList row = new ArrayList<>(); + for (int x = 0; x < width; x++) { + row.add(null); + } + this.grid.add(row); + } + } + + /** + * Initializes a grid filled with standard tiles. + * + * @param height sets the height of the grid + * @param width sets the width of the grid + * @param tile gives the TileType the grid is to be filled with + */ + public ListGrid(int width, int height, K tile) { + this.width = width; + this.height = height; + for (int y = 0; y < height; y++) { + ArrayList row = new ArrayList<>(); + for (int x = 0; x < width; x++) { + row.add(tile); + } + this.grid.add(row); + } + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public K getElement(int x, int y) throws IllegalArgumentException { + makeSureCoordinatesAreWithinBounds(x, y); + return grid.get(y).get(x); + } + + @Override + public void setElement(int x, int y, K element) throws IllegalArgumentException { + makeSureCoordinatesAreWithinBounds(x, y); + grid.get(y).set(x, element); + } + + /** + * Throws an exception if input coordinates are out of bounds + * + * @param x The x coordinate to check + * @param y The y coordinate to check + */ + private void makeSureCoordinatesAreWithinBounds(int x, int y) { + if (x < 0 || x >= width || y < 0 || y >= height) { + throw new IllegalArgumentException("Coordinates are outside the bounds of the board."); + } + } +} diff --git a/src/main/java/inf112/fiasko/roborally/objects/Particle.java b/src/main/java/inf112/fiasko/roborally/objects/Particle.java index 419e628..a34737a 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Particle.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Particle.java @@ -13,8 +13,9 @@ public class Particle { /** * Instantiates a new particle + * * @param particleType The type of the particle - * @param direction The direction of the particle + * @param direction The direction of the particle */ public Particle(ParticleType particleType, Direction direction) { if (direction.getDirectionID() % 2 == 0) { @@ -26,6 +27,7 @@ public class Particle { /** * Gets the particle type of the particle + * * @return The particle's particle type */ public ParticleType getParticleType() { @@ -34,6 +36,7 @@ public class Particle { /** * Gets the direction of the particle + * * @return The particle's direction */ public Direction getDirection() { diff --git a/src/main/java/inf112/fiasko/roborally/objects/Phase.java b/src/main/java/inf112/fiasko/roborally/objects/Phase.java index 648b9ff..eba0ddd 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Phase.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Phase.java @@ -1,8 +1,17 @@ package inf112.fiasko.roborally.objects; -import inf112.fiasko.roborally.elementproperties.*; +import inf112.fiasko.roborally.elementproperties.Action; +import inf112.fiasko.roborally.elementproperties.Direction; +import inf112.fiasko.roborally.elementproperties.GameState; +import inf112.fiasko.roborally.elementproperties.Position; +import inf112.fiasko.roborally.elementproperties.RobotID; +import inf112.fiasko.roborally.elementproperties.TileType; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; /** @@ -20,10 +29,11 @@ public class Phase { /** * Instantiates a new phase - * @param gameBoard The board to act on + * + * @param gameBoard The board to act on * @param playerList A list of players participating in the game * @param cycleDelay The amount of milliseconds to wait between moves - * @param game The game which uses this object + * @param game The game which uses this object */ public Phase(Board gameBoard, List playerList, int cycleDelay, RoboRallyGame game) { this.gameBoard = gameBoard; @@ -35,6 +45,7 @@ public class Phase { /** * Runs one phase as defined in the Robo Rally rulebook + * * @param phaseNumber The number of the phase to run * @throws InterruptedException If interrupted wile trying to sleep */ @@ -62,7 +73,7 @@ public class Phase { continue; } gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType()); - gameBoard.setHasTouchedFlagThisTurnFromRobotID(robotID,true); + gameBoard.setHasTouchedFlagThisTurnFromRobotID(robotID, true); checkIfPlayerWon(robotID, flags.size()); } } @@ -78,6 +89,7 @@ public class Phase { /** * Runs all programming cards for a phase + * * @param phase The number of the phase to run cards for * @throws InterruptedException If it gets interrupted while trying to sleep */ @@ -104,6 +116,7 @@ public class Phase { /** * Rotates all robots that are standing on cogWheel tiles on the board. + * * @throws InterruptedException If interrupted while sleeping. */ public void rotateCogwheels() throws InterruptedException { @@ -123,7 +136,7 @@ public class Phase { /** * Moves robots standing on conveyor belts in the direction of the conveyor belt * - * In addition, the function rotates appropriately when arriving at any non-straight conveyor belt + *

In addition, the function rotates appropriately when arriving at any non-straight conveyor belt.

* * @throws InterruptedException If disturbed during sleep */ @@ -136,8 +149,9 @@ public class Phase { /** * Makes the given robot move according to to the action input. + * * @param robotID The ID of the robot to move. - * @param action The specific movement the robot is to take. + * @param action The specific movement the robot is to take. * @throws InterruptedException If interrupted wile trying to sleep. */ public void makeMove(RobotID robotID, Action action) throws InterruptedException { @@ -178,7 +192,8 @@ public class Phase { /** * Checks if the player won, and shows the victory screen - * @param robotID The robot to be checked + * + * @param robotID The robot to be checked * @param numberOfFlags The number of flags on the map */ private void checkIfPlayerWon(RobotID robotID, int numberOfFlags) { @@ -197,8 +212,9 @@ public class Phase { /** * Checks whether a player has won + * * @param lastFlagVisited The last flag the player visited - * @param lastFlag The last flag of the board + * @param lastFlag The last flag of the board * @return True if the player has visited the last flag */ private boolean victoryCheck(int lastFlagVisited, int lastFlag) { @@ -207,6 +223,7 @@ public class Phase { /** * Moves a list of conveyor belts + * * @param conveyorBelts A list of board element containers containing conveyor belts */ private void moveConveyorBelts(List> conveyorBelts) { @@ -239,10 +256,11 @@ public class Phase { /** * Updates maps containing information about what a robot on a conveyor belt should do - * @param conveyorBeltPosition The position of the conveyor belt the robot stands on + * + * @param conveyorBeltPosition The position of the conveyor belt the robot stands on * @param conveyorBeltDirection The direction of the conveyor belt the robot stands on - * @param newPositions The map containing new positions for robots - * @param moveNormally The map containing whether a robot should move normally following normal rules + * @param newPositions The map containing new positions for robots + * @param moveNormally The map containing whether a robot should move normally following normal rules */ private void updateConveyorBeltMaps(Position conveyorBeltPosition, Direction conveyorBeltDirection, Map newPositions, Map moveNormally) { @@ -265,6 +283,7 @@ public class Phase { /** * Helper method for makeMove. Takes care of movement forward of given robot. + * * @param robotID ID of the given robot. * @throws InterruptedException If interrupted wile sleeping. */ @@ -278,6 +297,7 @@ public class Phase { /** * Makes the game thread wait a given time amount before continuing. + * * @throws InterruptedException If interrupted while trying to sleep. */ private void sleep() throws InterruptedException { diff --git a/src/main/java/inf112/fiasko/roborally/objects/Player.java b/src/main/java/inf112/fiasko/roborally/objects/Player.java index 42bd8d5..9d8adea 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Player.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Player.java @@ -14,12 +14,13 @@ public class Player { private boolean powerDownNextRound = false; private ProgrammingCardDeck playerDeck; private ProgrammingCardDeck lockedPlayerDeck; - private List program; + private List program; /** * Instantiates a new player + * * @param robotID the global identifier of the robot - * @param name the unique name of the player + * @param name the unique name of the player */ public Player(RobotID robotID, String name) { this.playerDeck = new ProgrammingCardDeck(new ArrayList<>()); @@ -31,26 +32,12 @@ public class Player { /** * Empty constructor required by kryo */ - public Player(){} - - /** - * Sets the robot id of the robot - * @param robotID The new id of the robot - */ - public void setRobotID(RobotID robotID) { - this.robotID = robotID; - } - - /** - * Sets the name of the robot - * @param name The new name of the robot - */ - public void setName(String name) { - this.name = name; + public Player() { } /** * Gives you the RobotID of a player + * * @return A RobotID */ public RobotID getRobotID() { @@ -58,23 +45,35 @@ public class Player { } /** - * Set the players deck to the given deck - * @param playerDeck A deck of cards given to the player + * Sets the robot id of the robot + * + * @param robotID The new id of the robot */ - public void setPlayerDeck(ProgrammingCardDeck playerDeck) { - this.playerDeck = playerDeck; + public void setRobotID(RobotID robotID) { + this.robotID = robotID; } /** * Gives you the Name of the player + * * @return A player Name */ public String getName() { return name; } + /** + * Sets the name of the robot + * + * @param name The new name of the robot + */ + public void setName(String name) { + this.name = name; + } + /** * Gives you the players program + * * @return A list of programming cards */ public List getProgram() { @@ -83,14 +82,25 @@ public class Player { /** * Gives you the player hand/deck + * * @return a deck */ public ProgrammingCardDeck getPlayerDeck() { return playerDeck; } + /** + * Set the players deck to the given deck + * + * @param playerDeck A deck of cards given to the player + */ + public void setPlayerDeck(ProgrammingCardDeck playerDeck) { + this.playerDeck = playerDeck; + } + /** * Gives you the player deck with locked cards + * * @return a deck with locked cards */ public ProgrammingCardDeck getLockedPlayerDeck() { @@ -99,6 +109,7 @@ public class Player { /** * Set the players locked deck to the given deck + * * @param lockedPlayerDeck A deck of locked cards kept by the player */ public void setLockedPlayerDeck(ProgrammingCardDeck lockedPlayerDeck) { @@ -107,6 +118,7 @@ public class Player { /** * Gives you the players power down status + * * @return Whether the player is to power down */ public boolean getPowerDownNextRound() { @@ -115,6 +127,7 @@ public class Player { /** * Sets the power down status + * * @param powerDownStatus Whether the player is to take power down next round */ public void setPowerDownNextRound(boolean powerDownStatus) { @@ -123,9 +136,10 @@ public class Player { /** * Sets the Players program to the given list of programing cards + * * @param cardList list the size of 5 with programing cards */ - public void setInProgram(List cardList) { + public void setInProgram(List cardList) { if (cardList.size() != 5) { throw new IllegalArgumentException("list must contain 5 programing cards"); } else { diff --git a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java index 38acd24..31e8f64 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java +++ b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java @@ -12,20 +12,22 @@ public class ProgrammingCard implements Comparable { /** * Initializes the priority and the action of the card + * * @param cardPriority the priority of the card - * @param cardAction the action of the card + * @param cardAction the action of the card */ public ProgrammingCard(int cardPriority, Action cardAction) { this.cardPriority = cardPriority; this.cardAction = cardAction; } - public ProgrammingCard(){ + public ProgrammingCard() { } /** * Gets the priority of the programming card + * * @return The programming card priority */ public int getPriority() { @@ -34,6 +36,7 @@ public class ProgrammingCard implements Comparable { /** * Gets the action of the programming card + * * @return The programming card action */ public Action getAction() { diff --git a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java index 5b61039..9a59be2 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java +++ b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java @@ -5,14 +5,17 @@ import java.util.List; /** * This class represents a deck containing programming cards */ -public class ProgrammingCardDeck extends Deck { +public class ProgrammingCardDeck extends AbstractDeck { /** * Initializes the PlayerDeck with a list of cards + * * @param cardList list of programing cards */ public ProgrammingCardDeck(List cardList) { super(cardList); } - public ProgrammingCardDeck(){} + + public ProgrammingCardDeck() { + } } diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index baafe7f..04fbf4c 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -7,7 +7,7 @@ import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.elementproperties.TileType; import inf112.fiasko.roborally.networking.RoboRallyClient; import inf112.fiasko.roborally.networking.RoboRallyServer; -import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.PowerDownContainer; import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import inf112.fiasko.roborally.utility.BoardLoaderUtil; import inf112.fiasko.roborally.utility.DeckLoaderUtil; @@ -20,16 +20,15 @@ import java.util.Map; /** * This class represent a game which is drawable using libgdx */ -public class RoboRallyGame implements IRoboRallyGame { - private Board gameBoard; - private List> repairTiles; +public class RoboRallyGame implements DrawableGame, InteractableGame { private final List playerList; private final boolean host; + private final String playerName; + private final RoboRallyServer server; + private Board gameBoard; + private List> repairTiles; private Deck mainDeck; private GameState gameState = GameState.BEGINNING_OF_GAME; - private final String playerName; - private final RoboRallyClient client; - private final RoboRallyServer server; private String winningPlayerName; private List program; private ProgrammingCardDeck playerHand; @@ -37,20 +36,19 @@ public class RoboRallyGame implements IRoboRallyGame { /** * Instantiates a new Robo Rally game + * * @param playerList A list of all the players participating in the game - * @param boardName The playerName of the board to use - * @param host Whether this player is the host + * @param boardName The playerName of the board to use + * @param host Whether this player is the host * @param playerName The name of the player of this instance of the game - * @param client The client used to send data to the server - * @param server The server if this player is host. Should be null otherwise - * @param debug Whether this game is to use the debugging board + * @param server The server if this player is host. Should be null otherwise + * @param debug Whether this game is to use the debugging board */ public RoboRallyGame(List playerList, String boardName, boolean host, String playerName, - RoboRallyClient client, RoboRallyServer server, boolean debug) { + RoboRallyServer server, boolean debug) { this.playerName = playerName; this.host = host; this.playerList = playerList; - this.client = client; this.server = server; if (debug) { initializeDebugMode(); @@ -62,19 +60,18 @@ public class RoboRallyGame implements IRoboRallyGame { /** * Instantiates a new Robo Rally game + * * @param playerList A list of all the players participating in the game - * @param boardName The playerName of the board to use - * @param host Whether this player is the host + * @param boardName The playerName of the board to use + * @param host Whether this player is the host * @param playerName The name of the player of this instance of the game - * @param client The client used to send data to the server - * @param server The server if this player is host. Should be null otherwise + * @param server The server if this player is host. Should be null otherwise */ public RoboRallyGame(List playerList, String boardName, boolean host, String playerName, - RoboRallyClient client, RoboRallyServer server) { + RoboRallyServer server) { this.playerName = playerName; this.host = host; this.playerList = playerList; - this.client = client; this.server = server; initializeGame(boardName); this.phase = new Phase(gameBoard, playerList, 600, this); @@ -111,7 +108,7 @@ public class RoboRallyGame implements IRoboRallyGame { } @Override - public GameState getGameState(){ + public GameState getGameState() { return gameState; } @@ -135,6 +132,11 @@ public class RoboRallyGame implements IRoboRallyGame { return program; } + @Override + public void setProgram(List program) { + this.program = program; + } + @Override public int getProgramSize() { Player player = getPlayerFromName(playerName); @@ -144,11 +146,6 @@ public class RoboRallyGame implements IRoboRallyGame { return -1; } - @Override - public void setProgram(List program) { - this.program = program; - } - @Override public void receiveAllPrograms(ProgamsContainer programs) throws InterruptedException { //Reads data from server and updates player objects @@ -181,7 +178,7 @@ public class RoboRallyGame implements IRoboRallyGame { } @Override - public void receiveStayInPowerDown(PowerdownContainer powerDowns) { + public void receiveStayInPowerDown(PowerDownContainer powerDowns) { for (Player player : playerList) { player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName())); } @@ -191,12 +188,22 @@ public class RoboRallyGame implements IRoboRallyGame { /** * Gets the name of the player that won the game + * * @return The name of the winning player */ public String getWinningPlayerName() { return winningPlayerName; } + /** + * Sets the name of the player that won the game + * + * @param winningPlayerName The player winning the game + */ + protected void setWinningPlayerName(String winningPlayerName) { + this.winningPlayerName = winningPlayerName; + } + /** * Initializes the game with a debugging board */ @@ -225,7 +232,7 @@ public class RoboRallyGame implements IRoboRallyGame { List robots = new ArrayList<>(); int posX = 1; for (Player player : playerList) { - Position spawn = new Position(posX,1); + Position spawn = new Position(posX, 1); robots.add(new Robot(player.getRobotID(), spawn)); posX++; } @@ -274,7 +281,7 @@ public class RoboRallyGame implements IRoboRallyGame { //Distributes programming cards for all players, and sends a deck to each player distributeProgrammingCardsToPlayers(); for (Connection connection : server.getPlayerNames().keySet()) { - String playerName = server.getPlayerNames().get(connection); + String playerName = server.getPlayerNames().get(connection); Player player = getPlayerFromName(playerName); if (player != null && player.getPlayerDeck() != null) { server.sendToClient(connection, player.getPlayerDeck()); @@ -333,8 +340,9 @@ public class RoboRallyGame implements IRoboRallyGame { /** * Moves a card from the player's deck to the player's locked deck if found - * @param card The card to move to the locked deck - * @param playerDeck The deck containing the player's cards + * + * @param card The card to move to the locked deck + * @param playerDeck The deck containing the player's cards * @param lockedPlayerDeck The deck containing the player's locked cards */ private void moveProgrammingCardToLockedDeck(ProgrammingCard card, ProgrammingCardDeck playerDeck, @@ -378,18 +386,10 @@ public class RoboRallyGame implements IRoboRallyGame { throw new IllegalStateException("Player deck must be empty when dealing new cards!"); } //Gives the player the correct amount of cards - playerDeck.draw(mainDeck,9 - robotDamage); + playerDeck.draw(mainDeck, 9 - robotDamage); } } - /** - * Sets the name of the player that won the game - * @param winningPlayerName The player winning the game - */ - protected void setWinningPlayerName(String winningPlayerName) { - this.winningPlayerName = winningPlayerName; - } - /** * Respawn all the dead robots with more lives and places them on the game board */ @@ -422,7 +422,8 @@ public class RoboRallyGame implements IRoboRallyGame { /** * Sets the power down status of a robot - * @param player The player that owns the robot + * + * @param player The player that owns the robot * @param powerDownStatus The new power down status */ private void setRobotPowerDown(Player player, Boolean powerDownStatus) { @@ -431,6 +432,7 @@ public class RoboRallyGame implements IRoboRallyGame { /** * Gets a player object given a player name + * * @param name The name of the player to get * @return The corresponding player object or null if no such object exists */ diff --git a/src/main/java/inf112/fiasko/roborally/objects/Robot.java b/src/main/java/inf112/fiasko/roborally/objects/Robot.java index 9e94dcc..b7bdfe0 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Robot.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Robot.java @@ -8,9 +8,9 @@ import inf112.fiasko.roborally.elementproperties.RobotID; * This class represents a robot */ public class Robot { + private final RobotID robotId; private int amountOfLives = 3; private int robotDamageTaken = 0; - private final RobotID robotId; private boolean inPowerDown = false; private int lastFlagVisited = 0; private Position backupPosition; @@ -20,10 +20,11 @@ public class Robot { /** * Instantiates a new robot - * @param robotId The global identifier of the robot + * + * @param robotId The global identifier of the robot * @param spawnPosition The starting position of the robot */ - public Robot (RobotID robotId, Position spawnPosition) { + public Robot(RobotID robotId, Position spawnPosition) { this.robotId = robotId; this.backupPosition = spawnPosition; this.currentPosition = spawnPosition; @@ -32,6 +33,7 @@ public class Robot { /** * True if the robot has touched a flag in the current turn + * * @return a boolean */ public boolean isHasTouchedFlagThisTurn() { @@ -41,6 +43,7 @@ public class Robot { /** * Sets the boolean value to true if the robot touches a flag during a turn, * and false at the end of each turn. + * * @param hasTouchedFlagThisTurn the boolean value to be set. */ public void setHasTouchedFlagThisTurn(boolean hasTouchedFlagThisTurn) { @@ -49,6 +52,7 @@ public class Robot { /** * Gets the damage the robot has taken + * * @return The amount of damage the robot has received */ public int getDamageTaken() { @@ -57,6 +61,7 @@ public class Robot { /** * Sets the robot's taken damage to a given amount + * * @param damage The amount of damage the robot has received */ public void setDamageTaken(int damage) { @@ -65,6 +70,7 @@ public class Robot { /** * Gets the robot's current position on the board + * * @return The robot's current position */ public Position getPosition() { @@ -73,14 +79,16 @@ public class Robot { /** * Sets the robot's current position on the board + * * @param newPosition The new position of the robot */ - public void setPosition( Position newPosition ) { + public void setPosition(Position newPosition) { this.currentPosition = newPosition; } /** * Sets power-down status + * * @param powerDownStatus Whether the robot is currently in power-down */ public void setPowerDown(Boolean powerDownStatus) { @@ -89,6 +97,7 @@ public class Robot { /** * Gets the robot's power-down status + * * @return Whether the robot is currently in power-down */ public Boolean isInPowerDown() { @@ -97,6 +106,7 @@ public class Robot { /** * Set the robot's last visited flag to the new flag and places its backup on the flag's position + * * @param currentFlag The flag the robot is standing on */ public void setLastFlagVisitedAndUpdateBackupPosition(int currentFlag) { @@ -109,6 +119,7 @@ public class Robot { /** * Gets the last flag the robot visited + * * @return Last visited flag */ public int getLastFlagVisited() { @@ -117,6 +128,7 @@ public class Robot { /** * Gets the robot's backup position + * * @return The robot's backup position */ public Position getBackupPosition() { @@ -125,6 +137,7 @@ public class Robot { /** * Gets the robot ID + * * @return Robot ID */ public RobotID getRobotId() { @@ -133,6 +146,7 @@ public class Robot { /** * Gets the direction the robot is currently facing + * * @return The direction the robot is facing */ public Direction getFacingDirection() { @@ -141,6 +155,7 @@ public class Robot { /** * Sets the direction the robot is currently facing + * * @param newFacingDirection The new direction the robot should be facing */ public void setFacingDirection(Direction newFacingDirection) { @@ -150,24 +165,27 @@ public class Robot { this.facingDirection = newFacingDirection; } - /** - * Sets the amount if life the robot has left - * @param amountOfLives the new amount if lives the robot has left - */ - public void setAmountOfLives(int amountOfLives) { - this.amountOfLives = amountOfLives; - } - /** * Gets the amount of life a robot has left. + * * @return amount of life left */ public int getAmountOfLives() { return this.amountOfLives; } + /** + * Sets the amount if life the robot has left + * + * @param amountOfLives the new amount if lives the robot has left + */ + public void setAmountOfLives(int amountOfLives) { + this.amountOfLives = amountOfLives; + } + /** * Makes a copy of this robot with the same properties as this robot + * * @return A copy of this robot */ public Robot copy() { diff --git a/src/main/java/inf112/fiasko/roborally/objects/Tile.java b/src/main/java/inf112/fiasko/roborally/objects/Tile.java index ba85a87..d8e9e77 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Tile.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Tile.java @@ -13,7 +13,8 @@ public class Tile { /** * Instantiates a new tile - * @param tileType The type of the tile + * + * @param tileType The type of the tile * @param direction The direction of the tile */ public Tile(TileType tileType, Direction direction) { @@ -26,6 +27,7 @@ public class Tile { /** * Gets the tile type of the tile + * * @return The tile's tile type */ public TileType getTileType() { @@ -34,6 +36,7 @@ public class Tile { /** * Gets the direction of the tile + * * @return The tile's direction */ public Direction getDirection() { diff --git a/src/main/java/inf112/fiasko/roborally/objects/Wall.java b/src/main/java/inf112/fiasko/roborally/objects/Wall.java index ac49057..99f675c 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Wall.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Wall.java @@ -12,10 +12,11 @@ public class Wall { /** * Initializes a wall - * @param wallType The type of the wall + * + * @param wallType The type of the wall * @param direction The direction of the wall */ - public Wall (WallType wallType, Direction direction) { + public Wall(WallType wallType, Direction direction) { if (direction.getDirectionID() % 2 == 0 && wallType != WallType.WALL_CORNER) { throw new IllegalArgumentException("Invalid direction for wall type submitted"); } @@ -25,6 +26,7 @@ public class Wall { /** * Gets the type of the wall + * * @return The wall type */ public WallType getWallType() { @@ -33,6 +35,7 @@ public class Wall { /** * Gets the direction of the wall + * * @return The direction of the wall */ public Direction getDirection() { diff --git a/src/test/java/inf112/fiasko/roborally/GdxTestRunner.java b/src/test/java/inf112/fiasko/roborally/GdxTestRunner.java index b106897..6f99653 100644 --- a/src/test/java/inf112/fiasko/roborally/GdxTestRunner.java +++ b/src/test/java/inf112/fiasko/roborally/GdxTestRunner.java @@ -29,6 +29,7 @@ import org.junit.runners.model.InitializationError; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; + import static org.mockito.Mockito.mock; import com.badlogic.gdx.ApplicationListener; diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardElementContainerTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardElementContainerTest.java index fa41016..75d49bb 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardElementContainerTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardElementContainerTest.java @@ -11,7 +11,7 @@ public class BoardElementContainerTest { @Test public void getObjectTest() { - Position pos = new Position(1,2); + Position pos = new Position(1, 2); Tile tile = new Tile(TileType.TILE, Direction.NORTH); BoardElementContainer element = new BoardElementContainer<>(tile, pos); assertEquals(tile, element.getElement()); @@ -19,7 +19,7 @@ public class BoardElementContainerTest { @Test public void getPositionTest() { - Position pos = new Position(1,2); + Position pos = new Position(1, 2); Tile tile = new Tile(TileType.TILE, Direction.NORTH); BoardElementContainer element = new BoardElementContainer<>(tile, pos); assertEquals(pos, element.getPosition()); diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index 524a3a5..dfc1dea 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -21,8 +21,6 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; public class BoardTest { - private Grid tileGrid; - private Grid wallGrid; private static Position zeroPosition; private static Position someValidPosition1; private static Position someValidPosition2; @@ -32,11 +30,13 @@ public class BoardTest { private static Position someValidPosition6; private static Position someValidPosition7; private static Position someValidPosition8; + private final Map wallTypeNumberMap = new HashMap<>(); + private final Map tileTypeNumberMap = new HashMap<>(); + private Grid tileGrid; + private Grid wallGrid; private List robotList; private Board board; private Board boardWithDifferentAmountOfAllTypes; - private final Map wallTypeNumberMap = new HashMap<>(); - private final Map tileTypeNumberMap = new HashMap<>(); private List robotListforlaser; private Board boardforlaser; private List robotListforpowerdown; @@ -58,30 +58,30 @@ public class BoardTest { @Before public void setUp() { - Grid tileGridforpowerdown = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH)); - Grid wallGridforpowerdown = new Grid<>(8, 8); + Grid tileGridforpowerdown = new ListGrid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH)); + Grid wallGridforpowerdown = new ListGrid<>(8, 8); robotListforpowerdown = new ArrayList<>(); - robotListforpowerdown.add(new Robot(RobotID.ROBOT_1, new Position(2,1))); - robotListforpowerdown.add(new Robot(RobotID.ROBOT_2, new Position(4,0))); - robotListforpowerdown.add(new Robot(RobotID.ROBOT_3, new Position(4,1))); - robotListforpowerdown.add(new Robot(RobotID.ROBOT_4, new Position(1,7))); - robotListforpowerdown.add(new Robot(RobotID.ROBOT_5, new Position(0,4))); - robotListforpowerdown.add(new Robot(RobotID.ROBOT_6, new Position(0,5))); - robotListforpowerdown.add(new Robot(RobotID.ROBOT_7, new Position(7,0))); - robotListforpowerdown.add(new Robot(RobotID.ROBOT_8, new Position(1,1))); + robotListforpowerdown.add(new Robot(RobotID.ROBOT_1, new Position(2, 1))); + robotListforpowerdown.add(new Robot(RobotID.ROBOT_2, new Position(4, 0))); + robotListforpowerdown.add(new Robot(RobotID.ROBOT_3, new Position(4, 1))); + robotListforpowerdown.add(new Robot(RobotID.ROBOT_4, new Position(1, 7))); + robotListforpowerdown.add(new Robot(RobotID.ROBOT_5, new Position(0, 4))); + robotListforpowerdown.add(new Robot(RobotID.ROBOT_6, new Position(0, 5))); + robotListforpowerdown.add(new Robot(RobotID.ROBOT_7, new Position(7, 0))); + robotListforpowerdown.add(new Robot(RobotID.ROBOT_8, new Position(1, 1))); boardforpowerdown = new Board(tileGridforpowerdown, wallGridforpowerdown, robotListforpowerdown); - Grid tileGridforlaser = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH)); - Grid wallGridforlaser = new Grid<>(8, 8); + Grid tileGridforlaser = new ListGrid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH)); + Grid wallGridforlaser = new ListGrid<>(8, 8); robotListforlaser = new ArrayList<>(); - robotListforlaser.add(new Robot(RobotID.ROBOT_1, new Position(2,1))); - robotListforlaser.add(new Robot(RobotID.ROBOT_2, new Position(4,0))); - robotListforlaser.add(new Robot(RobotID.ROBOT_3, new Position(4,1))); - robotListforlaser.add(new Robot(RobotID.ROBOT_4, new Position(1,7))); - robotListforlaser.add(new Robot(RobotID.ROBOT_5, new Position(0,4))); - robotListforlaser.add(new Robot(RobotID.ROBOT_6, new Position(0,5))); - robotListforlaser.add(new Robot(RobotID.ROBOT_7, new Position(7,0))); - robotListforlaser.add(new Robot(RobotID.ROBOT_8, new Position(1,1))); + robotListforlaser.add(new Robot(RobotID.ROBOT_1, new Position(2, 1))); + robotListforlaser.add(new Robot(RobotID.ROBOT_2, new Position(4, 0))); + robotListforlaser.add(new Robot(RobotID.ROBOT_3, new Position(4, 1))); + robotListforlaser.add(new Robot(RobotID.ROBOT_4, new Position(1, 7))); + robotListforlaser.add(new Robot(RobotID.ROBOT_5, new Position(0, 4))); + robotListforlaser.add(new Robot(RobotID.ROBOT_6, new Position(0, 5))); + robotListforlaser.add(new Robot(RobotID.ROBOT_7, new Position(7, 0))); + robotListforlaser.add(new Robot(RobotID.ROBOT_8, new Position(1, 1))); wallGridforlaser.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); wallGridforlaser.setElement(1, 3, new Wall(WallType.WALL_LASER_SINGLE, Direction.SOUTH)); wallGridforlaser.setElement(7, 4, new Wall(WallType.WALL_LASER_DOUBLE, Direction.SOUTH)); @@ -92,8 +92,8 @@ public class BoardTest { wallGridforlaser.setElement(0, 5, new Wall(WallType.WALL_LASER_SINGLE, Direction.SOUTH)); boardforlaser = new Board(tileGridforlaser, wallGridforlaser, robotListforlaser); - tileGrid = new Grid<>(5, 5, new Tile(TileType.TILE, Direction.NORTH)); - wallGrid = new Grid<>(5, 5); + tileGrid = new ListGrid<>(5, 5, new Tile(TileType.TILE, Direction.NORTH)); + wallGrid = new ListGrid<>(5, 5); robotList = new ArrayList<>(); robotList.add(new Robot(RobotID.ROBOT_1, someValidPosition1)); robotList.add(new Robot(RobotID.ROBOT_2, someValidPosition2)); @@ -108,12 +108,12 @@ public class BoardTest { wallGrid.setElement(2, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST)); wallGrid.setElement(1, 2, new Wall(WallType.WALL_CORNER, Direction.NORTH_EAST)); - tileGrid.setElement(3,3, new Tile(TileType.FLAG_1, Direction.NORTH)); - tileGrid.setElement(2,2, new Tile(TileType.FLAG_2, Direction.NORTH)); + tileGrid.setElement(3, 3, new Tile(TileType.FLAG_1, Direction.NORTH)); + tileGrid.setElement(2, 2, new Tile(TileType.FLAG_2, Direction.NORTH)); board = new Board(tileGrid, wallGrid, robotList); - Grid tileGridAllTypes = new Grid<>(6,6); - Grid wallGridAllTypes = new Grid<>(6,6); + Grid tileGridAllTypes = new ListGrid<>(6, 6); + Grid wallGridAllTypes = new ListGrid<>(6, 6); List emptyRobotList = new ArrayList<>(); wallGridAllTypes.setElement(1, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); wallGridAllTypes.setElement(1, 2, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); @@ -135,32 +135,35 @@ public class BoardTest { tileTypeNumberMap.put(TileType.COGWHEEL_RIGHT, 4); tileTypeNumberMap.put(TileType.COGWHEEL_LEFT, 1); tileTypeNumberMap.put(TileType.TILE, 5); - boardWithDifferentAmountOfAllTypes = new Board(tileGridAllTypes,wallGridAllTypes,emptyRobotList); + boardWithDifferentAmountOfAllTypes = new Board(tileGridAllTypes, wallGridAllTypes, emptyRobotList); } + @Test public void setRobotPowerDownStatus() { Robot testrobot = robotListforpowerdown.get(0); - assertEquals(false , testrobot.isInPowerDown()); - boardforpowerdown.setPowerDown(RobotID.ROBOT_1,true); - assertEquals(true , testrobot.isInPowerDown()); + assertEquals(false, testrobot.isInPowerDown()); + boardforpowerdown.setPowerDown(RobotID.ROBOT_1, true); + assertEquals(true, testrobot.isInPowerDown()); } + @Test public void executRobotPowerDown() { Robot testrobot = robotListforpowerdown.get(1); - boardforpowerdown.setPowerDown(RobotID.ROBOT_2,true); + boardforpowerdown.setPowerDown(RobotID.ROBOT_2, true); testrobot.setDamageTaken(4); - assertEquals(4,testrobot.getDamageTaken()); + assertEquals(4, testrobot.getDamageTaken()); boardforpowerdown.executePowerdown(); - assertEquals(0,testrobot.getDamageTaken()); + assertEquals(0, testrobot.getDamageTaken()); } + @Test public void repairRobotOnRepairTile() { Robot testrobot = robotListforpowerdown.get(2); testrobot.setDamageTaken(4); - assertEquals(4,testrobot.getDamageTaken()); + assertEquals(4, testrobot.getDamageTaken()); boardforpowerdown.repairRobotOnTile(RobotID.ROBOT_3); - assertEquals(3,testrobot.getDamageTaken()); + assertEquals(3, testrobot.getDamageTaken()); } @Test @@ -168,15 +171,17 @@ public class BoardTest { Robot testRobot = robotListforlaser.get(7); assertEquals(0, testRobot.getDamageTaken()); boardforlaser.fireAllLasers(); - assertNotEquals(0,testRobot.getDamageTaken()); + assertNotEquals(0, testRobot.getDamageTaken()); } + @Test public void laserBlockedByWallDoesNotDamageRobot() { Robot testRobot = robotListforlaser.get(0); assertEquals(0, testRobot.getDamageTaken()); boardforlaser.fireAllLasers(); - assertEquals(0,testRobot.getDamageTaken()); + assertEquals(0, testRobot.getDamageTaken()); } + @Test public void laserBlockedByRobotDoesNotDamageOtherRobot() { Robot testRobot1 = robotListforlaser.get(1); @@ -185,16 +190,18 @@ public class BoardTest { assertEquals(0, testRobot1.getDamageTaken()); assertEquals(0, testRobot2.getDamageTaken()); boardforlaser.fireAllLasers(); - assertEquals(0,testRobot1.getDamageTaken()); - assertNotEquals(0,testRobot2.getDamageTaken()); + assertEquals(0, testRobot1.getDamageTaken()); + assertNotEquals(0, testRobot2.getDamageTaken()); } + @Test public void doubleLaserDamage() { Robot testRobot = robotListforlaser.get(6); assertEquals(0, testRobot.getDamageTaken()); boardforlaser.fireAllLasers(); - assertEquals(2,testRobot.getDamageTaken()); + assertEquals(2, testRobot.getDamageTaken()); } + @Test public void robotGetsHitByTwoLasers() { Robot testRobot = robotListforlaser.get(3); @@ -202,38 +209,41 @@ public class BoardTest { boardforlaser.fireAllLasers(); assertEquals(2, testRobot.getDamageTaken()); } - @Test - public void robotDamageEachOther() { - Robot robot5 = robotListforlaser.get(4); - Robot robot6 = robotListforlaser.get(5); - robot5.setFacingDirection(Direction.SOUTH); - assertEquals(0, robot5.getDamageTaken()); - assertEquals(0, robot6.getDamageTaken()); - boardforlaser.fireAllLasers(); - assertEquals(1, robot5.getDamageTaken()); - assertEquals(2, robot6.getDamageTaken()); - } - @Test - public void robotStandingOnLaserTakesDamage() { - Robot robot6 = robotListforlaser.get(5); - assertEquals(0, robot6.getDamageTaken()); - boardforlaser.fireAllLasers(); - assertEquals(1, robot6.getDamageTaken()); - } + + @Test + public void robotDamageEachOther() { + Robot robot5 = robotListforlaser.get(4); + Robot robot6 = robotListforlaser.get(5); + robot5.setFacingDirection(Direction.SOUTH); + assertEquals(0, robot5.getDamageTaken()); + assertEquals(0, robot6.getDamageTaken()); + boardforlaser.fireAllLasers(); + assertEquals(1, robot5.getDamageTaken()); + assertEquals(2, robot6.getDamageTaken()); + } + + @Test + public void robotStandingOnLaserTakesDamage() { + Robot robot6 = robotListforlaser.get(5); + assertEquals(0, robot6.getDamageTaken()); + boardforlaser.fireAllLasers(); + assertEquals(1, robot6.getDamageTaken()); + } + @Test public void flagGetsUpdatedOnRobotWithCorrectLastVisitedFlag() { Robot testRobot = robotList.get(6); - assertEquals(0,testRobot.getLastFlagVisited()); + assertEquals(0, testRobot.getLastFlagVisited()); board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_1); - assertEquals(1,testRobot.getLastFlagVisited()); + assertEquals(1, testRobot.getLastFlagVisited()); } @Test public void flagDoesNotUpdatedOnRobotWithWringLastVisitedFlag() { Robot testRobot = robotList.get(6); - assertEquals(0,testRobot.getLastFlagVisited()); + assertEquals(0, testRobot.getLastFlagVisited()); board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_2); - assertEquals(0,testRobot.getLastFlagVisited()); + assertEquals(0, testRobot.getLastFlagVisited()); } @Test @@ -293,13 +303,13 @@ public class BoardTest { assertEquals(Direction.NORTH, robot.getFacingDirection()); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void gridsOfDifferentSizeThrowsError() { - IGrid wallGrid = new Grid<>(1, 1); + Grid wallGrid = new ListGrid<>(1, 1); new Board(tileGrid, wallGrid, robotList); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void multipleRobotsWithSameIDThrowsError() { Robot robot = new Robot(RobotID.ROBOT_1, someValidPosition1); robotList.add(robot); @@ -336,7 +346,7 @@ public class BoardTest { @Test public void getPositionsOfTileOnBoardGivesCorrectAmountOfCogwheelLeftTiles() { - assertEquals((int)tileTypeNumberMap.get(TileType.COGWHEEL_LEFT), + assertEquals((int) tileTypeNumberMap.get(TileType.COGWHEEL_LEFT), boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT).size()); } @@ -348,7 +358,7 @@ public class BoardTest { @Test public void getPositionsOfTileOnBoardGivesCorrectAmountOfTileTiles() { - assertEquals((int)tileTypeNumberMap.get(TileType.TILE), + assertEquals((int) tileTypeNumberMap.get(TileType.TILE), boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE).size()); } @@ -360,7 +370,7 @@ public class BoardTest { @Test public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallNormalWalls() { - assertEquals((int)wallTypeNumberMap.get(WallType.WALL_NORMAL), + assertEquals((int) wallTypeNumberMap.get(WallType.WALL_NORMAL), boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL).size()); } @@ -372,7 +382,7 @@ public class BoardTest { @Test public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallCornerWalls() { - assertEquals((int)wallTypeNumberMap.get(WallType.WALL_CORNER), + assertEquals((int) wallTypeNumberMap.get(WallType.WALL_CORNER), boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER).size()); } @@ -402,6 +412,7 @@ public class BoardTest { elemList.removeIf(pred); return 0 == elemList.size(); } + private boolean checkIfAllElementsAreOfSpecificTileType(List> elemList, K TileType) { Predicate> pred = (element) -> element.getElement().getTileType() == TileType; elemList.removeIf(pred); diff --git a/src/test/java/inf112/fiasko/roborally/objects/DrawableObjectTest.java b/src/test/java/inf112/fiasko/roborally/objects/DrawableObjectTest.java index 0bc560a..47c4a18 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/DrawableObjectTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/DrawableObjectTest.java @@ -15,16 +15,16 @@ import static org.junit.Assert.assertFalse; @RunWith(GdxTestRunner.class) public class DrawableObjectTest { + private static final int X_POSITION_MIN_ARG = 5; + private static final int Y_POSITION_MIN_ARG = 8; + private static final int X_POSITION_MAX_ARG = 6; + private static final int Y_POSITION_MAX_ARG = 7; private static final Texture textureSheet = new Texture(Gdx.files.internal("assets/tiles.png")); private static final Texture robotsTexture = new Texture(Gdx.files.internal("assets/robots.png")); + private static final TextureRegion TEXTURE_MAX_ARG = new TextureRegion(robotsTexture, 0, 0, + 64, 64); private static final TextureRegion TEXTURE_MIN_ARG = new TextureRegion(textureSheet, 4 * 300, 0, 300, 300); - public static final TextureRegion TEXTURE_MAX_ARG = new TextureRegion(robotsTexture, 0, 0, - 64, 64); - public static final int X_POSITION_MIN_ARG = 5; - public static final int Y_POSITION_MIN_ARG = 8; - public static final int X_POSITION_MAX_ARG = 6; - public static final int Y_POSITION_MAX_ARG = 7; private final int WIDTH_MAX_ARG = 50; private final int HEIGHT_MAX_ARG = 60; private final int ROTATION_MAX_ARG = 90; diff --git a/src/test/java/inf112/fiasko/roborally/objects/GridTest.java b/src/test/java/inf112/fiasko/roborally/objects/ListGridTest.java similarity index 72% rename from src/test/java/inf112/fiasko/roborally/objects/GridTest.java rename to src/test/java/inf112/fiasko/roborally/objects/ListGridTest.java index 5dc5d87..797b14f 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/GridTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/ListGridTest.java @@ -7,16 +7,16 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; -public class GridTest { - private Grid grid; - private Grid grid2; +public class ListGridTest { + private ListGrid grid; + private ListGrid grid2; private Tile defaultTile; @Before public void setUp() { defaultTile = new Tile(TileType.TILE, Direction.NORTH); - grid = new Grid<>(7, 4); - grid2 = new Grid<>(5,8, defaultTile); + grid = new ListGrid<>(7, 4); + grid2 = new ListGrid<>(5, 8, defaultTile); } @Test @@ -41,22 +41,22 @@ public class GridTest { @Test public void getElementFromGrid2() { - assertEquals(defaultTile, grid2.getElement(3,5)); + assertEquals(defaultTile, grid2.getElement(3, 5)); } @Test public void setElementInGrid2() { Tile hole = new Tile(TileType.HOLE, Direction.NORTH); - grid2.setElement(2,1, hole); - assertEquals(hole, grid2.getElement(2,1)); + grid2.setElement(2, 1, hole); + assertEquals(hole, grid2.getElement(2, 1)); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void invalidPositionThrowsErrorOnGet() { grid.getElement(7, 4); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void invalidPositionThrowsErrorOnSet() { grid2.setElement(5, 8, null); } diff --git a/src/test/java/inf112/fiasko/roborally/objects/ParticleTest.java b/src/test/java/inf112/fiasko/roborally/objects/ParticleTest.java index 92c684c..a690ca2 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/ParticleTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/ParticleTest.java @@ -44,7 +44,7 @@ public class ParticleTest { assertNull(ParticleType.getParticleTypeFromID(-1)); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void invalidParticleDirectionThrowsError() { new Particle(ParticleType.LASER_BEAM_DOUBLE, Direction.NORTH_EAST); } diff --git a/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java b/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java index b96da5a..08e85fd 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java @@ -14,8 +14,8 @@ import static org.junit.Assert.assertTrue; public class PlayerTest { - private Player playerTest; private final List cards = new ArrayList<>(); + private Player playerTest; @Before public void setUp() { @@ -24,7 +24,7 @@ public class PlayerTest { cards.add(new ProgrammingCard(30, Action.MOVE_3)); cards.add(new ProgrammingCard(40, Action.BACK_UP)); cards.add(new ProgrammingCard(50, Action.ROTATE_LEFT)); - playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" ); + playerTest = new Player(RobotID.ROBOT_1, "TestPlayer"); } @Test @@ -48,18 +48,18 @@ public class PlayerTest { assertEquals(Action.BACK_UP, playerTest.getProgram().get(3).getAction()); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testSetInProgramWithToManyCards() { - cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT)); + cards.add(new ProgrammingCard(10, Action.ROTATE_LEFT)); playerTest.setInProgram(cards); } @Test public void testSetInDeck() { - cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT)); + cards.add(new ProgrammingCard(10, Action.ROTATE_LEFT)); ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards); playerTest.setPlayerDeck(playerDeck); - assertEquals(playerDeck , playerTest.getPlayerDeck()); + assertEquals(playerDeck, playerTest.getPlayerDeck()); } @Test @@ -75,7 +75,7 @@ public class PlayerTest { @Test public void getProgramFromPlayer() { playerTest.setInProgram(cards); - assertEquals(cards,playerTest.getProgram()); + assertEquals(cards, playerTest.getProgram()); } } diff --git a/src/test/java/inf112/fiasko/roborally/objects/ProgrammingCardDeckTest.java b/src/test/java/inf112/fiasko/roborally/objects/ProgrammingCardDeckTest.java index 2721627..34bf9d1 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/ProgrammingCardDeckTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/ProgrammingCardDeckTest.java @@ -4,6 +4,7 @@ import inf112.fiasko.roborally.elementproperties.Action; import inf112.fiasko.roborally.utility.DeckLoaderUtil; import org.junit.Before; import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -16,9 +17,9 @@ import java.util.List; public class ProgrammingCardDeckTest { private ProgrammingCard programmingCard1; private ProgrammingCard programmingCard3; - private IDeck testDeck; - private IDeck testDeck2; - private IDeck fullDeck; + private Deck testDeck; + private Deck testDeck2; + private Deck fullDeck; @Before public void setUp() { @@ -40,18 +41,18 @@ public class ProgrammingCardDeckTest { @Test public void testSize() { - assertEquals(3,testDeck.size()); + assertEquals(3, testDeck.size()); testDeck.emptyInto(testDeck2); - assertEquals(0,testDeck.size()); + assertEquals(0, testDeck.size()); } @Test public void testDrawCard() { - assertEquals(3,testDeck.size()); - assertEquals(3,testDeck2.size()); + assertEquals(3, testDeck.size()); + assertEquals(3, testDeck2.size()); testDeck.draw(testDeck2); - assertEquals(4,testDeck.size()); - assertEquals(2,testDeck2.size()); + assertEquals(4, testDeck.size()); + assertEquals(2, testDeck2.size()); } @Test diff --git a/src/test/java/inf112/fiasko/roborally/objects/ProgrammingCardTest.java b/src/test/java/inf112/fiasko/roborally/objects/ProgrammingCardTest.java index d8e8ae7..10a3d2a 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/ProgrammingCardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/ProgrammingCardTest.java @@ -1,7 +1,9 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.elementproperties.Action; + import static org.junit.Assert.assertEquals; + import org.junit.Before; import org.junit.Test; @@ -17,11 +19,13 @@ public class ProgrammingCardTest { programmingCard2 = new ProgrammingCard(234, Action.ROTATE_LEFT); programmingCard3 = new ProgrammingCard(2334, Action.ROTATE_LEFT); } + @Test public void testGetProgrammingCardAction() { assertEquals(Action.MOVE_1, programmingCard1.getAction()); assertEquals(Action.ROTATE_LEFT, programmingCard2.getAction()); } + @Test public void testGetProgrammingCardValue() { assertEquals(5, programmingCard1.getPriority()); diff --git a/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java b/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java index eb1aa03..07715ea 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java @@ -8,12 +8,12 @@ import org.junit.Test; import java.util.ArrayList; public class RoboRallyGameTest { - private IDrawableGame game; + private DrawableGame game; @Before public void setUp() { - game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false, "Player1", - null, null); + game = new RoboRallyGame(new ArrayList<>(), "Checkmate.txt", false, "Player1", + null); } @Test diff --git a/src/test/java/inf112/fiasko/roborally/objects/RobotTest.java b/src/test/java/inf112/fiasko/roborally/objects/RobotTest.java index 32f8b52..4de1186 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/RobotTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/RobotTest.java @@ -1,6 +1,7 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.elementproperties.Position; + import static org.junit.Assert.assertEquals; import inf112.fiasko.roborally.elementproperties.RobotID; @@ -8,13 +9,13 @@ import org.junit.Before; import org.junit.Test; public class RobotTest { + private final int nextFlag = 1; private Position robotPosition; private Robot testRobot; - private final int nextFlag = 1; @Before public void setUp() { - robotPosition = new Position(3,6); + robotPosition = new Position(3, 6); testRobot = new Robot(RobotID.ROBOT_6, robotPosition); } @@ -46,7 +47,7 @@ public class RobotTest { @Test public void testRobotGetPositionOnRobotWithNewPosition() { - Position newRobotPosition = new Position(8,12); + Position newRobotPosition = new Position(8, 12); testRobot.setPosition(newRobotPosition); assertEquals(newRobotPosition, testRobot.getPosition()); } @@ -70,7 +71,7 @@ public class RobotTest { @Test public void testRobotGetNewBackup() { - Position nextFlagPosition = new Position(3,4); + Position nextFlagPosition = new Position(3, 4); testRobot.setPosition(nextFlagPosition); testRobot.setLastFlagVisitedAndUpdateBackupPosition(nextFlag); assertEquals(nextFlagPosition, testRobot.getBackupPosition()); diff --git a/src/test/java/inf112/fiasko/roborally/objects/TileTest.java b/src/test/java/inf112/fiasko/roborally/objects/TileTest.java index 8672352..990e7bd 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/TileTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/TileTest.java @@ -44,7 +44,7 @@ public class TileTest { assertNull(TileType.getTileTypeFromID(-1)); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void invalidTileDirectionThrowsError() { new Tile(TileType.TILE, Direction.NORTH_EAST); } diff --git a/src/test/java/inf112/fiasko/roborally/objects/WallTest.java b/src/test/java/inf112/fiasko/roborally/objects/WallTest.java index 7586989..076d1fe 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/WallTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/WallTest.java @@ -2,7 +2,9 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.elementproperties.Direction; import inf112.fiasko.roborally.elementproperties.WallType; + import static org.junit.Assert.assertEquals; + import org.junit.Test; public class WallTest { @@ -11,21 +13,25 @@ public class WallTest { Wall testGetWall = new Wall(WallType.WALL_NORMAL, Direction.NORTH); assertEquals(WallType.WALL_NORMAL, testGetWall.getWallType()); } + @Test public void testWallGetWallTypeCorner() { Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.NORTH); assertEquals(WallType.WALL_CORNER, testGetWall.getWallType()); } + @Test public void testWallGetWallTypeLaserSingle() { Wall testGetWall = new Wall(WallType.WALL_LASER_SINGLE, Direction.NORTH); assertEquals(WallType.WALL_LASER_SINGLE, testGetWall.getWallType()); } + @Test public void testWallGetDirectionNorth() { Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.NORTH); assertEquals(Direction.NORTH, testGetWall.getDirection()); } + @Test public void testWallGetDirectionEast() { Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.EAST);