Endrer navn på java grensesnitt og kjører automatisk reformatering av objekter og objekttester

Endrer IInteractabaleGame til InteractableGame
Endrer IDrawableGame til DrawableGame
Endrer IDeck til Deck
Endrer IGrid til Grid
Endrer Grid til ListGrid
Endrer Deck til AbstractDeck
Endrer PowerdownContainer til PowerDownContainer
Endrer GridTest til ListGridTest
Kjører IntelliJ sin automatiske reformatering for å fikse formateringsfeil
This commit is contained in:
Kristian Knarvik 2020-04-20 13:13:04 +02:00
parent 36b934242d
commit a0ba1511b3
35 changed files with 795 additions and 640 deletions

View File

@ -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<T> implements Deck<T> {
private final List<T> cardList;
public AbstractDeck() {
this.cardList = new ArrayList<>();
}
/**
* Initializes the deck with cards
*
* @param cardList list of cards
*/
public AbstractDeck(List<T> 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<T> other) {
AbstractDeck<T> otherDeck = (AbstractDeck<T>) 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<T> other, int n) {
AbstractDeck<T> otherDeck = (AbstractDeck<T>) 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<T> other) {
AbstractDeck<T> otherDeck = (AbstractDeck<T>) 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<T> 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);
}
}

View File

