From 979703bcf9bf7196adf811c7b212ad39700d82e3 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 5 May 2020 12:33:20 +0200 Subject: [PATCH] =?UTF-8?q?Legger=20til=20automatisk=20rotasjon=20av=20bre?= =?UTF-8?q?tt=20med=20st=C3=B8rre=20bredde=20enn=20h=C3=B8yde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roborally/utility/BoardLoaderUtil.java | 57 ++++++++----------- .../fiasko/roborally/objects/PhaseTest.java | 6 +- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java b/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java index 0c51290..ec52397 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java @@ -51,6 +51,26 @@ public final class BoardLoaderUtil { return boards; } + /** + * Loads a board described in a file + * + * @param boardFile The file containing the board description + * @param robotList A list of robots on the board + * @return A board + * @throws IOException If the board file cannot be loaded + */ + public static Board loadBoard(String boardFile, List robotList) throws IOException { + TwoTuple, Grid> grids = loadBoardGrids(boardFile); + Grid tileGrid = grids.value1; + Grid wallGrid = grids.value2; + if (grids.value1.getHeight() < grids.value1.getWidth()) { + tileGrid = rotateGrid(tileGrid, true); + wallGrid = rotateGrid(wallGrid, true); + } + adjustRobotRotationToBoardRotation(tileGrid, robotList); + return new Board(tileGrid, wallGrid, robotList); + } + /** * Gets a list of all available boards * @@ -69,21 +89,6 @@ public final class BoardLoaderUtil { return boardList; } - /** - * Loads and rotates a board described in a file - * - * @param boardFile The file containing the board description - * @param robotList A list of robots on the board - * @param clockwise Whether to rotate the board clockwise - * @return A board - * @throws IOException If the board file cannot be loaded - */ - public static Board loadBoardRotated(String boardFile, List robotList, boolean clockwise) throws IOException { - TwoTuple, Grid> grids = loadBoardGrids(boardFile); - adjustRobotRotationToBoardRotation(grids.value1, robotList); - return new Board(rotateGrid(grids.value1, clockwise), rotateGrid(grids.value2, clockwise), robotList); - } - /** * Loads the grids necessary to create a board * @@ -138,20 +143,6 @@ public final class BoardLoaderUtil { return newGrid; } - /** - * Loads a board described in a file - * - * @param boardFile The file containing the board description - * @param robotList A list of robots on the board - * @return A board - * @throws IOException If the board file cannot be loaded - */ - public static Board loadBoard(String boardFile, List robotList) throws IOException { - TwoTuple, Grid> grids = loadBoardGrids(boardFile); - adjustRobotRotationToBoardRotation(grids.value1, robotList); - return new Board(grids.value1, grids.value2, robotList); - } - /** * Changes the direction of robots to the direction which is up * @@ -159,13 +150,13 @@ public final class BoardLoaderUtil { * @param robotList The list of robots on the board */ private static void adjustRobotRotationToBoardRotation(Grid tileGrid, List robotList) { - //The flags are always in the up direction - List> flags = GridUtil.getMatchingElements(TileType.ROBOT_SPAWN_1, tileGrid); + //The spawns are always in the up direction + List> spawns = GridUtil.getMatchingElements(TileType.ROBOT_SPAWN_1, tileGrid); Direction boardDirection; - if (flags.size() == 0) { + if (spawns.size() == 0) { boardDirection = Direction.NORTH; } else { - boardDirection = flags.get(0).getElement().getDirection(); + boardDirection = spawns.get(0).getElement().getDirection(); } for (Robot robot : robotList) { robot.setFacingDirection(boardDirection); diff --git a/src/test/java/inf112/fiasko/roborally/objects/PhaseTest.java b/src/test/java/inf112/fiasko/roborally/objects/PhaseTest.java index cccccd1..611ac68 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/PhaseTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/PhaseTest.java @@ -86,21 +86,21 @@ public class PhaseTest { assertTrue(robot.hasTouchedFlagThisTurn()); robot.setHasTouchedFlagThisTurn(false); assertNull(testGame.getWinningPlayerName()); - board.moveRobot(robotID, Direction.EAST); + board.moveRobot(robotID, Direction.SOUTH); testPhase.checkAllFlags(); //Should have registered second flag assertEquals(2, robot.getLastFlagVisited()); assertTrue(robot.hasTouchedFlagThisTurn()); assertNull(testGame.getWinningPlayerName()); robot.setHasTouchedFlagThisTurn(false); - board.moveRobot(robotID, Direction.EAST); + board.moveRobot(robotID, Direction.SOUTH); testPhase.checkAllFlags(); //Should have registered third flag assertEquals(3, robot.getLastFlagVisited()); assertTrue(robot.hasTouchedFlagThisTurn()); assertNull(testGame.getWinningPlayerName()); robot.setHasTouchedFlagThisTurn(false); - board.moveRobot(robotID, Direction.EAST); + board.moveRobot(robotID, Direction.SOUTH); testPhase.checkAllFlags(); //Should have registered fourth and last flag assertEquals(4, robot.getLastFlagVisited());