From 8df3a8a9ab0dc3838116d7677012c2ab1abc85ff Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 20 Mar 2020 17:46:49 +0100 Subject: [PATCH] Rydder opp i en del kommentarer og kode --- .../game_wrapper/CardChoiceScreen.java | 2 +- .../game_wrapper/MainMenuScreen.java | 7 +- .../game_wrapper/RoboRallyWrapper.java | 2 +- .../fiasko/roborally/objects/Board.java | 133 +++++++++--------- .../roborally/objects/RoboRallyGame.java | 5 +- .../fiasko/roborally/objects/BoardTest.java | 7 +- 6 files changed, 76 insertions(+), 80 deletions(-) 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 fa7bbcd..9d38ee3 100644 --- a/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java @@ -30,7 +30,7 @@ public class CardChoiceScreen extends InputAdapter implements Screen { private final List cardRectangles; private final ShapeRenderer shapeRenderer; private final Viewport viewport; - private List chosenCards; + private final List chosenCards; private final int maxCards; public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) { diff --git a/src/main/java/inf112/fiasko/roborally/game_wrapper/MainMenuScreen.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/MainMenuScreen.java index e349670..90979f9 100644 --- a/src/main/java/inf112/fiasko/roborally/game_wrapper/MainMenuScreen.java +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/MainMenuScreen.java @@ -33,9 +33,10 @@ public class MainMenuScreen implements Screen { roboRallyWrapper.batch.setProjectionMatrix(camera.combined); roboRallyWrapper.batch.begin(); - roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Robo Rally", 0, 250, - 200, 0, false); - roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click anywhere to run the demo", 70, 200); + roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Robo Rally", 10, 250, + 380, 1, true); + roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click anywhere to run the demo", 10, 200, + 380, 1, true); roboRallyWrapper.batch.end(); if (Gdx.input.isTouched()) { diff --git a/src/main/java/inf112/fiasko/roborally/game_wrapper/RoboRallyWrapper.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/RoboRallyWrapper.java index ac109aa..778028b 100644 --- a/src/main/java/inf112/fiasko/roborally/game_wrapper/RoboRallyWrapper.java +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/RoboRallyWrapper.java @@ -17,7 +17,7 @@ public class RoboRallyWrapper extends Game { batch = new SpriteBatch(); font = new BitmapFont(Gdx.files.internal("assets/Montserrat-Regular.fnt")); this.screenManager = new ScreenManager(); - this.setScreen(screenManager.getBoardActiveScreen(this)); + this.setScreen(screenManager.getMainMenuScreen(this)); } public void dispose() { diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index d6a05d4..f34b25b 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -46,21 +46,6 @@ public class Board { this.deadRobots = new ArrayList<>(); } - /** - * Fires all lasers on the board and kills any robot that has taken to much damage after all lasers have fired. - */ - public void fireAllLasers(){ - List> listOfWallLasers = getPositionsOfWallOnBoard(WallType.WALL_LASER_SINGLE, - WallType.WALL_LASER_DOUBLE); - for (Robot robot:robots.values()) { - fireOneRobotLaser(robot.getPosition(),robot.getFacingDirection()); - } - for (BoardElementContainer laser:listOfWallLasers) { - fireOneWallLaser(laser); - } - killAllDeadRobot(); - } - /** * Gets the height of the board * @return The height of the board @@ -244,6 +229,21 @@ public class Board { } } + /** + * Fires all lasers on the board and kills any robot that has taken to much damage after all lasers have fired. + */ + public void fireAllLasers() { + List> listOfWallLasers = getPositionsOfWallOnBoard(WallType.WALL_LASER_SINGLE, + WallType.WALL_LASER_DOUBLE); + for (Robot robot:robots.values()) { + fireRobotLaser(robot.getPosition(),robot.getFacingDirection()); + } + for (BoardElementContainer laser : listOfWallLasers) { + fireWallLaser(laser); + } + killAllHeavilyDamagedRobots(); + } + /** * Gets the tile on a specific position * @param position The position to get a tile from @@ -282,6 +282,15 @@ public class Board { return combinedList; } + /** + * 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 + */ + public boolean hasRobotOnPosition(Position position) { + return getRobotOnPosition(position) != null; + } + /** * Checks if a potential move would be blocked by a wall * @param robotPosition The current position of whatever is trying to move @@ -289,7 +298,7 @@ public class Board { * @param direction The direction something is going * @return True if a wall would stop its path */ - public boolean moveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) { + private boolean moveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) { return hasWallFacing(robotPosition, direction) || (isValidPosition(newPosition) && hasWallFacing(newPosition, Direction.getReverseDirection(direction))); } @@ -357,15 +366,6 @@ public class Board { deadRobots.add(robot); } - /** - * 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 - */ - public boolean hasRobotOnPosition(Position position) { - return getRobotOnPosition(position) != null; - } - /** * Checks whether a position has a wall facing a specific direction * @param position The position to check @@ -403,11 +403,11 @@ public class Board { } /** - * Finds all position of an obj and makes a list of BoardElementContainers - * @param type Type of obj - * @param grid Grid to search - * @param Type of type - * @param Type of grid + * Finds all tiles/walls with a certain type + * @param type The type of tile/wall to look for + * @param grid The grid to look through + * @param Type of the type to look for + * @param Type of the grid * @return List of BoardElementContainers */ private List> makeTileList(K type, IGrid grid) { @@ -420,12 +420,12 @@ public class Board { if (gridElement.getClass().isAssignableFrom(Tile.class)) { Tile tile = (Tile) gridElement; if (tile.getTileType() == type) { - objList.add(new BoardElementContainer<>(gridElement, new Position(x,y))); + objList.add(new BoardElementContainer<>(gridElement, new Position(x, y))); } } else if (gridElement.getClass().isAssignableFrom(Wall.class)) { Wall wall = (Wall) gridElement; if (wall.getWallType() == type) { - objList.add(new BoardElementContainer<>(gridElement, new Position(x,y))); + objList.add(new BoardElementContainer<>(gridElement, new Position(x, y))); } } else { throw new IllegalArgumentException("Grid has unknown type."); @@ -437,11 +437,11 @@ public class Board { } /** - * Kills all robots that has taken too much damage + * Kills all robots that have taken too much damage */ - private void killAllDeadRobot(){ + private void killAllHeavilyDamagedRobots() { for (Robot robot:robots.values()) { - if(robot.getDamageTaken()>=10){ + if (robot.getDamageTaken() >= 10) { killRobot(robot); } } @@ -449,62 +449,57 @@ public class Board { /** * Fires one wall laser - * @param laser the wall laser that is being fired + * @param wallLaser The wall laser being fired */ - private void fireOneWallLaser(BoardElementContainer laser){ - Position hitPosition = lineForTheLaser(Direction.getReverseDirection(laser.getElement().getDirection()), - laser.getPosition()); - if(getRobotOnPosition(hitPosition)!=null){ - laserDamage(laser.getElement().getWallType(),robots.get(getRobotOnPosition(hitPosition))); + private void fireWallLaser(BoardElementContainer wallLaser) { + Position hitPosition = getLaserTarget(Direction.getReverseDirection(wallLaser.getElement().getDirection()), + wallLaser.getPosition()); + if (getRobotOnPosition(hitPosition) != null) { + applyLaserDamage(wallLaser.getElement().getWallType(), robots.get(getRobotOnPosition(hitPosition))); } } /** - * fires on robot laser - * @param robotPosition the position of the robot firing the laser - * @param robotDirection the direction the robot is facing + * Fires one robot laser + * @param robotPosition The position of the robot firing the laser + * @param robotDirection The direction the robot is facing */ - private void fireOneRobotLaser(Position robotPosition, Direction robotDirection){ + private void fireRobotLaser(Position robotPosition, Direction robotDirection){ Position positionInFront = getNewPosition(robotPosition,robotDirection); - - if(!isValidPosition(positionInFront)||moveIsStoppedByWall(robotPosition,positionInFront,robotDirection)){ + if (!isValidPosition(positionInFront) || moveIsStoppedByWall(robotPosition, positionInFront, robotDirection)) { return; } - Position hitPosition = lineForTheLaser(robotDirection,positionInFront); - if(getRobotOnPosition(hitPosition)!=null){ - laserDamage(WallType.WALL_LASER_SINGLE,robots.get(getRobotOnPosition(hitPosition))); + Position hitPosition = getLaserTarget(robotDirection, positionInFront); + if (getRobotOnPosition(hitPosition) != null) { + applyLaserDamage(WallType.WALL_LASER_SINGLE, robots.get(getRobotOnPosition(hitPosition))); } } /** * Applies the damage form the laser to the robot the laser hit - * @param laserType the type of laser that hit the robot - * @param robot the robot getting hit by the robot + * @param laserType The type of laser that hit the robot + * @param robot The robot getting hit by the robot */ - private void laserDamage(WallType laserType, Robot robot){ - robot.setDamageTaken(robot.getDamageTaken()+laserType.getWallTypeID()-2); + private void applyLaserDamage(WallType laserType, Robot robot) { + robot.setDamageTaken(robot.getDamageTaken() + laserType.getWallTypeID() - 2); } /** - * Gets the Position of where the laser hits something - * @param direction the direction of the laser - * @param startPosition the start positon of the laser - * @return the position of the element that stopped the laser + * Gets the position of the tile the laser stops at + * @param direction The direction of the laser + * @param startPosition The start position of the laser + * @return The position the laser stopped at */ - private Position lineForTheLaser(Direction direction, Position startPosition){ - Position newPosition = getNewPosition(startPosition,direction); - if(!isValidPosition(newPosition) || moveIsStoppedByWall(startPosition,newPosition,direction) || - getRobotOnPosition(startPosition)!= null){ + private Position getLaserTarget(Direction direction, Position startPosition) { + Position newPosition = getNewPosition(startPosition, direction); + if (!isValidPosition(newPosition) || moveIsStoppedByWall(startPosition, newPosition, direction) || + getRobotOnPosition(startPosition) != null) { return startPosition; - } - else if(getRobotOnPosition(newPosition)!=null){ + } else if (getRobotOnPosition(newPosition) != null) { return newPosition; - } - else{ - return lineForTheLaser(direction,newPosition); + } else { + return getLaserTarget(direction, newPosition); } } - - } \ No newline at end of file diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 87b4a7e..0547f63 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -154,7 +154,10 @@ public class RoboRallyGame implements IDrawableGame { makeMove(RobotID.ROBOT_2, Action.U_TURN); makeMove(RobotID.ROBOT_2, Action.MOVE_1); moveAllConveyorBelts(); + checkAllFlags(); + rotateCogwheels(); makeMove(RobotID.ROBOT_7, Action.MOVE_1); + fireAllLasers(); } /** @@ -362,7 +365,7 @@ public class RoboRallyGame implements IDrawableGame { } } - private void fireAllLasers(){ + private void fireAllLasers() { gameBoard.fireAllLasers(); } } \ No newline at end of file diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index 54d6958..515fcf1 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -5,7 +5,6 @@ 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 org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -38,8 +37,6 @@ public class BoardTest { private Board boardWithDifferentAmountOfAllTypes; private final Map wallTypeNumberMap = new HashMap<>(); private final Map tileTypeNumberMap = new HashMap<>(); - private Grid tileGridforlaser; - private Grid wallGridforlaser; private List robotListforlaser; private Board boardforlaser; @@ -59,8 +56,8 @@ public class BoardTest { @Before public void setUp() { - tileGridforlaser = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH)); - wallGridforlaser = new Grid<>(8, 8); + Grid tileGridforlaser = new Grid<>(8, 8, new Tile(TileType.TILE, Direction.NORTH)); + Grid wallGridforlaser = new Grid<>(8, 8); robotListforlaser = new ArrayList<>(); robotListforlaser.add(new Robot(RobotID.ROBOT_1, new Position(2,1))); robotListforlaser.add(new Robot(RobotID.ROBOT_2, new Position(4,0)));