@ -18,20 +18,21 @@ import java.util.Map;
public class Board { public class Board {
private int boardHeight; private int boardHeight;
private int boardWidth; private int boardWidth;
private IGrid<Wall> walls; private Grid<Wall> walls;
private IGrid<Tile> tiles; private Grid<Tile> tiles;
private IGrid<Particle> particles; private Grid<Particle> particles;
private Map<RobotID, Robot> robots; private Map<RobotID, Robot> robots;
private List<Robot> deadRobots; private List<Robot> deadRobots;
private List<RobotID> realDeadRobots; private List<RobotID> realDeadRobots;
/** /**
* Initializes the board * Initializes the board
*
* @param tiles A grid containing all tiles * @param tiles A grid containing all tiles
* @param walls A grid containing all walls * @param walls A grid containing all walls
* @param robots A list of all robots in the game * @param robots A list of all robots in the game
*/ */
public Board(IGrid<Tile> tiles, IGrid<Wall> walls, List<Robot> robots) { public Board(Grid<Tile> tiles, Grid<Wall> walls, List<Robot> robots) {
if (walls.getWidth() != tiles.getWidth() || walls.getHeight() != tiles.getHeight()) { if (walls.getWidth() != tiles.getWidth() || walls.getHeight() != tiles.getHeight()) {
throw new IllegalArgumentException("The grids in the input don't have the same dimensions."); 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.boardHeight = tiles.getHeight();
this.walls = walls; this.walls = walls;
this.tiles = tiles; this.tiles = tiles;
this.particles = new Grid<>(tiles.getWidth(), tiles.getHeight()); this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight());
this.deadRobots = new ArrayList<>(); this.deadRobots = new ArrayList<>();
this.realDeadRobots = new ArrayList<>(); this.realDeadRobots = new ArrayList<>();
} }
/** /**
* All the Real dead player's robots. * All the Real dead player's robots.
*
* @return A list of Robots. * @return A list of Robots.
*/ */
public List<RobotID> getRealDeadRobots() { return realDeadRobots; } public List<RobotID> getRealDeadRobots() {
return realDeadRobots;
}
/** /**
* Gets the height of the board * Gets the height of the board
*
* @return The height of the board * @return The height of the board
*/ */
public int getBoardHeight() { public int getBoardHeight() {
@ -67,6 +72,7 @@ public class Board {
/** /**
* Gets the width of the board * Gets the width of the board
*
* @return The width of the board * @return The width of the board
*/ */
public int getBoardWidth() { public int getBoardWidth() {
@ -75,6 +81,7 @@ public class Board {
/** /**
* Gets all alive robots from the board * Gets all alive robots from the board
*
* @return A list of alive robots * @return A list of alive robots
*/ */
public List<Robot> getAliveRobots() { public List<Robot> getAliveRobots() {
@ -85,6 +92,7 @@ public class Board {
/** /**
* Gets all the tiles from the board * Gets all the tiles from the board
*
* @return A list of all tiles on the board * @return A list of all tiles on the board
*/ */
public List<Tile> getTiles() { public List<Tile> getTiles() {
@ -93,6 +101,7 @@ public class Board {
/** /**
* Gets all the walls from the board * Gets all the walls from the board
*
* @return A list of all the walls on the board * @return A list of all the walls on the board
*/ */
public List<Wall> getWalls() { public List<Wall> getWalls() {
@ -101,6 +110,7 @@ public class Board {
/** /**
* Gets all the particles from the board * Gets all the particles from the board
*
* @return A list of all the particles on the board * @return A list of all the particles on the board
*/ */
public List<Particle> getParticles() { public List<Particle> getParticles() {
@ -109,6 +119,7 @@ public class Board {
/** /**
* Rotates a robot to the right * Rotates a robot to the right
*
* @param robotID The id of the robot to rotate * @param robotID The id of the robot to rotate
*/ */
public void rotateRobotLeft(RobotID robotID) { public void rotateRobotLeft(RobotID robotID) {
@ -119,6 +130,7 @@ public class Board {
/** /**
* Rotates a robot to the left * Rotates a robot to the left
*
* @param robotID The id of the robot to rotate * @param robotID The id of the robot to rotate
*/ */
public void rotateRobotRight(RobotID robotID) { 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 * Moves a robot one unit forward according to the direction it's currently facing
*
* @param robotID The robot to move * @param robotID The robot to move
*/ */
public void moveRobotForward(RobotID robotID) { 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 * Moves a robot one unit backwards according to the direction it's currently facing
*
* @param robotID The robot to move * @param robotID The robot to move
*/ */
public void reverseRobot(RobotID robotID) { public void reverseRobot(RobotID robotID) {
@ -145,6 +159,7 @@ public class Board {
/** /**
* Sets the power down status of the robot * 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 * @param powerdown The status of the powerdown
*/ */
@ -154,6 +169,7 @@ public class Board {
/** /**
* Gets the power down status of the robot * Gets the power down status of the robot
*
* @param robotID The robot id of the robot * @param robotID The robot id of the robot
*/ */
public boolean getPowerDown(RobotID robotID) { 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 * removes one damage for a given robot given that it has taken som damage before
*
* @param robotID the ID of the robot * @param robotID the ID of the robot
*/ */
public void repairRobotOnTile(RobotID robotID) { public void repairRobotOnTile(RobotID robotID) {
@ -183,6 +200,7 @@ public class Board {
/** /**
* Get the damage of a specific robot * Get the damage of a specific robot
*
* @param robot The RobotID of a robot * @param robot The RobotID of a robot
* @return The amount of damage the robot has currently * @return The amount of damage the robot has currently
*/ */
@ -192,6 +210,7 @@ public class Board {
/** /**
* Moves a robot one unit in a specified direction * 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 * @param direction The direction to move the robot
* @return True if the robot moved away from its old position * @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 * Checks whether a given tile is a conveyor belt
*
* @param tile The tile to check * @param tile The tile to check
* @return True if the tile is a conveyor belt * @return True if the tile is a conveyor belt
*/ */
@ -253,9 +273,9 @@ public class Board {
/** /**
* Teleports a robot to some position without verification * 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 * <p>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 * 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.</p>
* *
* @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 * @param newPosition The position the robot should teleport to
@ -266,6 +286,7 @@ public class Board {
/** /**
* Checks whether a given conveyor belt is able to move in its direction * Checks whether a given conveyor belt is able to move in its direction
*
* @param conveyorBelt The conveyor belt to move * @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 * @return True if nothing is blocking its movement
@ -308,6 +329,7 @@ public class Board {
/** /**
* Checks whether a conveyor belt has anything in front of it preventing it from moving forward * 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 conveyorBeltPosition The position of the conveyor belt
* @param positionInFront The position in front of the conveyor belt * @param positionInFront The position in front of the conveyor belt
* @param conveyorBeltDirection The direction of the conveyor belt * @param conveyorBeltDirection The direction of the conveyor belt
@ -321,6 +343,7 @@ public class Board {
/** /**
* Checks whether a conveyor belt has a conflict in a crossing * 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 * @param conveyorBeltDirection The direction of the conveyor belt
* @return True if there is a conflict. False otherwise * @return True if there is a conflict. False otherwise
@ -356,8 +379,7 @@ public class Board {
robot.setFacingDirection(Direction.NORTH); robot.setFacingDirection(Direction.NORTH);
robot.setDamageTaken(2); robot.setDamageTaken(2);
robots.put(robot.getRobotId(), robot); robots.put(robot.getRobotId(), robot);
} } else {
else {
realDeadRobots.add(robot.getRobotId()); 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 * Returns a robot id for a robot on a specific position if such a robot exists
*
* @param position The position to check * @param position The position to check
* @return The robot id of the robot on the position or null if there is no robot there * @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 * Checks if a specific robot is currently alive on the board
*
* @param robot the ID of the robot you want to check * @param robot the ID of the robot you want to check
* @return True/False based on if the robot was found. * @return True/False based on if the robot was found.
*/ */
@ -390,6 +414,7 @@ public class Board {
/** /**
* Updates the flag of the robot if it stands on the correct flag. * Updates the flag of the robot if it stands on the correct flag.
*
* @param robotID The RobotID of a robot * @param robotID The RobotID of a robot
* @param flagID TileType of the flag we check * @param flagID TileType of the flag we check
*/ */
@ -403,6 +428,7 @@ public class Board {
/** /**
* Gets the position 1 unit in a specific direction from another position * Gets the position 1 unit in a specific direction from another position
*
* @param oldPosition The old/current position of the element * @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 * @return The new position of the element
@ -428,8 +454,8 @@ public class Board {
public void fireAllLasers() { public void fireAllLasers() {
List<BoardElementContainer<Wall>> listOfWallLasers = getPositionsOfWallOnBoard(WallType.WALL_LASER_SINGLE, List<BoardElementContainer<Wall>> listOfWallLasers = getPositionsOfWallOnBoard(WallType.WALL_LASER_SINGLE,
WallType.WALL_LASER_DOUBLE); WallType.WALL_LASER_DOUBLE);
for (Robot robot:robots.values()) { for (Robot robot : robots.values()) {
fireRobotLaser(robot.getPosition(),robot.getFacingDirection()); fireRobotLaser(robot.getPosition(), robot.getFacingDirection());
} }
for (BoardElementContainer<Wall> laser : listOfWallLasers) { for (BoardElementContainer<Wall> laser : listOfWallLasers) {
fireWallLaser(laser); fireWallLaser(laser);
@ -440,12 +466,13 @@ public class Board {
* Does necessary cleanup after lasers have been fired * Does necessary cleanup after lasers have been fired
*/ */
public void doLaserCleanup() { public void doLaserCleanup() {
this.particles = new Grid<>(tiles.getWidth(), tiles.getHeight()); this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight());
killAllHeavilyDamagedRobots(); killAllHeavilyDamagedRobots();
} }
/** /**
* Gets the tile on a specific position * Gets the tile on a specific position
*
* @param position The position to get a tile from * @param position The position to get a tile from
* @return The tile on the given position * @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 * Gets a list of BoardElementContainers, containing all tiles and positions of given tile types
*
* @param tiles The tiles you want all positions for * @param tiles The tiles you want all positions for
* @return A list of BoardElementContainers * @return A list of BoardElementContainers
*/ */
public List<BoardElementContainer<Tile>> getPositionsOfTileOnBoard(TileType ... tiles) { public List<BoardElementContainer<Tile>> getPositionsOfTileOnBoard(TileType... tiles) {
List<BoardElementContainer<Tile>> combinedList = new ArrayList<>(); List<BoardElementContainer<Tile>> combinedList = new ArrayList<>();
for (TileType tile : tiles) { for (TileType tile : tiles) {
combinedList.addAll(makeTileList(tile, this.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 * Gets a list of BoardElementContainers, containing all tiles and positions of given wall types
*
* @param walls The walls you want all positions for * @param walls The walls you want all positions for
* @return A list of BoardElementContainers * @return A list of BoardElementContainers
*/ */
@ -484,6 +513,7 @@ public class Board {
/** /**
* Checks whether there exists a robot on a specific position * Checks whether there exists a robot on a specific position
*
* @param position The position to check * @param position The position to check
* @return True if there is a robot on the specified position * @return True if there is a robot on the specified position
*/ */
@ -493,6 +523,7 @@ public class Board {
/** /**
* Checks if a potential move would be blocked by a wall * Checks if a potential move would be blocked by a wall
*
* @param robotPosition The current position of whatever is trying to move * @param robotPosition The current position of whatever is trying to move
* @param newPosition The position something is trying to move to * @param newPosition The position something is trying to move to
* @param direction The direction something is going * @param direction The direction something is going
@ -505,6 +536,7 @@ public class Board {
/** /**
* Checks whether a given position is valid * Checks whether a given position is valid
*
* @param position The position to test * @param position The position to test
* @return True if the position is valid. False otherwise * @return True if the position is valid. False otherwise
*/ */
@ -517,6 +549,7 @@ public class Board {
/** /**
* Checks if the robot is about to step outside of the board, and kills it if it does * 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 * @param newPosition The position the robot is attempting to move to
* @return True if the robot was killed for leaving the board * @return True if the robot was killed for leaving the board
@ -531,6 +564,7 @@ public class Board {
/** /**
* Checks the tile the robot is about to step on and kills it if the tile is dangerous * 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 * @param newPosition The position the robot is attempting to move to
*/ */
@ -555,8 +589,8 @@ public class Board {
/** /**
* Kills the robot * 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 * <p>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. * properly dispose of the robot until the next round.</p>
* *
* @param robot The robot to kill * @param robot The robot to kill
*/ */
@ -568,6 +602,7 @@ public class Board {
/** /**
* Checks whether a position has a wall facing a specific direction * 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 * @param direction The direction of the wall to check for
* @return True if there is a wall on the position facing the input direction * @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 * Gets all elements on a grid
*
* @param grid The grid to get elements from * @param grid The grid to get elements from
* @param <K> The type of the elements int the grid * @param <K> The type of the elements int the grid
* @return A list containing all the elements in the grid * @return A list containing all the elements in the grid
*/ */
private <K> List<K> getAllElementsFromGrid(IGrid<K> grid) { private <K> List<K> getAllElementsFromGrid(Grid<K> grid) {
List<K> elements = new ArrayList<>(); List<K> elements = new ArrayList<>();
for (int y = grid.getHeight() - 1; y >= 0; y--) { for (int y = grid.getHeight() - 1; y >= 0; y--) {
for (int x = 0; x < grid.getWidth(); x++) { for (int x = 0; x < grid.getWidth(); x++) {
@ -604,13 +640,14 @@ public class Board {
/** /**
* Finds all tiles/walls with a certain type * Finds all tiles/walls with a certain type
*
* @param type The type of tile/wall to look for * @param type The type of tile/wall to look for
* @param grid The grid to look through * @param grid The grid to look through
* @param <K> Type of the type to look for * @param <K> Type of the type to look for
* @param <T> Type of the grid * @param <T> Type of the grid
* @return List of BoardElementContainers * @return List of BoardElementContainers
*/ */
private <K,T> List<BoardElementContainer<T>> makeTileList(K type, IGrid<T> grid) { private <K, T> List<BoardElementContainer<T>> makeTileList(K type, Grid<T> grid) {
List<BoardElementContainer<T>> objList = new ArrayList<>(); List<BoardElementContainer<T>> objList = new ArrayList<>();
for (int y = grid.getHeight() - 1; y >= 0; y--) { 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))); objList.add(new BoardElementContainer<>(gridElement, new Position(x, y)));
} }
} else { } 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 * Kills all robots that have taken too much damage
*/ */
private void killAllHeavilyDamagedRobots() { private void killAllHeavilyDamagedRobots() {
for (Robot robot:robots.values()) { for (Robot robot : robots.values()) {
if (robot.getDamageTaken() >= 10) { if (robot.getDamageTaken() >= 10) {
killRobot(robot); killRobot(robot);
} }
@ -649,6 +686,7 @@ public class Board {
/** /**
* Fires one wall laser * Fires one wall laser
*
* @param wallLaser The wall laser being fired * @param wallLaser The wall laser being fired
*/ */
private void fireWallLaser(BoardElementContainer<Wall> wallLaser) { private void fireWallLaser(BoardElementContainer<Wall> wallLaser) {
@ -665,11 +703,12 @@ public class Board {
/** /**
* Fires one robot laser * 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 * @param robotDirection The direction the robot is facing
*/ */
private void fireRobotLaser(Position robotPosition, Direction robotDirection) { private void fireRobotLaser(Position robotPosition, Direction robotDirection) {
Position positionInFront = getNewPosition(robotPosition,robotDirection); Position positionInFront = getNewPosition(robotPosition, robotDirection);
if (!isValidPosition(positionInFront) || moveIsStoppedByWall(robotPosition, positionInFront, robotDirection)) { if (!isValidPosition(positionInFront) || moveIsStoppedByWall(robotPosition, positionInFront, robotDirection)) {
return; return;
} }
@ -685,6 +724,7 @@ public class Board {
/** /**
* Applies the damage form the laser to the robot the laser hit * Applies the damage form the laser to the robot the laser hit
*
* @param laserType The type of laser that hit the robot * @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
*/ */
@ -694,6 +734,7 @@ public class Board {
/** /**
* Gets all the positions the laser fires at * 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 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
@ -714,6 +755,7 @@ public class Board {
/** /**
* Adds any lasers in the targets list to the grid displaying lasers * 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 laserDirection The direction of the laser
* @param laserType The type of the laser * @param laserType The type of the laser
@ -726,6 +768,7 @@ public class Board {
/** /**
* Updates a laser beam on the particle grid * 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 laserDirection The direction of the beam
* @param laserType The type of the laser shooting * @param laserType The type of the laser shooting
@ -758,6 +801,7 @@ public class Board {
/** /**
* Gets the int corresponding to the flag a robot has last visited * Gets the int corresponding to the flag a robot has last visited
*
* @param robotID The robot to be checked * @param robotID The robot to be checked
* @return The flag last visited in a number * @return The flag last visited in a number
*/ */
@ -767,6 +811,7 @@ public class Board {
/** /**
* Sets a boolean for if the robot has touched a flag this turn * 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 * @param hasTouched If the robot has touched a flag this turn
*/ */
@ -776,6 +821,7 @@ public class Board {
/** /**
* Checks a boolean for if the robot has touched a flag this turn * Checks 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
* @return If the robot has touched a flag this turn * @return If the robot has touched a flag this turn
*/ */

View File

@ -4,14 +4,16 @@ import inf112.fiasko.roborally.elementproperties.Position;
/** /**
* This class represents a board element and its position * This class represents a board element and its position
*
* @param <K> The type of element * @param <K> The type of element
*/ */
public class BoardElementContainer <K> { public class BoardElementContainer<K> {
private final K element; private final K element;
private final Position position; private final Position position;
/** /**
* Initializes the BoardElementContainer * Initializes the BoardElementContainer
*
* @param element The element * @param element The element
* @param position The position * @param position The position
*/ */
@ -22,6 +24,7 @@ public class BoardElementContainer <K> {
/** /**
* Gets the element * Gets the element
*
* @return The element * @return The element
*/ */
public K getElement() { public K getElement() {
@ -30,6 +33,7 @@ public class BoardElementContainer <K> {
/** /**
* Gets the position * Gets the position
*
* @return The position * @return The position
*/ */
public Position getPosition() { public Position getPosition() {

View File

@ -1,134 +1,76 @@
package inf112.fiasko.roborally.objects; package inf112.fiasko.roborally.objects;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
/** /**
* This class represents a deck of cards * Describes a deck
*
* <p>Any card stored in the deck is assumed to be immutable. If it's not, the integrity of the deck cannot be
* guaranteed.</p>
*/ */
public abstract class Deck<T> implements IDeck<T> { public interface Deck<T> {
private final List<T> cardList;
public Deck (){
this.cardList=new ArrayList<>();
}
/**
* Initializes the deck with cards
* @param cardList list of cards
*/
public Deck (List<T> cardList) {
this.cardList = new ArrayList<>(cardList);
}
/** /**
* Randomises the order of the deck * Shuffles the order of the cards in the deck
*/ */
@Override void shuffle();
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 * @param other The deck to draw the card from
*/ */
@Override void draw(Deck<T> other);
public void draw(IDeck<T> other) {
Deck<T> otherDeck = (Deck<T>) other;
cardList.add(otherDeck.cardList.remove(0));
}
/** /**
* 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 other The other deck to draw from
* @param n The number of cards to draw * @param n The number of cards to draw
*/ */
@Override void draw(Deck<T> other, int n);
public void draw(IDeck<T> other, int n) {
Deck<T> otherDeck = (Deck<T>) 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 * Moves all cards in this deck into another deck
*
* @param other The deck to move this deck's cards into * @param other The deck to move this deck's cards into
*/ */
@Override void emptyInto(Deck<T> other);
public void emptyInto(IDeck<T> other) {
Deck<T> otherDeck = (Deck<T>) other;
otherDeck.draw(this, this.size());
}
/** /**
* Checks if the deck is empty * Whether this deck is empty
* @return Boolean for if the deck is empty *
* @return True if this deck is currently empty
*/ */
@Override boolean isEmpty();
public boolean isEmpty() {
return cardList.isEmpty();
}
/** /**
* Gets the size of the deck * Gets the number of cards currently in this deck
* @return int size of the deck *
* @return The number of cards in this deck
*/ */
@Override int size();
public int size() {
return cardList.size();
}
/** /**
* Gets a list of all the cards in the deck * Takes a peek at the card currently at the top of the deck
* @return ArrayList of cards from the deck *
* @return The card at the top of the deck
*/ */
@Override T peekTop();
public List<T> getCards() {
return new ArrayList<>(cardList);
}
/** /**
* Gets the card from the deck in String format * Takes a peek at the card currently at the bottom of the deck
* @return String the cards from the deck *
* @return The card at the bottom of the deck
*/ */
@Override T peekBottom();
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 * Gets a list of all cards in this deck
* @return ProgrammingCard the first card in the deck *
* <p>The list should have the correct order according to the actual order within the deck.</p>
*
* @return A list of all cards in this deck
*/ */
@Override List<T> getCards();
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);
}
} }

View File

@ -5,16 +5,18 @@ import java.util.List;
/** /**
* This interface describes a game drawable using libgdx * This interface describes a game drawable using libgdx
*/ */
public interface IDrawableGame { public interface DrawableGame {
/** /**
* Gets the number of tiles in the x direction * Gets the number of tiles in the x direction
*
* @return A positive integer * @return A positive integer
*/ */
int getWidth(); int getWidth();
/** /**
* Gets the number of tiles in the y direction * Gets the number of tiles in the y direction
*
* @return A positive integer * @return A positive integer
*/ */
int getHeight(); int getHeight();
@ -22,8 +24,8 @@ public interface IDrawableGame {
/** /**
* Gets a list of all the tiles to be drawn * 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 * <p>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 be drawn on the top row from left to right.</p>
* *
* @return A list of tiles * @return A list of tiles
*/ */
@ -32,8 +34,8 @@ public interface IDrawableGame {
/** /**
* Gets a list of all the walls to be drawn * 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 * <p>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 be drawn on the top row from left to right.</p>
* *
* @return A list of walls * @return A list of walls
*/ */
@ -42,8 +44,8 @@ public interface IDrawableGame {
/** /**
* Gets a list of all the particles to be drawn * 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() * <p>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. * particles should be drawn on the top row from left to right.</p>
* *
* @return A list of particles * @return A list of particles
*/ */
@ -51,6 +53,7 @@ public interface IDrawableGame {
/** /**
* Gets a list of all robots to draw * Gets a list of all robots to draw
*
* @return A list of all robots to draw * @return A list of all robots to draw
*/ */
List<Robot> getRobotsToDraw(); List<Robot> getRobotsToDraw();

View File

@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
/** /**
* This class represents an object that can be drawn using libgdx * 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 TextureRegion texture;
private final int xPos; private final int xPos;
private final int yPos; private final int yPos;
@ -17,6 +17,7 @@ public class DrawableObject implements IDrawableObject {
/** /**
* Initializes a drawable object * Initializes a drawable object
*
* @param texture The texture to use for drawing 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 xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y axis * @param yPos The pixel to start drawing on for the y axis
@ -40,6 +41,7 @@ public class DrawableObject implements IDrawableObject {
/** /**
* Initializes a drawable object * Initializes a drawable object
*
* @param texture The texture to use for drawing 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 xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y axis * @param yPos The pixel to start drawing on for the y axis
@ -58,6 +60,7 @@ public class DrawableObject implements IDrawableObject {
/** /**
* Initializes a new drawable object * Initializes a new drawable object
*
* @param texture The texture to use for drawing 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 xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y axis * @param yPos The pixel to start drawing on for the y axis
@ -68,42 +71,80 @@ public class DrawableObject implements IDrawableObject {
this.texture = texture; this.texture = texture;
} }
@Override /**
* Gets the texture to use for drawing the object
*
* @return The texture of the object
*/
public TextureRegion getTexture() { public TextureRegion getTexture() {
return texture; return texture;
} }
@Override /**
* Gets the x position the object should be drawn on
*
* <p>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).</p>
*
* @return An x position libgdx
*/
public int getXPosition() { public int getXPosition() {
return xPos; return xPos;
} }
@Override /**
* Gets the y position the object should be drawn on
*
* <p>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).</p>
*
* @return An x position libgdx
*/
public int getYPosition() { public int getYPosition() {
return yPos; return yPos;
} }
@Override /**
* Gets the width of the object
*
* @return A positive integer
*/
public int getWidth() { public int getWidth() {
return width; return width;
} }
@Override /**
* Gets the height of the object
*
* @return A positive integer
*/
public int getHeight() { public int getHeight() {
return height; return height;
} }
@Override /**
* Gets the number of degrees to rotate the texture counterclockwise when rendering
*
* @return An integer
*/
public int getRotation() { public int getRotation() {
return rotation; 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() { public boolean flipX() {
return 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() { public boolean flipY() {
return flipY; return flipY;
} }

View File

@ -1,83 +1,42 @@
package inf112.fiasko.roborally.objects; package inf112.fiasko.roborally.objects;
import java.util.ArrayList;
import java.util.List;
/** /**
* This class represents a grid which can store anything * This Interface describes a grid
* @param <K> The type of element the grid should store *
* @param <K> The type of element the grid is to store
*/ */
public class Grid<K> implements IGrid<K> { public interface Grid<K> {
private final int height;
private final int width;
private final List<ArrayList<K>> grid = new ArrayList<>();
/** /**
* Initializes an empty grid * Gets the width of the grid
* @param width The width of the grid *
* @param height The height of the grid * @return The width of the grid
*/ */
public Grid(int width, int height) { int getWidth();
this.width = width;
this.height = height;
for (int y = 0; y < height; y++) {
ArrayList<K> row = new ArrayList<>();
for(int x = 0; x < width; x++) {
row.add(null);
}
this.grid.add(row);
}
}
/** /**
* Initializes a grid filled with standard tiles. * Gets height of the grid
* @param height sets the height of the grid *
* @param width sets the width of the grid * @return The height of the grid
* @param tile gives the TileType the grid is to be filled with
*/ */
public Grid(int width, int height, K tile) { int getHeight();
this.width = width;
this.height = height;
for (int y = 0; y < height; y++) {
ArrayList<K> 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 * Gets the element in a given x and y coordinate
* @param x The x coordinate to check *
* @param y The y coordinate to check * @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) { K getElement(int x, int y) throws IllegalArgumentException;
if (x < 0 || x >= width || y < 0 || y >= height) {
throw new IllegalArgumentException("Coordinates are outside the bounds of the board."); /**
} * 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;
} }

View File

@ -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 <T> {
/**
* 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<T> 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<T> 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<T> 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<T> getCards();
}

View File

@ -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();
}

View File

@ -1,37 +0,0 @@
package inf112.fiasko.roborally.objects;
/**
* This Interface describes a grid
* @param <K> The type of element the grid is to store
*/
public interface IGrid<K> {
/**
* 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;
}

View File

@ -1,3 +0,0 @@
package inf112.fiasko.roborally.objects;
public interface IRoboRallyGame extends IDrawableGame, IInteractableGame {}

View File

@ -1,7 +1,7 @@
package inf112.fiasko.roborally.objects; package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.elementproperties.GameState; 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 inf112.fiasko.roborally.networking.containers.ProgamsContainer;
import java.util.List; import java.util.List;
@ -9,27 +9,31 @@ import java.util.List;
/** /**
* This interface describes * This interface describes
*/ */
public interface IInteractableGame { public interface InteractableGame {
/** /**
* Gets the current state og the game * Gets the current state og the game
*
* @return The state the game is currently in * @return The state the game is currently in
*/ */
GameState getGameState(); GameState getGameState();
/** /**
* Sets the state of the game * Sets the state of the game
*
* @param gameState The new state of the game * @param gameState The new state of the game
*/ */
void setGameState(GameState gameState); void setGameState(GameState gameState);
/** /**
* Gets the name of the player who won * Gets the name of the player who won
*
* @return A string of the player name * @return A string of the player name
*/ */
String getWinningPlayerName(); String getWinningPlayerName();
/** /**
* Continues turn when programs for all players are received from the server * Continues turn when programs for all players are received from the server
*
* @param programs The programs container received from the server * @param programs The programs container received from the server
* @throws InterruptedException If interrupted during sleep * @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 * Continues turn when stay in power down is received from all players
*
* @param powerDowns The power down container received from the server * @param powerDowns The power down container received from the server
*/ */
void receiveStayInPowerDown(PowerdownContainer powerDowns); void receiveStayInPowerDown(PowerDownContainer powerDowns);
/** /**
* Gets the hand of this player * Gets the hand of this player
*
* @return The hand of this player * @return The hand of this player
*/ */
ProgrammingCardDeck getPlayerHand(); ProgrammingCardDeck getPlayerHand();
/** /**
* Sets the hand of this player * Sets the hand of this player
*
* @param playerHand The new hand of this player * @param playerHand The new hand of this player
*/ */
void setPlayerHand(ProgrammingCardDeck playerHand); void setPlayerHand(ProgrammingCardDeck playerHand);
/** /**
* Gets the amount of cards the player can choose for their program * Gets the amount of cards the player can choose for their program
*
* @return The size of the player's next program * @return The size of the player's next program
*/ */
int getProgramSize(); int getProgramSize();
/** /**
* Gets the program of this player * Gets the program of this player
*
* @return The program of this player * @return The program of this player
*/ */
List<ProgrammingCard> getProgram(); List<ProgrammingCard> getProgram();
/** /**
* Sets the program of this player * Sets the program of this player
*
* @param program The program of this player * @param program The program of this player
*/ */
void setProgram(List<ProgrammingCard> program); void setProgram(List<ProgrammingCard> program);

View File

@ -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 <K> The type of element the grid should store
*/
public class ListGrid<K> implements Grid<K> {
private final int height;
private final int width;
private final List<ArrayList<K>> 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<K> 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<K> 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.");
}
}
}

View File

@ -13,6 +13,7 @@ public class Particle {
/** /**
* Instantiates a new particle * Instantiates a new particle
*
* @param particleType The type of the particle * @param particleType The type of the particle
* @param direction The direction of the particle * @param direction The direction of the particle
*/ */
@ -26,6 +27,7 @@ public class Particle {
/** /**
* Gets the particle type of the particle * Gets the particle type of the particle
*
* @return The particle's particle type * @return The particle's particle type
*/ */
public ParticleType getParticleType() { public ParticleType getParticleType() {
@ -34,6 +36,7 @@ public class Particle {
/** /**
* Gets the direction of the particle * Gets the direction of the particle
*
* @return The particle's direction * @return The particle's direction
*/ */
public Direction getDirection() { public Direction getDirection() {

View File

@ -1,8 +1,17 @@
package inf112.fiasko.roborally.objects; 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; import java.util.concurrent.TimeUnit;
/** /**
@ -20,6 +29,7 @@ public class Phase {
/** /**
* Instantiates a new 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 playerList A list of players participating in the game
* @param cycleDelay The amount of milliseconds to wait between moves * @param cycleDelay The amount of milliseconds to wait between moves
@ -35,6 +45,7 @@ public class Phase {
/** /**
* Runs one phase as defined in the Robo Rally rulebook * Runs one phase as defined in the Robo Rally rulebook
*
* @param phaseNumber The number of the phase to run * @param phaseNumber The number of the phase to run
* @throws InterruptedException If interrupted wile trying to sleep * @throws InterruptedException If interrupted wile trying to sleep
*/ */
@ -62,7 +73,7 @@ public class Phase {
continue; continue;
} }
gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType()); gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
gameBoard.setHasTouchedFlagThisTurnFromRobotID(robotID,true); gameBoard.setHasTouchedFlagThisTurnFromRobotID(robotID, true);
checkIfPlayerWon(robotID, flags.size()); checkIfPlayerWon(robotID, flags.size());
} }
} }
@ -78,6 +89,7 @@ public class Phase {
/** /**
* Runs all programming cards for a phase * Runs all programming cards for a phase
*
* @param phase The number of the phase to run cards for * @param phase The number of the phase to run cards for
* @throws InterruptedException If it gets interrupted while trying to sleep * @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. * Rotates all robots that are standing on cogWheel tiles on the board.
*
* @throws InterruptedException If interrupted while sleeping. * @throws InterruptedException If interrupted while sleeping.
*/ */
public void rotateCogwheels() throws InterruptedException { 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 * 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 * <p>In addition, the function rotates appropriately when arriving at any non-straight conveyor belt.</p>
* *
* @throws InterruptedException If disturbed during sleep * @throws InterruptedException If disturbed during sleep
*/ */
@ -136,6 +149,7 @@ public class Phase {
/** /**
* Makes the given robot move according to to the action input. * Makes the given robot move according to to the action input.
*
* @param robotID The ID of the robot to move. * @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. * @throws InterruptedException If interrupted wile trying to sleep.
@ -178,6 +192,7 @@ public class Phase {
/** /**
* Checks if the player won, and shows the victory screen * 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 * @param numberOfFlags The number of flags on the map
*/ */
@ -197,6 +212,7 @@ public class Phase {
/** /**
* Checks whether a player has won * Checks whether a player has won
*
* @param lastFlagVisited The last flag the player visited * @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 * @return True if the player has visited the last flag
@ -207,6 +223,7 @@ public class Phase {
/** /**
* Moves a list of conveyor belts * Moves a list of conveyor belts
*
* @param conveyorBelts A list of board element containers containing conveyor belts * @param conveyorBelts A list of board element containers containing conveyor belts
*/ */
private void moveConveyorBelts(List<BoardElementContainer<Tile>> conveyorBelts) { private void moveConveyorBelts(List<BoardElementContainer<Tile>> conveyorBelts) {
@ -239,6 +256,7 @@ public class Phase {
/** /**
* Updates maps containing information about what a robot on a conveyor belt should do * 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 conveyorBeltDirection The direction of the conveyor belt the robot stands on
* @param newPositions The map containing new positions for robots * @param newPositions The map containing new positions for robots
@ -265,6 +283,7 @@ public class Phase {
/** /**
* Helper method for makeMove. Takes care of movement forward of given robot. * Helper method for makeMove. Takes care of movement forward of given robot.
*
* @param robotID ID of the given robot. * @param robotID ID of the given robot.
* @throws InterruptedException If interrupted wile sleeping. * @throws InterruptedException If interrupted wile sleeping.
*/ */
@ -278,6 +297,7 @@ public class Phase {
/** /**
* Makes the game thread wait a given time amount before continuing. * Makes the game thread wait a given time amount before continuing.
*
* @throws InterruptedException If interrupted while trying to sleep. * @throws InterruptedException If interrupted while trying to sleep.
*/ */
private void sleep() throws InterruptedException { private void sleep() throws InterruptedException {

View File

@ -14,10 +14,11 @@ public class Player {
private boolean powerDownNextRound = false; private boolean powerDownNextRound = false;
private ProgrammingCardDeck playerDeck; private ProgrammingCardDeck playerDeck;
private ProgrammingCardDeck lockedPlayerDeck; private ProgrammingCardDeck lockedPlayerDeck;
private List <ProgrammingCard> program; private List<ProgrammingCard> program;
/** /**
* Instantiates a new player * Instantiates a new player
*
* @param robotID the global identifier of the robot * @param robotID the global identifier of the robot
* @param name the unique name of the player * @param name the unique name of the player
*/ */
@ -31,26 +32,12 @@ public class Player {
/** /**
* Empty constructor required by kryo * Empty constructor required by kryo
*/ */
public Player(){} 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;
} }
/** /**
* Gives you the RobotID of a player * Gives you the RobotID of a player
*
* @return A RobotID * @return A RobotID
*/ */
public RobotID getRobotID() { public RobotID getRobotID() {
@ -58,23 +45,35 @@ public class Player {
} }
/** /**
* Set the players deck to the given deck * Sets the robot id of the robot
* @param playerDeck A deck of cards given to the player *
* @param robotID The new id of the robot
*/ */
public void setPlayerDeck(ProgrammingCardDeck playerDeck) { public void setRobotID(RobotID robotID) {
this.playerDeck = playerDeck; this.robotID = robotID;
} }
/** /**
* Gives you the Name of the player * Gives you the Name of the player
*
* @return A player Name * @return A player Name
*/ */
public String getName() { public String getName() {
return name; 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 * Gives you the players program
*
* @return A list of programming cards * @return A list of programming cards
*/ */
public List<ProgrammingCard> getProgram() { public List<ProgrammingCard> getProgram() {
@ -83,14 +82,25 @@ public class Player {
/** /**
* Gives you the player hand/deck * Gives you the player hand/deck
*
* @return a deck * @return a deck
*/ */
public ProgrammingCardDeck getPlayerDeck() { public ProgrammingCardDeck getPlayerDeck() {
return playerDeck; 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 * Gives you the player deck with locked cards
*
* @return a deck with locked cards * @return a deck with locked cards
*/ */
public ProgrammingCardDeck getLockedPlayerDeck() { public ProgrammingCardDeck getLockedPlayerDeck() {
@ -99,6 +109,7 @@ public class Player {
/** /**
* Set the players locked deck to the given deck * Set the players locked deck to the given deck
*
* @param lockedPlayerDeck A deck of locked cards kept by the player * @param lockedPlayerDeck A deck of locked cards kept by the player
*/ */
public void setLockedPlayerDeck(ProgrammingCardDeck lockedPlayerDeck) { public void setLockedPlayerDeck(ProgrammingCardDeck lockedPlayerDeck) {
@ -107,6 +118,7 @@ public class Player {
/** /**
* Gives you the players power down status * Gives you the players power down status
*
* @return Whether the player is to power down * @return Whether the player is to power down
*/ */
public boolean getPowerDownNextRound() { public boolean getPowerDownNextRound() {
@ -115,6 +127,7 @@ public class Player {
/** /**
* Sets the power down status * Sets the power down status
*
* @param powerDownStatus Whether the player is to take power down next round * @param powerDownStatus Whether the player is to take power down next round
*/ */
public void setPowerDownNextRound(boolean powerDownStatus) { public void setPowerDownNextRound(boolean powerDownStatus) {
@ -123,9 +136,10 @@ public class Player {
/** /**
* Sets the Players program to the given list of programing cards * Sets the Players program to the given list of programing cards
*
* @param cardList list the size of 5 with programing cards * @param cardList list the size of 5 with programing cards
*/ */
public void setInProgram(List <ProgrammingCard> cardList) { public void setInProgram(List<ProgrammingCard> cardList) {
if (cardList.size() != 5) { if (cardList.size() != 5) {
throw new IllegalArgumentException("list must contain 5 programing cards"); throw new IllegalArgumentException("list must contain 5 programing cards");
} else { } else {

View File

@ -12,6 +12,7 @@ public class ProgrammingCard implements Comparable<ProgrammingCard> {
/** /**
* Initializes the priority and the action of the card * Initializes the priority and the action of the card
*
* @param cardPriority the priority of the card * @param cardPriority the priority of the card
* @param cardAction the action of the card * @param cardAction the action of the card
*/ */
@ -20,12 +21,13 @@ public class ProgrammingCard implements Comparable<ProgrammingCard> {
this.cardAction = cardAction; this.cardAction = cardAction;
} }
public ProgrammingCard(){ public ProgrammingCard() {
} }
/** /**
* Gets the priority of the programming card * Gets the priority of the programming card
*
* @return The programming card priority * @return The programming card priority
*/ */
public int getPriority() { public int getPriority() {
@ -34,6 +36,7 @@ public class ProgrammingCard implements Comparable<ProgrammingCard> {
/** /**
* Gets the action of the programming card * Gets the action of the programming card
*
* @return The programming card action * @return The programming card action
*/ */
public Action getAction() { public Action getAction() {

View File

@ -5,14 +5,17 @@ import java.util.List;
/** /**
* This class represents a deck containing programming cards * This class represents a deck containing programming cards
*/ */
public class ProgrammingCardDeck extends Deck<ProgrammingCard> { public class ProgrammingCardDeck extends AbstractDeck<ProgrammingCard> {
/** /**
* Initializes the PlayerDeck with a list of cards * Initializes the PlayerDeck with a list of cards
*
* @param cardList list of programing cards * @param cardList list of programing cards
*/ */
public ProgrammingCardDeck(List<ProgrammingCard> cardList) { public ProgrammingCardDeck(List<ProgrammingCard> cardList) {
super(cardList); super(cardList);
} }
public ProgrammingCardDeck(){}
public ProgrammingCardDeck() {
}
} }

View File

@ -7,7 +7,7 @@ import inf112.fiasko.roborally.elementproperties.RobotID;
import inf112.fiasko.roborally.elementproperties.TileType; import inf112.fiasko.roborally.elementproperties.TileType;
import inf112.fiasko.roborally.networking.RoboRallyClient; import inf112.fiasko.roborally.networking.RoboRallyClient;
import inf112.fiasko.roborally.networking.RoboRallyServer; 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.networking.containers.ProgamsContainer;
import inf112.fiasko.roborally.utility.BoardLoaderUtil; import inf112.fiasko.roborally.utility.BoardLoaderUtil;
import inf112.fiasko.roborally.utility.DeckLoaderUtil; import inf112.fiasko.roborally.utility.DeckLoaderUtil;
@ -20,16 +20,15 @@ import java.util.Map;
/** /**
* This class represent a game which is drawable using libgdx * This class represent a game which is drawable using libgdx
*/ */
public class RoboRallyGame implements IRoboRallyGame { public class RoboRallyGame implements DrawableGame, InteractableGame {
private Board gameBoard;
private List<BoardElementContainer<Tile>> repairTiles;
private final List<Player> playerList; private final List<Player> playerList;
private final boolean host; private final boolean host;
private final String playerName;
private final RoboRallyServer server;
private Board gameBoard;
private List<BoardElementContainer<Tile>> repairTiles;
private Deck<ProgrammingCard> mainDeck; private Deck<ProgrammingCard> mainDeck;
private GameState gameState = GameState.BEGINNING_OF_GAME; private GameState gameState = GameState.BEGINNING_OF_GAME;
private final String playerName;
private final RoboRallyClient client;
private final RoboRallyServer server;
private String winningPlayerName; private String winningPlayerName;
private List<ProgrammingCard> program; private List<ProgrammingCard> program;
private ProgrammingCardDeck playerHand; private ProgrammingCardDeck playerHand;
@ -37,20 +36,19 @@ public class RoboRallyGame implements IRoboRallyGame {
/** /**
* Instantiates a new Robo Rally game * Instantiates a new Robo Rally game
*
* @param playerList A list of all the players participating in the game * @param playerList A list of all the players participating in the game
* @param boardName The playerName of the board to use * @param boardName The playerName of the board to use
* @param host Whether this player is the host * @param host Whether this player is the host
* @param playerName The name of the player of this instance of the game * @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
* @param debug Whether this game is to use the debugging board * @param debug Whether this game is to use the debugging board
*/ */
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName, public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName,
RoboRallyClient client, RoboRallyServer server, boolean debug) { RoboRallyServer server, boolean debug) {
this.playerName = playerName; this.playerName = playerName;
this.host = host; this.host = host;
this.playerList = playerList; this.playerList = playerList;
this.client = client;
this.server = server; this.server = server;
if (debug) { if (debug) {
initializeDebugMode(); initializeDebugMode();
@ -62,19 +60,18 @@ public class RoboRallyGame implements IRoboRallyGame {
/** /**
* Instantiates a new Robo Rally game * Instantiates a new Robo Rally game
*
* @param playerList A list of all the players participating in the game * @param playerList A list of all the players participating in the game
* @param boardName The playerName of the board to use * @param boardName The playerName of the board to use
* @param host Whether this player is the host * @param host Whether this player is the host
* @param playerName The name of the player of this instance of the game * @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<Player> playerList, String boardName, boolean host, String playerName, public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName,
RoboRallyClient client, RoboRallyServer server) { RoboRallyServer server) {
this.playerName = playerName; this.playerName = playerName;
this.host = host; this.host = host;
this.playerList = playerList; this.playerList = playerList;
this.client = client;
this.server = server; this.server = server;
initializeGame(boardName); initializeGame(boardName);
this.phase = new Phase(gameBoard, playerList, 600, this); this.phase = new Phase(gameBoard, playerList, 600, this);
@ -111,7 +108,7 @@ public class RoboRallyGame implements IRoboRallyGame {
} }
@Override @Override
public GameState getGameState(){ public GameState getGameState() {
return gameState; return gameState;
} }
@ -135,6 +132,11 @@ public class RoboRallyGame implements IRoboRallyGame {
return program; return program;
} }
@Override
public void setProgram(List<ProgrammingCard> program) {
this.program = program;
}
@Override @Override
public int getProgramSize() { public int getProgramSize() {
Player player = getPlayerFromName(playerName); Player player = getPlayerFromName(playerName);
@ -144,11 +146,6 @@ public class RoboRallyGame implements IRoboRallyGame {
return -1; return -1;
} }
@Override
public void setProgram(List<ProgrammingCard> program) {
this.program = program;
}
@Override @Override
public void receiveAllPrograms(ProgamsContainer programs) throws InterruptedException { public void receiveAllPrograms(ProgamsContainer programs) throws InterruptedException {
//Reads data from server and updates player objects //Reads data from server and updates player objects
@ -181,7 +178,7 @@ public class RoboRallyGame implements IRoboRallyGame {
} }
@Override @Override
public void receiveStayInPowerDown(PowerdownContainer powerDowns) { public void receiveStayInPowerDown(PowerDownContainer powerDowns) {
for (Player player : playerList) { for (Player player : playerList) {
player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName())); 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 * Gets the name of the player that won the game
*
* @return The name of the winning player * @return The name of the winning player
*/ */
public String getWinningPlayerName() { public String getWinningPlayerName() {
return winningPlayerName; 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 * Initializes the game with a debugging board
*/ */
@ -225,7 +232,7 @@ public class RoboRallyGame implements IRoboRallyGame {
List<Robot> robots = new ArrayList<>(); List<Robot> robots = new ArrayList<>();
int posX = 1; int posX = 1;
for (Player player : playerList) { for (Player player : playerList) {
Position spawn = new Position(posX,1); Position spawn = new Position(posX, 1);
robots.add(new Robot(player.getRobotID(), spawn)); robots.add(new Robot(player.getRobotID(), spawn));
posX++; posX++;
} }
@ -333,6 +340,7 @@ public class RoboRallyGame implements IRoboRallyGame {
/** /**
* Moves a card from the player's deck to the player's locked deck if found * 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 card The card to move to the locked deck
* @param playerDeck The deck containing the player's cards * @param playerDeck The deck containing the player's cards
* @param lockedPlayerDeck The deck containing the player's locked cards * @param lockedPlayerDeck The deck containing the player's locked cards
@ -378,18 +386,10 @@ public class RoboRallyGame implements IRoboRallyGame {
throw new IllegalStateException("Player deck must be empty when dealing new cards!"); throw new IllegalStateException("Player deck must be empty when dealing new cards!");
} }
//Gives the player the correct amount of 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 * Respawn all the dead robots with more lives and places them on the game board
*/ */
@ -422,6 +422,7 @@ public class RoboRallyGame implements IRoboRallyGame {
/** /**
* Sets the power down status of a robot * 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 * @param powerDownStatus The new power down status
*/ */
@ -431,6 +432,7 @@ public class RoboRallyGame implements IRoboRallyGame {
/** /**
* Gets a player object given a player name * Gets a player object given a player name
*
* @param name The name of the player to get * @param name The name of the player to get
* @return The corresponding player object or null if no such object exists * @return The corresponding player object or null if no such object exists
*/ */

View File

@ -8,9 +8,9 @@ import inf112.fiasko.roborally.elementproperties.RobotID;
* This class represents a robot * This class represents a robot
*/ */
public class Robot { public class Robot {
private final RobotID robotId;
private int amountOfLives = 3; private int amountOfLives = 3;
private int robotDamageTaken = 0; private int robotDamageTaken = 0;
private final RobotID robotId;
private boolean inPowerDown = false; private boolean inPowerDown = false;
private int lastFlagVisited = 0; private int lastFlagVisited = 0;
private Position backupPosition; private Position backupPosition;
@ -20,10 +20,11 @@ public class Robot {
/** /**
* Instantiates a new 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 * @param spawnPosition The starting position of the robot
*/ */
public Robot (RobotID robotId, Position spawnPosition) { public Robot(RobotID robotId, Position spawnPosition) {
this.robotId = robotId; this.robotId = robotId;
this.backupPosition = spawnPosition; this.backupPosition = spawnPosition;
this.currentPosition = spawnPosition; this.currentPosition = spawnPosition;
@ -32,6 +33,7 @@ public class Robot {
/** /**
* True if the robot has touched a flag in the current turn * True if the robot has touched a flag in the current turn
*
* @return a boolean * @return a boolean
*/ */
public boolean isHasTouchedFlagThisTurn() { 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, * Sets the boolean value to true if the robot touches a flag during a turn,
* and false at the end of each turn. * and false at the end of each turn.
*
* @param hasTouchedFlagThisTurn the boolean value to be set. * @param hasTouchedFlagThisTurn the boolean value to be set.
*/ */
public void setHasTouchedFlagThisTurn(boolean hasTouchedFlagThisTurn) { public void setHasTouchedFlagThisTurn(boolean hasTouchedFlagThisTurn) {
@ -49,6 +52,7 @@ public class Robot {
/** /**
* Gets the damage the robot has taken * Gets the damage the robot has taken
*
* @return The amount of damage the robot has received * @return The amount of damage the robot has received
*/ */
public int getDamageTaken() { public int getDamageTaken() {
@ -57,6 +61,7 @@ public class Robot {
/** /**
* Sets the robot's taken damage to a given amount * Sets the robot's taken damage to a given amount
*
* @param damage The amount of damage the robot has received * @param damage The amount of damage the robot has received
*/ */
public void setDamageTaken(int damage) { public void setDamageTaken(int damage) {
@ -65,6 +70,7 @@ public class Robot {
/** /**
* Gets the robot's current position on the board * Gets the robot's current position on the board
*
* @return The robot's current position * @return The robot's current position
*/ */
public Position getPosition() { public Position getPosition() {
@ -73,14 +79,16 @@ public class Robot {
/** /**
* Sets the robot's current position on the board * Sets the robot's current position on the board
*
* @param newPosition The new position of the robot * @param newPosition The new position of the robot
*/ */
public void setPosition( Position newPosition ) { public void setPosition(Position newPosition) {
this.currentPosition = newPosition; this.currentPosition = newPosition;
} }
/** /**
* Sets power-down status * Sets power-down status
*
* @param powerDownStatus Whether the robot is currently in power-down * @param powerDownStatus Whether the robot is currently in power-down
*/ */
public void setPowerDown(Boolean powerDownStatus) { public void setPowerDown(Boolean powerDownStatus) {
@ -89,6 +97,7 @@ public class Robot {
/** /**
* Gets the robot's power-down status * Gets the robot's power-down status
*
* @return Whether the robot is currently in power-down * @return Whether the robot is currently in power-down
*/ */
public Boolean isInPowerDown() { 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 * 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 * @param currentFlag The flag the robot is standing on
*/ */
public void setLastFlagVisitedAndUpdateBackupPosition(int currentFlag) { public void setLastFlagVisitedAndUpdateBackupPosition(int currentFlag) {
@ -109,6 +119,7 @@ public class Robot {
/** /**
* Gets the last flag the robot visited * Gets the last flag the robot visited
*
* @return Last visited flag * @return Last visited flag
*/ */
public int getLastFlagVisited() { public int getLastFlagVisited() {
@ -117,6 +128,7 @@ public class Robot {
/** /**
* Gets the robot's backup position * Gets the robot's backup position
*
* @return The robot's backup position * @return The robot's backup position
*/ */
public Position getBackupPosition() { public Position getBackupPosition() {
@ -125,6 +137,7 @@ public class Robot {
/** /**
* Gets the robot ID * Gets the robot ID
*
* @return Robot ID * @return Robot ID
*/ */
public RobotID getRobotId() { public RobotID getRobotId() {
@ -133,6 +146,7 @@ public class Robot {
/** /**
* Gets the direction the robot is currently facing * Gets the direction the robot is currently facing
*
* @return The direction the robot is facing * @return The direction the robot is facing
*/ */
public Direction getFacingDirection() { public Direction getFacingDirection() {
@ -141,6 +155,7 @@ public class Robot {
/** /**
* Sets the direction the robot is currently facing * Sets the direction the robot is currently facing
*
* @param newFacingDirection The new direction the robot should be facing * @param newFacingDirection The new direction the robot should be facing
*/ */
public void setFacingDirection(Direction newFacingDirection) { public void setFacingDirection(Direction newFacingDirection) {
@ -150,24 +165,27 @@ public class Robot {
this.facingDirection = newFacingDirection; 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. * Gets the amount of life a robot has left.
*
* @return amount of life left * @return amount of life left
*/ */
public int getAmountOfLives() { public int getAmountOfLives() {
return this.amountOfLives; 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 * Makes a copy of this robot with the same properties as this robot
*
* @return A copy of this robot * @return A copy of this robot
*/ */
public Robot copy() { public Robot copy() {

View File

@ -13,6 +13,7 @@ public class Tile {
/** /**
* Instantiates a new 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 * @param direction The direction of the tile
*/ */
@ -26,6 +27,7 @@ public class Tile {
/** /**
* Gets the tile type of the tile * Gets the tile type of the tile
*
* @return The tile's tile type * @return The tile's tile type
*/ */
public TileType getTileType() { public TileType getTileType() {
@ -34,6 +36,7 @@ public class Tile {
/** /**
* Gets the direction of the tile * Gets the direction of the tile
*
* @return The tile's direction * @return The tile's direction
*/ */
public Direction getDirection() { public Direction getDirection() {

View File

@ -12,10 +12,11 @@ public class Wall {
/** /**
* Initializes a 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 * @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) { if (direction.getDirectionID() % 2 == 0 && wallType != WallType.WALL_CORNER) {
throw new IllegalArgumentException("Invalid direction for wall type submitted"); throw new IllegalArgumentException("Invalid direction for wall type submitted");
} }
@ -25,6 +26,7 @@ public class Wall {
/** /**
* Gets the type of the wall * Gets the type of the wall
*
* @return The wall type * @return The wall type
*/ */
public WallType getWallType() { public WallType getWallType() {
@ -33,6 +35,7 @@ public class Wall {
/** /**
* Gets the direction of the wall * Gets the direction of the wall
*
* @return The direction of the wall * @return The direction of the wall
*/ */
public Direction getDirection() { public Direction getDirection() {

View File

@ -29,6 +29,7 @@ import org.junit.runners.model.InitializationError;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.ApplicationListener;

View File

@ -11,7 +11,7 @@ public class BoardElementContainerTest {
@Test @Test
public void getObjectTest() { public void getObjectTest() {
Position pos = new Position(1,2); Position pos = new Position(1, 2);
Tile tile = new Tile(TileType.TILE, Direction.NORTH); Tile tile = new Tile(TileType.TILE, Direction.NORTH);
BoardElementContainer<Tile> element = new BoardElementContainer<>(tile, pos); BoardElementContainer<Tile> element = new BoardElementContainer<>(tile, pos);
assertEquals(tile, element.getElement()); assertEquals(tile, element.getElement());
@ -19,7 +19,7 @@ public class BoardElementContainerTest {
@Test @Test
public void getPositionTest() { public void getPositionTest() {
Position pos = new Position(1,2); Position pos = new Position(1, 2);
Tile tile = new Tile(TileType.TILE, Direction.NORTH); Tile tile = new Tile(TileType.TILE, Direction.NORTH);
BoardElementContainer<Tile> element = new BoardElementContainer<>(tile, pos); BoardElementContainer<Tile> element = new BoardElementContainer<>(tile, pos);
assertEquals(pos, element.getPosition()); assertEquals(pos, element.getPosition());

View File

@ -21,8 +21,6 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class BoardTest { public class BoardTest {
private Grid<Tile> tileGrid;
private Grid<Wall> wallGrid;
private static Position zeroPosition; private static Position zeroPosition;
private static Position someValidPosition1; private static Position someValidPosition1;
private static Position someValidPosition2; private static Position someValidPosition2;
@ -32,11 +30,13 @@ public class BoardTest {
private static Position someValidPosition6; private static Position someValidPosition6;
private static Position someValidPosition7; private static Position someValidPosition7;
private static Position someValidPosition8; private static Position someValidPosition8;
private final Map<WallType, Integer> wallTypeNumberMap = new HashMap<>();
private final Map<TileType, Integer> tileTypeNumberMap = new HashMap<>();
private Grid<Tile> tileGrid;
private Grid<Wall> wallGrid;
private List<Robot> robotList; private List<Robot> robotList;
private Board board; private Board board;
private Board boardWithDifferentAmountOfAllTypes; private Board boardWithDifferentAmountOfAllTypes;
private final Map<WallType,Integer> wallTypeNumberMap = new HashMap<>();
private final Map<TileType,Integer> tileTypeNumberMap = new HashMap<>();
private List<Robot> robotListforlaser; private List<Robot> robotListforlaser;
private Board boardforlaser; private Board boardforlaser;
private List<Robot> robotListforpowerdown; private List<Robot> robotListforpowerdown;
@ -58,30 +58,30 @@ public class BoardTest {
@Before @Before
public void setUp() { public void setUp() {
Grid<Tile> tileGridforpowerdown = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH)); Grid<Tile> tileGridforpowerdown = new ListGrid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH));
Grid<Wall> wallGridforpowerdown = new Grid<>(8, 8); Grid<Wall> wallGridforpowerdown = new ListGrid<>(8, 8);
robotListforpowerdown = new ArrayList<>(); robotListforpowerdown = new ArrayList<>();
robotListforpowerdown.add(new Robot(RobotID.ROBOT_1, new Position(2,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_2, new Position(4, 0)));
robotListforpowerdown.add(new Robot(RobotID.ROBOT_3, new Position(4,1))); 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_4, new Position(1, 7)));
robotListforpowerdown.add(new Robot(RobotID.ROBOT_5, new Position(0,4))); 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_6, new Position(0, 5)));
robotListforpowerdown.add(new Robot(RobotID.ROBOT_7, new Position(7,0))); 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_8, new Position(1, 1)));
boardforpowerdown = new Board(tileGridforpowerdown, wallGridforpowerdown, robotListforpowerdown); boardforpowerdown = new Board(tileGridforpowerdown, wallGridforpowerdown, robotListforpowerdown);
Grid<Tile> tileGridforlaser = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH)); Grid<Tile> tileGridforlaser = new ListGrid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH));
Grid<Wall> wallGridforlaser = new Grid<>(8, 8); Grid<Wall> wallGridforlaser = new ListGrid<>(8, 8);
robotListforlaser = new ArrayList<>(); robotListforlaser = new ArrayList<>();
robotListforlaser.add(new Robot(RobotID.ROBOT_1, new Position(2,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_2, new Position(4, 0)));
robotListforlaser.add(new Robot(RobotID.ROBOT_3, new Position(4,1))); 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_4, new Position(1, 7)));
robotListforlaser.add(new Robot(RobotID.ROBOT_5, new Position(0,4))); 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_6, new Position(0, 5)));
robotListforlaser.add(new Robot(RobotID.ROBOT_7, new Position(7,0))); 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_8, new Position(1, 1)));
wallGridforlaser.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); 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(1, 3, new Wall(WallType.WALL_LASER_SINGLE, Direction.SOUTH));
wallGridforlaser.setElement(7, 4, new Wall(WallType.WALL_LASER_DOUBLE, 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)); wallGridforlaser.setElement(0, 5, new Wall(WallType.WALL_LASER_SINGLE, Direction.SOUTH));
boardforlaser = new Board(tileGridforlaser, wallGridforlaser, robotListforlaser); boardforlaser = new Board(tileGridforlaser, wallGridforlaser, robotListforlaser);
tileGrid = new Grid<>(5, 5, new Tile(TileType.TILE, Direction.NORTH)); tileGrid = new ListGrid<>(5, 5, new Tile(TileType.TILE, Direction.NORTH));
wallGrid = new Grid<>(5, 5); wallGrid = new ListGrid<>(5, 5);
robotList = new ArrayList<>(); robotList = new ArrayList<>();
robotList.add(new Robot(RobotID.ROBOT_1, someValidPosition1)); robotList.add(new Robot(RobotID.ROBOT_1, someValidPosition1));
robotList.add(new Robot(RobotID.ROBOT_2, someValidPosition2)); 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, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH));
wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST)); wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST));
wallGrid.setElement(1, 2, new Wall(WallType.WALL_CORNER, Direction.NORTH_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(3, 3, new Tile(TileType.FLAG_1, Direction.NORTH));
tileGrid.setElement(2,2, new Tile(TileType.FLAG_2, Direction.NORTH)); tileGrid.setElement(2, 2, new Tile(TileType.FLAG_2, Direction.NORTH));
board = new Board(tileGrid, wallGrid, robotList); board = new Board(tileGrid, wallGrid, robotList);
Grid<Tile> tileGridAllTypes = new Grid<>(6,6); Grid<Tile> tileGridAllTypes = new ListGrid<>(6, 6);
Grid<Wall> wallGridAllTypes = new Grid<>(6,6); Grid<Wall> wallGridAllTypes = new ListGrid<>(6, 6);
List<Robot> emptyRobotList = new ArrayList<>(); List<Robot> emptyRobotList = new ArrayList<>();
wallGridAllTypes.setElement(1, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); wallGridAllTypes.setElement(1, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH));
wallGridAllTypes.setElement(1, 2, 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_RIGHT, 4);
tileTypeNumberMap.put(TileType.COGWHEEL_LEFT, 1); tileTypeNumberMap.put(TileType.COGWHEEL_LEFT, 1);
tileTypeNumberMap.put(TileType.TILE, 5); tileTypeNumberMap.put(TileType.TILE, 5);
boardWithDifferentAmountOfAllTypes = new Board(tileGridAllTypes,wallGridAllTypes,emptyRobotList); boardWithDifferentAmountOfAllTypes = new Board(tileGridAllTypes, wallGridAllTypes, emptyRobotList);
} }
@Test @Test
public void setRobotPowerDownStatus() { public void setRobotPowerDownStatus() {
Robot testrobot = robotListforpowerdown.get(0); Robot testrobot = robotListforpowerdown.get(0);
assertEquals(false , testrobot.isInPowerDown()); assertEquals(false, testrobot.isInPowerDown());
boardforpowerdown.setPowerDown(RobotID.ROBOT_1,true); boardforpowerdown.setPowerDown(RobotID.ROBOT_1, true);
assertEquals(true , testrobot.isInPowerDown()); assertEquals(true, testrobot.isInPowerDown());
} }
@Test @Test
public void executRobotPowerDown() { public void executRobotPowerDown() {
Robot testrobot = robotListforpowerdown.get(1); Robot testrobot = robotListforpowerdown.get(1);
boardforpowerdown.setPowerDown(RobotID.ROBOT_2,true); boardforpowerdown.setPowerDown(RobotID.ROBOT_2, true);
testrobot.setDamageTaken(4); testrobot.setDamageTaken(4);
assertEquals(4,testrobot.getDamageTaken()); assertEquals(4, testrobot.getDamageTaken());
boardforpowerdown.executePowerdown(); boardforpowerdown.executePowerdown();
assertEquals(0,testrobot.getDamageTaken()); assertEquals(0, testrobot.getDamageTaken());
} }
@Test @Test
public void repairRobotOnRepairTile() { public void repairRobotOnRepairTile() {
Robot testrobot = robotListforpowerdown.get(2); Robot testrobot = robotListforpowerdown.get(2);
testrobot.setDamageTaken(4); testrobot.setDamageTaken(4);
assertEquals(4,testrobot.getDamageTaken()); assertEquals(4, testrobot.getDamageTaken());
boardforpowerdown.repairRobotOnTile(RobotID.ROBOT_3); boardforpowerdown.repairRobotOnTile(RobotID.ROBOT_3);
assertEquals(3,testrobot.getDamageTaken()); assertEquals(3, testrobot.getDamageTaken());
} }
@Test @Test
@ -168,15 +171,17 @@ public class BoardTest {
Robot testRobot = robotListforlaser.get(7); Robot testRobot = robotListforlaser.get(7);
assertEquals(0, testRobot.getDamageTaken()); assertEquals(0, testRobot.getDamageTaken());
boardforlaser.fireAllLasers(); boardforlaser.fireAllLasers();
assertNotEquals(0,testRobot.getDamageTaken()); assertNotEquals(0, testRobot.getDamageTaken());
} }
@Test @Test
public void laserBlockedByWallDoesNotDamageRobot() { public void laserBlockedByWallDoesNotDamageRobot() {
Robot testRobot = robotListforlaser.get(0); Robot testRobot = robotListforlaser.get(0);
assertEquals(0, testRobot.getDamageTaken()); assertEquals(0, testRobot.getDamageTaken());
boardforlaser.fireAllLasers(); boardforlaser.fireAllLasers();
assertEquals(0,testRobot.getDamageTaken()); assertEquals(0, testRobot.getDamageTaken());
} }
@Test @Test
public void laserBlockedByRobotDoesNotDamageOtherRobot() { public void laserBlockedByRobotDoesNotDamageOtherRobot() {
Robot testRobot1 = robotListforlaser.get(1); Robot testRobot1 = robotListforlaser.get(1);
@ -185,16 +190,18 @@ public class BoardTest {
assertEquals(0, testRobot1.getDamageTaken()); assertEquals(0, testRobot1.getDamageTaken());
assertEquals(0, testRobot2.getDamageTaken()); assertEquals(0, testRobot2.getDamageTaken());
boardforlaser.fireAllLasers(); boardforlaser.fireAllLasers();
assertEquals(0,testRobot1.getDamageTaken()); assertEquals(0, testRobot1.getDamageTaken());
assertNotEquals(0,testRobot2.getDamageTaken()); assertNotEquals(0, testRobot2.getDamageTaken());
} }
@Test @Test
public void doubleLaserDamage() { public void doubleLaserDamage() {
Robot testRobot = robotListforlaser.get(6); Robot testRobot = robotListforlaser.get(6);
assertEquals(0, testRobot.getDamageTaken()); assertEquals(0, testRobot.getDamageTaken());
boardforlaser.fireAllLasers(); boardforlaser.fireAllLasers();
assertEquals(2,testRobot.getDamageTaken()); assertEquals(2, testRobot.getDamageTaken());
} }
@Test @Test
public void robotGetsHitByTwoLasers() { public void robotGetsHitByTwoLasers() {
Robot testRobot = robotListforlaser.get(3); Robot testRobot = robotListforlaser.get(3);
@ -202,6 +209,7 @@ public class BoardTest {
boardforlaser.fireAllLasers(); boardforlaser.fireAllLasers();
assertEquals(2, testRobot.getDamageTaken()); assertEquals(2, testRobot.getDamageTaken());
} }
@Test @Test
public void robotDamageEachOther() { public void robotDamageEachOther() {
Robot robot5 = robotListforlaser.get(4); Robot robot5 = robotListforlaser.get(4);
@ -213,6 +221,7 @@ public class BoardTest {
assertEquals(1, robot5.getDamageTaken()); assertEquals(1, robot5.getDamageTaken());
assertEquals(2, robot6.getDamageTaken()); assertEquals(2, robot6.getDamageTaken());
} }
@Test @Test
public void robotStandingOnLaserTakesDamage() { public void robotStandingOnLaserTakesDamage() {
Robot robot6 = robotListforlaser.get(5); Robot robot6 = robotListforlaser.get(5);
@ -220,20 +229,21 @@ public class BoardTest {
boardforlaser.fireAllLasers(); boardforlaser.fireAllLasers();
assertEquals(1, robot6.getDamageTaken()); assertEquals(1, robot6.getDamageTaken());
} }
@Test @Test
public void flagGetsUpdatedOnRobotWithCorrectLastVisitedFlag() { public void flagGetsUpdatedOnRobotWithCorrectLastVisitedFlag() {
Robot testRobot = robotList.get(6); Robot testRobot = robotList.get(6);
assertEquals(0,testRobot.getLastFlagVisited()); assertEquals(0, testRobot.getLastFlagVisited());
board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_1); board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_1);
assertEquals(1,testRobot.getLastFlagVisited()); assertEquals(1, testRobot.getLastFlagVisited());
} }
@Test @Test
public void flagDoesNotUpdatedOnRobotWithWringLastVisitedFlag() { public void flagDoesNotUpdatedOnRobotWithWringLastVisitedFlag() {
Robot testRobot = robotList.get(6); Robot testRobot = robotList.get(6);
assertEquals(0,testRobot.getLastFlagVisited()); assertEquals(0, testRobot.getLastFlagVisited());
board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_2); board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_2);
assertEquals(0,testRobot.getLastFlagVisited()); assertEquals(0, testRobot.getLastFlagVisited());
} }
@Test @Test
@ -293,13 +303,13 @@ public class BoardTest {
assertEquals(Direction.NORTH, robot.getFacingDirection()); assertEquals(Direction.NORTH, robot.getFacingDirection());
} }
@Test (expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void gridsOfDifferentSizeThrowsError() { public void gridsOfDifferentSizeThrowsError() {
IGrid<Wall> wallGrid = new Grid<>(1, 1); Grid<Wall> wallGrid = new ListGrid<>(1, 1);
new Board(tileGrid, wallGrid, robotList); new Board(tileGrid, wallGrid, robotList);
} }
@Test (expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void multipleRobotsWithSameIDThrowsError() { public void multipleRobotsWithSameIDThrowsError() {
Robot robot = new Robot(RobotID.ROBOT_1, someValidPosition1); Robot robot = new Robot(RobotID.ROBOT_1, someValidPosition1);
robotList.add(robot); robotList.add(robot);
@ -336,7 +346,7 @@ public class BoardTest {
@Test @Test
public void getPositionsOfTileOnBoardGivesCorrectAmountOfCogwheelLeftTiles() { public void getPositionsOfTileOnBoardGivesCorrectAmountOfCogwheelLeftTiles() {
assertEquals((int)tileTypeNumberMap.get(TileType.COGWHEEL_LEFT), assertEquals((int) tileTypeNumberMap.get(TileType.COGWHEEL_LEFT),
boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT).size()); boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT).size());
} }
@ -348,7 +358,7 @@ public class BoardTest {
@Test @Test
public void getPositionsOfTileOnBoardGivesCorrectAmountOfTileTiles() { public void getPositionsOfTileOnBoardGivesCorrectAmountOfTileTiles() {
assertEquals((int)tileTypeNumberMap.get(TileType.TILE), assertEquals((int) tileTypeNumberMap.get(TileType.TILE),
boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE).size()); boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE).size());
} }
@ -360,7 +370,7 @@ public class BoardTest {
@Test @Test
public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallNormalWalls() { public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallNormalWalls() {
assertEquals((int)wallTypeNumberMap.get(WallType.WALL_NORMAL), assertEquals((int) wallTypeNumberMap.get(WallType.WALL_NORMAL),
boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL).size()); boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL).size());
} }
@ -372,7 +382,7 @@ public class BoardTest {
@Test @Test
public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallCornerWalls() { public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallCornerWalls() {
assertEquals((int)wallTypeNumberMap.get(WallType.WALL_CORNER), assertEquals((int) wallTypeNumberMap.get(WallType.WALL_CORNER),
boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER).size()); boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER).size());
} }
@ -402,6 +412,7 @@ public class BoardTest {
elemList.removeIf(pred); elemList.removeIf(pred);
return 0 == elemList.size(); return 0 == elemList.size();
} }
private <K> boolean checkIfAllElementsAreOfSpecificTileType(List<BoardElementContainer<Tile>> elemList, K TileType) { private <K> boolean checkIfAllElementsAreOfSpecificTileType(List<BoardElementContainer<Tile>> elemList, K TileType) {
Predicate<BoardElementContainer<Tile>> pred = (element) -> element.getElement().getTileType() == TileType; Predicate<BoardElementContainer<Tile>> pred = (element) -> element.getElement().getTileType() == TileType;
elemList.removeIf(pred); elemList.removeIf(pred);

View File

@ -15,16 +15,16 @@ import static org.junit.Assert.assertFalse;
@RunWith(GdxTestRunner.class) @RunWith(GdxTestRunner.class)
public class DrawableObjectTest { 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 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 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, private static final TextureRegion TEXTURE_MIN_ARG = new TextureRegion(textureSheet, 4 * 300, 0,
300, 300); 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 WIDTH_MAX_ARG = 50;
private final int HEIGHT_MAX_ARG = 60; private final int HEIGHT_MAX_ARG = 60;
private final int ROTATION_MAX_ARG = 90; private final int ROTATION_MAX_ARG = 90;

View File

@ -7,16 +7,16 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class GridTest { public class ListGridTest {
private Grid<Tile> grid; private ListGrid<Tile> grid;
private Grid<Tile> grid2; private ListGrid<Tile> grid2;
private Tile defaultTile; private Tile defaultTile;
@Before @Before
public void setUp() { public void setUp() {
defaultTile = new Tile(TileType.TILE, Direction.NORTH); defaultTile = new Tile(TileType.TILE, Direction.NORTH);
grid = new Grid<>(7, 4); grid = new ListGrid<>(7, 4);
grid2 = new Grid<>(5,8, defaultTile); grid2 = new ListGrid<>(5, 8, defaultTile);
} }
@Test @Test
@ -41,22 +41,22 @@ public class GridTest {
@Test @Test
public void getElementFromGrid2() { public void getElementFromGrid2() {
assertEquals(defaultTile, grid2.getElement(3,5)); assertEquals(defaultTile, grid2.getElement(3, 5));
} }
@Test @Test
public void setElementInGrid2() { public void setElementInGrid2() {
Tile hole = new Tile(TileType.HOLE, Direction.NORTH); Tile hole = new Tile(TileType.HOLE, Direction.NORTH);
grid2.setElement(2,1, hole); grid2.setElement(2, 1, hole);
assertEquals(hole, grid2.getElement(2,1)); assertEquals(hole, grid2.getElement(2, 1));
} }
@Test (expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void invalidPositionThrowsErrorOnGet() { public void invalidPositionThrowsErrorOnGet() {
grid.getElement(7, 4); grid.getElement(7, 4);
} }
@Test (expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void invalidPositionThrowsErrorOnSet() { public void invalidPositionThrowsErrorOnSet() {
grid2.setElement(5, 8, null); grid2.setElement(5, 8, null);
} }

View File

@ -44,7 +44,7 @@ public class ParticleTest {
assertNull(ParticleType.getParticleTypeFromID(-1)); assertNull(ParticleType.getParticleTypeFromID(-1));
} }
@Test (expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void invalidParticleDirectionThrowsError() { public void invalidParticleDirectionThrowsError() {
new Particle(ParticleType.LASER_BEAM_DOUBLE, Direction.NORTH_EAST); new Particle(ParticleType.LASER_BEAM_DOUBLE, Direction.NORTH_EAST);
} }

View File

@ -14,8 +14,8 @@ import static org.junit.Assert.assertTrue;
public class PlayerTest { public class PlayerTest {
private Player playerTest;
private final List<ProgrammingCard> cards = new ArrayList<>(); private final List<ProgrammingCard> cards = new ArrayList<>();
private Player playerTest;
@Before @Before
public void setUp() { public void setUp() {
@ -24,7 +24,7 @@ public class PlayerTest {
cards.add(new ProgrammingCard(30, Action.MOVE_3)); cards.add(new ProgrammingCard(30, Action.MOVE_3));
cards.add(new ProgrammingCard(40, Action.BACK_UP)); cards.add(new ProgrammingCard(40, Action.BACK_UP));
cards.add(new ProgrammingCard(50, Action.ROTATE_LEFT)); cards.add(new ProgrammingCard(50, Action.ROTATE_LEFT));
playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" ); playerTest = new Player(RobotID.ROBOT_1, "TestPlayer");
} }
@Test @Test
@ -48,18 +48,18 @@ public class PlayerTest {
assertEquals(Action.BACK_UP, playerTest.getProgram().get(3).getAction()); assertEquals(Action.BACK_UP, playerTest.getProgram().get(3).getAction());
} }
@Test (expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testSetInProgramWithToManyCards() { public void testSetInProgramWithToManyCards() {
cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT)); cards.add(new ProgrammingCard(10, Action.ROTATE_LEFT));
playerTest.setInProgram(cards); playerTest.setInProgram(cards);
} }
@Test @Test
public void testSetInDeck() { public void testSetInDeck() {
cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT)); cards.add(new ProgrammingCard(10, Action.ROTATE_LEFT));
ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards); ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards);
playerTest.setPlayerDeck(playerDeck); playerTest.setPlayerDeck(playerDeck);
assertEquals(playerDeck , playerTest.getPlayerDeck()); assertEquals(playerDeck, playerTest.getPlayerDeck());
} }
@Test @Test
@ -75,7 +75,7 @@ public class PlayerTest {
@Test @Test
public void getProgramFromPlayer() { public void getProgramFromPlayer() {
playerTest.setInProgram(cards); playerTest.setInProgram(cards);
assertEquals(cards,playerTest.getProgram()); assertEquals(cards, playerTest.getProgram());
} }
} }

View File

@ -4,6 +4,7 @@ import inf112.fiasko.roborally.elementproperties.Action;
import inf112.fiasko.roborally.utility.DeckLoaderUtil; import inf112.fiasko.roborally.utility.DeckLoaderUtil;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -16,9 +17,9 @@ import java.util.List;
public class ProgrammingCardDeckTest { public class ProgrammingCardDeckTest {
private ProgrammingCard programmingCard1; private ProgrammingCard programmingCard1;
private ProgrammingCard programmingCard3; private ProgrammingCard programmingCard3;
private IDeck<ProgrammingCard> testDeck; private Deck<ProgrammingCard> testDeck;
private IDeck<ProgrammingCard> testDeck2; private Deck<ProgrammingCard> testDeck2;
private IDeck<ProgrammingCard> fullDeck; private Deck<ProgrammingCard> fullDeck;
@Before @Before
public void setUp() { public void setUp() {
@ -40,18 +41,18 @@ public class ProgrammingCardDeckTest {
@Test @Test
public void testSize() { public void testSize() {
assertEquals(3,testDeck.size()); assertEquals(3, testDeck.size());
testDeck.emptyInto(testDeck2); testDeck.emptyInto(testDeck2);
assertEquals(0,testDeck.size()); assertEquals(0, testDeck.size());
} }
@Test @Test
public void testDrawCard() { public void testDrawCard() {
assertEquals(3,testDeck.size()); assertEquals(3, testDeck.size());
assertEquals(3,testDeck2.size()); assertEquals(3, testDeck2.size());
testDeck.draw(testDeck2); testDeck.draw(testDeck2);
assertEquals(4,testDeck.size()); assertEquals(4, testDeck.size());
assertEquals(2,testDeck2.size()); assertEquals(2, testDeck2.size());
} }
@Test @Test

View File

@ -1,7 +1,9 @@
package inf112.fiasko.roborally.objects; package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.elementproperties.Action; import inf112.fiasko.roborally.elementproperties.Action;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -17,11 +19,13 @@ public class ProgrammingCardTest {
programmingCard2 = new ProgrammingCard(234, Action.ROTATE_LEFT); programmingCard2 = new ProgrammingCard(234, Action.ROTATE_LEFT);
programmingCard3 = new ProgrammingCard(2334, Action.ROTATE_LEFT); programmingCard3 = new ProgrammingCard(2334, Action.ROTATE_LEFT);
} }
@Test @Test
public void testGetProgrammingCardAction() { public void testGetProgrammingCardAction() {
assertEquals(Action.MOVE_1, programmingCard1.getAction()); assertEquals(Action.MOVE_1, programmingCard1.getAction());
assertEquals(Action.ROTATE_LEFT, programmingCard2.getAction()); assertEquals(Action.ROTATE_LEFT, programmingCard2.getAction());
} }
@Test @Test
public void testGetProgrammingCardValue() { public void testGetProgrammingCardValue() {
assertEquals(5, programmingCard1.getPriority()); assertEquals(5, programmingCard1.getPriority());

View File

@ -8,12 +8,12 @@ import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
public class RoboRallyGameTest { public class RoboRallyGameTest {
private IDrawableGame game; private DrawableGame game;
@Before @Before
public void setUp() { public void setUp() {
game = new RoboRallyGame(new ArrayList<>(),"Checkmate.txt",false, "Player1", game = new RoboRallyGame(new ArrayList<>(), "Checkmate.txt", false, "Player1",
null, null); null);
} }
@Test @Test

View File

@ -1,6 +1,7 @@
package inf112.fiasko.roborally.objects; package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.elementproperties.Position; import inf112.fiasko.roborally.elementproperties.Position;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.elementproperties.RobotID;
@ -8,13 +9,13 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class RobotTest { public class RobotTest {
private final int nextFlag = 1;
private Position robotPosition; private Position robotPosition;
private Robot testRobot; private Robot testRobot;
private final int nextFlag = 1;
@Before @Before
public void setUp() { public void setUp() {
robotPosition = new Position(3,6); robotPosition = new Position(3, 6);
testRobot = new Robot(RobotID.ROBOT_6, robotPosition); testRobot = new Robot(RobotID.ROBOT_6, robotPosition);
} }
@ -46,7 +47,7 @@ public class RobotTest {
@Test @Test
public void testRobotGetPositionOnRobotWithNewPosition() { public void testRobotGetPositionOnRobotWithNewPosition() {
Position newRobotPosition = new Position(8,12); Position newRobotPosition = new Position(8, 12);
testRobot.setPosition(newRobotPosition); testRobot.setPosition(newRobotPosition);
assertEquals(newRobotPosition, testRobot.getPosition()); assertEquals(newRobotPosition, testRobot.getPosition());
} }
@ -70,7 +71,7 @@ public class RobotTest {
@Test @Test
public void testRobotGetNewBackup() { public void testRobotGetNewBackup() {
Position nextFlagPosition = new Position(3,4); Position nextFlagPosition = new Position(3, 4);
testRobot.setPosition(nextFlagPosition); testRobot.setPosition(nextFlagPosition);
testRobot.setLastFlagVisitedAndUpdateBackupPosition(nextFlag); testRobot.setLastFlagVisitedAndUpdateBackupPosition(nextFlag);
assertEquals(nextFlagPosition, testRobot.getBackupPosition()); assertEquals(nextFlagPosition, testRobot.getBackupPosition());

View File

@ -44,7 +44,7 @@ public class TileTest {
assertNull(TileType.getTileTypeFromID(-1)); assertNull(TileType.getTileTypeFromID(-1));
} }
@Test (expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void invalidTileDirectionThrowsError() { public void invalidTileDirectionThrowsError() {
new Tile(TileType.TILE, Direction.NORTH_EAST); new Tile(TileType.TILE, Direction.NORTH_EAST);
} }

View File

@ -2,7 +2,9 @@ package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.elementproperties.Direction; import inf112.fiasko.roborally.elementproperties.Direction;
import inf112.fiasko.roborally.elementproperties.WallType; import inf112.fiasko.roborally.elementproperties.WallType;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
public class WallTest { public class WallTest {
@ -11,21 +13,25 @@ public class WallTest {
Wall testGetWall = new Wall(WallType.WALL_NORMAL, Direction.NORTH); Wall testGetWall = new Wall(WallType.WALL_NORMAL, Direction.NORTH);
assertEquals(WallType.WALL_NORMAL, testGetWall.getWallType()); assertEquals(WallType.WALL_NORMAL, testGetWall.getWallType());
} }
@Test @Test
public void testWallGetWallTypeCorner() { public void testWallGetWallTypeCorner() {
Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.NORTH); Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.NORTH);
assertEquals(WallType.WALL_CORNER, testGetWall.getWallType()); assertEquals(WallType.WALL_CORNER, testGetWall.getWallType());
} }
@Test @Test
public void testWallGetWallTypeLaserSingle() { public void testWallGetWallTypeLaserSingle() {
Wall testGetWall = new Wall(WallType.WALL_LASER_SINGLE, Direction.NORTH); Wall testGetWall = new Wall(WallType.WALL_LASER_SINGLE, Direction.NORTH);
assertEquals(WallType.WALL_LASER_SINGLE, testGetWall.getWallType()); assertEquals(WallType.WALL_LASER_SINGLE, testGetWall.getWallType());
} }
@Test @Test
public void testWallGetDirectionNorth() { public void testWallGetDirectionNorth() {
Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.NORTH); Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.NORTH);
assertEquals(Direction.NORTH, testGetWall.getDirection()); assertEquals(Direction.NORTH, testGetWall.getDirection());
} }
@Test @Test
public void testWallGetDirectionEast() { public void testWallGetDirectionEast() {
Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.EAST); Wall testGetWall = new Wall(WallType.WALL_CORNER, Direction.EAST);