diff --git a/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java index eb1d767..0028d7b 100644 --- a/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java @@ -16,8 +16,8 @@ public class CardChoiceScreen extends InputAdapter implements Screen { private final RoboRallyWrapper roboRallyWrapper; private final OrthographicCamera camera; - private CardRectangle cardRectangle; - private ShapeRenderer shapeRenderer; + private final CardRectangle cardRectangle; + private final ShapeRenderer shapeRenderer; public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) { this.roboRallyWrapper = roboRallyWrapper; @@ -28,7 +28,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen { card1.y = 1200/2; card1.width = 100; card1.height = 100; - cardRectangle = new CardRectangle(card1, false); + cardRectangle = new CardRectangle(card1); shapeRenderer = new ShapeRenderer(); shapeRenderer.setAutoShapeType(true); Gdx.input.setInputProcessor(this); @@ -36,7 +36,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen { @Override public void show() { - + //Nothing to do } @Override @@ -61,27 +61,27 @@ public class CardChoiceScreen extends InputAdapter implements Screen { @Override public void resize(int i, int i1) { - + //Nothing to do } @Override public void pause() { - + //Nothing to do } @Override public void resume() { - + //Nothing to do } @Override public void hide() { - + //Nothing to do } @Override public void dispose() { - + //Nothing to do } @Override @@ -99,11 +99,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen { } class CardRectangle { - Rectangle rectangle; - boolean selected; + protected final Rectangle rectangle; + protected boolean selected = false; - CardRectangle(Rectangle rectangle, boolean selected) { + CardRectangle(Rectangle rectangle) { this.rectangle = rectangle; - this.selected = selected; } } \ No newline at end of file diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index e120dcd..4faf4a3 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -1,6 +1,11 @@ package inf112.fiasko.roborally.objects; -import inf112.fiasko.roborally.element_properties.*; +import inf112.fiasko.roborally.element_properties.Direction; +import inf112.fiasko.roborally.element_properties.Position; +import inf112.fiasko.roborally.element_properties.RobotID; +import inf112.fiasko.roborally.element_properties.TileType; +import inf112.fiasko.roborally.element_properties.WallType; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -166,6 +171,21 @@ public class Board { deadRobots = new ArrayList<>(); } + /** + * Returns a robot id for a robot on a specific position if such a robot exists + * @param position The position to check + * @return The robot id of the robot on the position or null if there is no robot there + */ + public RobotID getRobotOnPosition(Position position) { + for (RobotID robotID : robots.keySet()) { + Robot robot = robots.get(robotID); + if (position.equals(robot.getPosition())) { + return robotID; + } + } + return null; + } + /** * Checks if a specific robot is currently alive on the board * @param robot the ID of the robot you want to check @@ -256,27 +276,12 @@ public class Board { deadRobots.add(robot); } - /** - * Returns a robot id for a robot on a specific position if such a robot exists - * @param position The position to check - * @return The robot id of the robot on the position or null if there is no robot there - */ - RobotID getRobotOnPosition(Position position) { - for (RobotID robotID : robots.keySet()) { - Robot robot = robots.get(robotID); - if (position.equals(robot.getPosition())) { - return robotID; - } - } - return null; - } - /** * Checks whether there exists a robot on a specific position * @param position The position to check * @return True if there is a robot on the specified position */ - boolean hasRobotOnPosition(Position position) { + public boolean hasRobotOnPosition(Position position) { return getRobotOnPosition(position) != null; } @@ -362,7 +367,7 @@ public class Board { * @param walls The walls you want all positions for * @return A list of BoardElementContainers */ - public List> getPositionsOfWallOnBoard(WallType ... walls) { + public List> getPositionsOfWallOnBoard(WallType... walls) { List> combinedList = new ArrayList<>(); for (WallType wall : walls) { combinedList.addAll(makeTileList(wall, this.walls)); diff --git a/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java b/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java index 7b253c7..7b03e4e 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java +++ b/src/main/java/inf112/fiasko/roborally/objects/BoardElementContainer.java @@ -3,36 +3,36 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.Position; /** - * This class represents a type of object and its position - * @param The type of object + * This class represents a board element and its position + * @param The type of element */ -public class BoardElementContainer { - K obj; - private Position pos; +public class BoardElementContainer { + private final K element; + private final Position position; /** * Initializes the BoardElementContainer - * @param obj The object - * @param pos The position + * @param element The element + * @param position The position */ - BoardElementContainer(K obj, Position pos) { - this.obj = obj; - this.pos = pos; + BoardElementContainer(K element, Position position) { + this.element = element; + this.position = position; } /** - * Gets the object - * @return object + * Gets the element + * @return The element */ - public K getObject() { - return obj; + public K getElement() { + return element; } /** * Gets the position - * @return position + * @return The position */ public Position getPosition() { - return pos; + return position; } } diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 5befa58..9ae75e6 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -211,7 +211,7 @@ public class RoboRallyGame implements IDrawableGame { continue; } sleep(); - if (cogwheel.obj.getTileType() == TileType.COGWHEEL_RIGHT) { + if (cogwheel.getElement().getTileType() == TileType.COGWHEEL_RIGHT) { gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition())); } else { gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition())); @@ -258,7 +258,7 @@ public class RoboRallyGame implements IDrawableGame { continue; } Position conveyorBeltPosition = conveyorBelt.getPosition(); - Tile conveyorBeltTile = conveyorBelt.getObject(); + Tile conveyorBeltTile = conveyorBelt.getElement(); Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltTile.getDirection()); Tile nextTile = gameBoard.getTileOnPosition(newPosition); @@ -283,7 +283,7 @@ public class RoboRallyGame implements IDrawableGame { Direction nextDirection = nextTile.getDirection(); sleep(); gameBoard.moveRobot(robot, currentDirection); - if (testPredicate(conveyorBelts, (container) -> container.getObject() == nextTile)) { + if (testPredicate(conveyorBelts, (container) -> container.getElement() == nextTile)) { if (Direction.getRightRotatedDirection(nextDirection) == currentDirection) { sleep(); gameBoard.rotateRobotLeft(robot); @@ -304,7 +304,7 @@ public class RoboRallyGame implements IDrawableGame { Position flagPosition = flag.getPosition(); if (gameBoard.hasRobotOnPosition(flagPosition)) { RobotID robot = gameBoard.getRobotOnPosition(flagPosition); - gameBoard.updateFlagOnRobot(robot, flag.getObject().getTileType()); + gameBoard.updateFlagOnRobot(robot, flag.getElement().getTileType()); } } } diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardElementContainerTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardElementContainerTest.java index 7654fcb..6203264 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardElementContainerTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardElementContainerTest.java @@ -14,7 +14,7 @@ public class BoardElementContainerTest { Position pos = new Position(1,2); Tile tile = new Tile(TileType.TILE, Direction.NORTH); BoardElementContainer element = new BoardElementContainer<>(tile, pos); - assertEquals(tile, element.getObject()); + assertEquals(tile, element.getElement()); } @Test diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index c155e68..7f10db1 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -35,8 +35,8 @@ public class BoardTest { private List robotList; private Board board; private Board boardWithDifferentAmountOfAllTypes; - private Map wallTypeNumberMap = new HashMap<>(); - private Map tileTypeNumberMap = new HashMap<>(); + private final Map wallTypeNumberMap = new HashMap<>(); + private final Map tileTypeNumberMap = new HashMap<>(); @BeforeClass public static void globalSetUp() { @@ -223,7 +223,7 @@ public class BoardTest { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT); for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getObject().getTileType(), TileType.COGWHEEL_LEFT); + assertEquals(elem.getElement().getTileType(), TileType.COGWHEEL_LEFT); } } @@ -238,7 +238,7 @@ public class BoardTest { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE); for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getObject().getTileType(), TileType.TILE); + assertEquals(elem.getElement().getTileType(), TileType.TILE); } } @@ -253,7 +253,7 @@ public class BoardTest { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL); for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getObject().getWallType(), WallType.WALL_NORMAL); + assertEquals(elem.getElement().getWallType(), WallType.WALL_NORMAL); } } @@ -268,14 +268,14 @@ public class BoardTest { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getObject().getWallType(), WallType.WALL_CORNER); + assertEquals(elem.getElement().getWallType(), WallType.WALL_CORNER); } } @Test public void getPositionsOfWallOnBoardHasCorrect() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); - Predicate> pred = (element) -> element.getObject().getWallType() == WallType.WALL_CORNER; + Predicate> pred = (element) -> element.getElement().getWallType() == WallType.WALL_CORNER; boardElemList.removeIf(pred); assertEquals(0, boardElemList.size()); } diff --git a/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java b/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java index 9277788..3bdce6e 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/PlayerTest.java @@ -8,12 +8,14 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class PlayerTest { private Player playerTest; - private List cards = new ArrayList(); + private final List cards = new ArrayList<>(); @Before public void setUp() { @@ -22,7 +24,6 @@ public class PlayerTest { cards.add(new ProgrammingCard(30, Action.MOVE_3)); cards.add(new ProgrammingCard(40, Action.BACK_UP)); cards.add(new ProgrammingCard(50, Action.ROTATE_LEFT)); - ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards); playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" ); } @@ -37,8 +38,9 @@ public class PlayerTest { playerTest.setPowerDownNextRound(false); assertFalse(playerTest.getPowerDownNextRound()); } + @Test - public void testSetInProgram(){ + public void testSetInProgram() { playerTest.setInProgram(cards); assertEquals(Action.MOVE_1, playerTest.getProgramFromPlayer().get(0).getAction()); assertEquals(Action.MOVE_2, playerTest.getProgramFromPlayer().get(1).getAction()); @@ -47,13 +49,13 @@ public class PlayerTest { } @Test (expected = IllegalArgumentException.class) - public void testSetInProgramWithToManyCards(){ + public void testSetInProgramWithToManyCards() { cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT)); playerTest.setInProgram(cards); } @Test - public void testSetInDeck(){ + public void testSetInDeck() { cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT)); ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards); playerTest.setPlayerDeck(playerDeck); @@ -61,17 +63,17 @@ public class PlayerTest { } @Test - public void GetPlayerRobotId(){ + public void getPlayerRobotId() { assertEquals(RobotID.ROBOT_1, playerTest.getRobotID()); } @Test - public void GetPlayerName(){ + public void getPlayerName() { assertEquals("TestPlayer", playerTest.getName()); } @Test - public void GetProgramFromPlayer(){ + public void getProgramFromPlayer() { playerTest.setInProgram(cards); assertEquals(cards,playerTest.getProgram()); }