diff --git a/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java b/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java index 01ff12a..0f50999 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java @@ -4,11 +4,11 @@ import inf112.fiasko.roborally.elementproperties.Direction; import inf112.fiasko.roborally.elementproperties.TileType; import inf112.fiasko.roborally.elementproperties.WallType; import inf112.fiasko.roborally.objects.Board; -import inf112.fiasko.roborally.objects.IGrid; +import inf112.fiasko.roborally.objects.Grid; import inf112.fiasko.roborally.objects.Robot; import inf112.fiasko.roborally.objects.Tile; import inf112.fiasko.roborally.objects.Wall; -import inf112.fiasko.roborally.objects.Grid; +import inf112.fiasko.roborally.objects.ListGrid; import java.io.*; import java.util.List; @@ -17,10 +17,13 @@ import java.util.List; * This class helps loading boards */ public final class BoardLoaderUtil { - private BoardLoaderUtil() {} + + private BoardLoaderUtil() { + } /** * 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 @@ -34,21 +37,22 @@ public final class BoardLoaderUtil { int gridWidth = Integer.parseInt(infoData[0]); int gridHeight = Integer.parseInt(infoData[1]); - IGrid tileGrid = loadTileGrid(reader, gridWidth, gridHeight); - IGrid wallGrid = loadWallGrid(reader, gridWidth, gridHeight); + Grid tileGrid = loadTileGrid(reader, gridWidth, gridHeight); + Grid wallGrid = loadWallGrid(reader, gridWidth, gridHeight); return new Board(tileGrid, wallGrid, robotList); } /** * Loads information about a tile grid from a buffered reader - * @param reader A buffered reader ready to read information about the grid - * @param gridWidth The width of the grid to load + * + * @param reader A buffered reader ready to read information about the grid + * @param gridWidth The width of the grid to load * @param gridHeight The height of the grid to load * @return A grid containing the tiles described by the buffered reader * @throws IOException If the reader reads invalid grid information */ - private static IGrid loadTileGrid(BufferedReader reader, int gridWidth, int gridHeight) throws IOException { - IGrid tileGrid = new Grid<>(gridWidth, gridHeight); + private static Grid loadTileGrid(BufferedReader reader, int gridWidth, int gridHeight) throws IOException { + Grid tileGrid = new ListGrid<>(gridWidth, gridHeight); for (int y = 0; y < gridHeight; y++) { String gridLine = reader.readLine(); String[] tilesOnLine = gridLine.split(" "); @@ -67,14 +71,15 @@ public final class BoardLoaderUtil { /** * Loads information about a wall grid from a buffered reader - * @param reader A buffered reader ready to read information about the grid - * @param gridWidth The width of the grid to load + * + * @param reader A buffered reader ready to read information about the grid + * @param gridWidth The width of the grid to load * @param gridHeight The height of the grid to load * @return A grid containing the walls described by the buffered reader * @throws IOException If the reader reads invalid grid information */ - private static IGrid loadWallGrid(BufferedReader reader, int gridWidth, int gridHeight) throws IOException { - IGrid wallGrid = new Grid<>(gridWidth, gridHeight); + private static Grid loadWallGrid(BufferedReader reader, int gridWidth, int gridHeight) throws IOException { + Grid wallGrid = new ListGrid<>(gridWidth, gridHeight); for (int y = 0; y < gridHeight; y++) { String gridLine = reader.readLine(); String[] wallsOnLine = gridLine.split(" "); diff --git a/src/main/java/inf112/fiasko/roborally/utility/DeckLoaderUtil.java b/src/main/java/inf112/fiasko/roborally/utility/DeckLoaderUtil.java index f167f18..1a1f4da 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/DeckLoaderUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/DeckLoaderUtil.java @@ -17,6 +17,7 @@ public final class DeckLoaderUtil { /** * Returns a programming card deck containing all official programming cards + * * @return A programming card deck with programming cards * @throws IOException If the programming cards file is invalid */ diff --git a/src/main/java/inf112/fiasko/roborally/utility/IOUtil.java b/src/main/java/inf112/fiasko/roborally/utility/IOUtil.java index 834c28c..40d8691 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/IOUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/IOUtil.java @@ -5,14 +5,14 @@ import inf112.fiasko.roborally.elementproperties.Direction; import inf112.fiasko.roborally.elementproperties.Position; import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.objects.Player; -import inf112.fiasko.roborally.objects.IDrawableObject; import inf112.fiasko.roborally.objects.Tile; -import inf112.fiasko.roborally.objects.IDrawableGame; +import inf112.fiasko.roborally.objects.DrawableGame; import inf112.fiasko.roborally.objects.Wall; import inf112.fiasko.roborally.objects.Particle; import inf112.fiasko.roborally.objects.Robot; import inf112.fiasko.roborally.objects.DrawableObject; import com.esotericsoftware.kryonet.Connection; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -21,17 +21,19 @@ import java.util.Map; * This class helps with tasks which mix primitive classes and classes from external libraries */ public final class IOUtil { - private IOUtil() {} + private IOUtil() { + } /** * Generates a list of players from a map of player names and a map of robot ids + * * @param playerNames A map between connections and player names - * @param robotIDs A map between connections and robot ids + * @param robotIDs A map between connections and robot ids * @return A list of players */ public static List playerGenerator(Map playerNames, Map robotIDs) { List playerList = new ArrayList<>(); - for (Connection connection: playerNames.keySet()) { + for (Connection connection : playerNames.keySet()) { Player player = new Player(robotIDs.get(connection), playerNames.get(connection)); playerList.add(player); } @@ -40,13 +42,14 @@ public final class IOUtil { /** * Gets a list of all elements which should be drawn from the game provided - * @param game A game implementing IDrawableGame - * @param tileWidth The with of all tiles to be drawn + * + * @param game A game implementing DrawableGame + * @param tileWidth The with of all tiles to be drawn * @param tileHeight The height of all tiles to be drawn * @return A list of drawable objects */ - public static List getDrawableObjectsFromGame(IDrawableGame game, int tileWidth, int tileHeight) { - List drawableObjects = new ArrayList<>(); + public static List getDrawableObjectsFromGame(DrawableGame game, int tileWidth, int tileHeight) { + List drawableObjects = new ArrayList<>(); List tilesToDraw = game.getTilesToDraw(); List wallsToDraw = game.getWallsToDraw(); List particlesToDraw = game.getParticlesToDraw(); @@ -62,19 +65,21 @@ public final class IOUtil { /** * Gets a list of all drawable robots on the board - * @param robots A list of robots to draw + * + * @param robots A list of robots to draw * @param gameHeight The height of the game - * @param tileWidth The width of a tile + * @param tileWidth The width of a tile * @param tileHeight The height of a tile * @return A list of drawable robots */ - private static List getDrawableRobots(List robots, int gameHeight, int tileWidth, int tileHeight) { - List drawableObjects = new ArrayList<>(); + private static List getDrawableRobots(List robots, int gameHeight, int tileWidth, + int tileHeight) { + List drawableObjects = new ArrayList<>(); for (Robot robot : robots) { TextureRegion region = TextureConverterUtil.convertElement(robot); Position robotPosition = robot.getPosition(); int rotation = getElementRotation(robot); - IDrawableObject drawableObject = new DrawableObject(region, robotPosition.getXCoordinate() * tileWidth, + DrawableObject drawableObject = new DrawableObject(region, robotPosition.getXCoordinate() * tileWidth, (-robotPosition.getYCoordinate() + gameHeight - 1) * tileHeight, tileWidth, tileHeight, rotation); drawableObjects.add(drawableObject); } @@ -83,16 +88,17 @@ public final class IOUtil { /** * Gets a list of drawable objects with correct positions from a list of elements + * * @param elementsToDraw A list of elements to draw - * @param gameWidth The width of the game board in tiles - * @param tileWidth The width of a tile - * @param tileHeight The height of a tile - * @param Should be type Robot, Tile or Wall + * @param gameWidth The width of the game board in tiles + * @param tileWidth The width of a tile + * @param tileHeight The height of a tile + * @param Should be type Robot, Tile or Wall * @return A list of drawable objects */ - private static List getDrawableObjectsFromElementList(List elementsToDraw, int gameWidth, int tileWidth, - int tileHeight) { - List drawableObjects = new ArrayList<>(); + private static List getDrawableObjectsFromElementList(List elementsToDraw, int gameWidth, + int tileWidth, int tileHeight) { + List drawableObjects = new ArrayList<>(); int y = 0; for (int i = 0; i < elementsToDraw.size(); i++) { K currentElement = elementsToDraw.get(i); @@ -117,7 +123,7 @@ public final class IOUtil { throw new IllegalArgumentException("Unknown element type passed to function."); } int rotation = getElementRotation(currentElement); - IDrawableObject drawableObject = new DrawableObject(region, + DrawableObject drawableObject = new DrawableObject(region, x * tileWidth, y * tileHeight, tileWidth, tileHeight, rotation); drawableObjects.add(drawableObject); } @@ -126,8 +132,9 @@ public final class IOUtil { /** * Gets the amount of degrees to rotate an element + * * @param element The element to rotate - * @param Should be of type Tile, Robot or Wall + * @param Should be of type Tile, Robot or Wall * @return The amount of degrees the tile should be rotated to be properly displayed */ private static int getElementRotation(K element) { diff --git a/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java b/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java index 863790d..5109624 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java @@ -5,10 +5,10 @@ import inf112.fiasko.roborally.elementproperties.Action; import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.networking.containers.ErrorResponse; import inf112.fiasko.roborally.networking.containers.GameStartInfo; -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.ProgramAndPowerdownRequest; -import inf112.fiasko.roborally.objects.IDeck; +import inf112.fiasko.roborally.objects.Deck; import inf112.fiasko.roborally.objects.Player; import inf112.fiasko.roborally.objects.ProgrammingCard; import inf112.fiasko.roborally.objects.ProgrammingCardDeck; @@ -23,11 +23,12 @@ public final class NetworkUtil { /** * Registers all classes which can be sent between a server and a client + * * @param kryo The kryo object to register the classes to */ public static void registerClasses(Kryo kryo) { kryo.register(ErrorResponse.class); - kryo.register(IDeck.class); + kryo.register(Deck.class); kryo.register(ProgrammingCard.class); kryo.register(GameStartInfo.class); kryo.register(ArrayList.class); @@ -37,7 +38,7 @@ public final class NetworkUtil { kryo.register(Action.class); kryo.register(ProgramAndPowerdownRequest.class); kryo.register(ProgamsContainer.class); - kryo.register(PowerdownContainer.class); + kryo.register(PowerDownContainer.class); kryo.register(HashMap.class); diff --git a/src/main/java/inf112/fiasko/roborally/utility/ResourceUtil.java b/src/main/java/inf112/fiasko/roborally/utility/ResourceUtil.java index 5e5a32c..01723aa 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/ResourceUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/ResourceUtil.java @@ -6,10 +6,12 @@ import java.io.InputStream; * This class helps with tasks related to resource loading */ public final class ResourceUtil { - private ResourceUtil() {} + private ResourceUtil() { + } /** * Gets an input stream for a given resource + * * @param resourcePath The relative path from the resources folder to the resource * @return An input stream */ diff --git a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java index 136be44..9eb1b78 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java @@ -35,10 +35,12 @@ public final class TextureConverterUtil { private static Map tileSheetParticleHasRotatedTextureMappings; private static Map tileSheetWallTextureMappings; - private TextureConverterUtil() {} + private TextureConverterUtil() { + } /** * Gets a list of all disposable elements which should be disposed when the software closes + * * @return A list of disposable elements */ public static List getDisposableElements() { @@ -50,6 +52,7 @@ public final class TextureConverterUtil { /** * Gets the texture representing the tile + * * @param tile The tile to draw * @return The texture to draw */ @@ -74,6 +77,7 @@ public final class TextureConverterUtil { /** * Gets the texture representing the particle + * * @param particle The particle to draw * @return The texture to draw */ @@ -98,6 +102,7 @@ public final class TextureConverterUtil { /** * Gets the texture representing the tile + * * @param wall The wall to draw * @return The texture to draw */ @@ -125,6 +130,7 @@ public final class TextureConverterUtil { /** * Gets the texture representing the robot + * * @param robot The robot to draw * @return The texture to draw */ @@ -134,17 +140,17 @@ public final class TextureConverterUtil { } else if (robot.getRobotId() == RobotID.ROBOT_2) { return new TextureRegion(robotsTexture, 64, 0, 64, 64); } else if (robot.getRobotId() == RobotID.ROBOT_3) { - return new TextureRegion(robotsTexture, 2*64, 0, 64, 64); + return new TextureRegion(robotsTexture, 2 * 64, 0, 64, 64); } else if (robot.getRobotId() == RobotID.ROBOT_4) { - return new TextureRegion(robotsTexture, 3*64, 0, 64, 64); + return new TextureRegion(robotsTexture, 3 * 64, 0, 64, 64); } else if (robot.getRobotId() == RobotID.ROBOT_5) { - return new TextureRegion(robotsTexture, 4*64, 0, 64, 64); + return new TextureRegion(robotsTexture, 4 * 64, 0, 64, 64); } else if (robot.getRobotId() == RobotID.ROBOT_6) { - return new TextureRegion(robotsTexture, 5*64, 0, 64, 64); + return new TextureRegion(robotsTexture, 5 * 64, 0, 64, 64); } else if (robot.getRobotId() == RobotID.ROBOT_7) { - return new TextureRegion(robotsTexture, 6*64, 0, 64, 64); + return new TextureRegion(robotsTexture, 6 * 64, 0, 64, 64); } else if (robot.getRobotId() == RobotID.ROBOT_8) { - return new TextureRegion(robotsTexture, 7*64, 0, 64, 64); + return new TextureRegion(robotsTexture, 7 * 64, 0, 64, 64); } throw new IllegalArgumentException("Robot has no drawable texture."); } @@ -152,7 +158,7 @@ public final class TextureConverterUtil { /** * Checks whether a tile has textures for different rotations * - * For a tile without a rotated texture, the texture needs to be rotated when rendering. + *

For a tile without a rotated texture, the texture needs to be rotated when rendering.

* * @param tile The tile to check * @return True if rotated versions of the texture exists. False otherwise @@ -171,7 +177,7 @@ public final class TextureConverterUtil { /** * Checks whether a particle has textures for different rotations * - * For a particle without a rotated texture, the texture needs to be rotated when rendering. + *

For a particle without a rotated texture, the texture needs to be rotated when rendering.

* * @param particle The particle to check * @return True if rotated versions of the texture exists. False otherwise @@ -190,8 +196,8 @@ public final class TextureConverterUtil { /** * Loads mappings between a tile and texture * - * Loads both information about mapping from a tile to a texture converter container and information about mapping - * from a tile to whether the tile has a rotated version of each texture + *

Loads both information about mapping from a tile to a texture converter container and information about mapping + * from a tile to whether the tile has a rotated version of each texture

* * @throws IOException If the mapping file can't be properly read */ @@ -212,8 +218,8 @@ public final class TextureConverterUtil { /** * Loads mappings between a particle and a texture * - * Loads both information about mapping from a particle to a texture converter container and information about - * mapping from a particle to whether the particle has a rotated version of each texture + *

Loads both information about mapping from a particle to a texture converter container and information about + * mapping from a particle to whether the particle has a rotated version of each texture

* * @throws IOException If the mapping file can't be properly read */ @@ -251,15 +257,16 @@ public final class TextureConverterUtil { /** * Reads one line of texture mapping and puts it into the correct maps - * @param parameters The parameters describing the texture mapping of the element - * @param mapKey The key to store in the map - * @param textureMapping The map containing texture mappings + * + * @param parameters The parameters describing the texture mapping of the element + * @param mapKey The key to store in the map + * @param textureMapping The map containing texture mappings * @param hasRotatedTextureMapping The map containing whether an element has rotated textures or not - * @param The type of element that will be used for map keys + * @param The type of element that will be used for map keys */ private static synchronized void storeTextMappingInMap(String[] parameters, K mapKey, - Map textureMapping, - Map hasRotatedTextureMapping) { + Map textureMapping, + Map hasRotatedTextureMapping) { TextureConverterContainer container; int xNorth = Integer.parseInt(parameters[1]); int yNorth = Integer.parseInt(parameters[2]); @@ -287,15 +294,16 @@ public final class TextureConverterUtil { /** * Gets a texture region based on the direction of the tile + * * @param direction The direction the tile is facing - * @param xNorth The relative x position on the texture sheet if the tile is facing north - * @param yNorth The relative y position on the texture sheet if the tile is facing north - * @param xEast The relative x position on the texture sheet if the tile is facing east - * @param yEast The relative y position on the texture sheet if the tile is facing east - * @param xSouth The relative x position on the texture sheet if the tile is facing south - * @param ySouth The relative y position on the texture sheet if the tile is facing south - * @param xWest The relative x position on the texture sheet if the tile is facing west - * @param yWest The relative y position on the texture sheet if the tile is facing west + * @param xNorth The relative x position on the texture sheet if the tile is facing north + * @param yNorth The relative y position on the texture sheet if the tile is facing north + * @param xEast The relative x position on the texture sheet if the tile is facing east + * @param yEast The relative y position on the texture sheet if the tile is facing east + * @param xSouth The relative x position on the texture sheet if the tile is facing south + * @param ySouth The relative y position on the texture sheet if the tile is facing south + * @param xWest The relative x position on the texture sheet if the tile is facing west + * @param yWest The relative y position on the texture sheet if the tile is facing west * @return The texture region containing the tile's texture */ private static TextureRegion getDirectionalTextureRegion(Direction direction, int xNorth, int yNorth, int xEast, @@ -321,6 +329,7 @@ public final class TextureConverterUtil { /** * Gets a texture on the main tiles texture sheet + * * @param x The relative x coordinate on the sheet * @param y The relative y coordinate on the sheet * @return The texture region containing the texture @@ -328,7 +337,7 @@ public final class TextureConverterUtil { private static TextureRegion getTextureOnSheet(int x, int y) { final int tileTextureHeight = 300; final int tileTextureWidth = 300; - return new TextureRegion(textureSheet, x*tileTextureWidth, y*tileTextureHeight, + return new TextureRegion(textureSheet, x * tileTextureWidth, y * tileTextureHeight, tileTextureWidth, tileTextureHeight); } diff --git a/src/test/java/inf112/fiasko/roborally/utility/BoardLoaderUtilTest.java b/src/test/java/inf112/fiasko/roborally/utility/BoardLoaderUtilTest.java index 5e1562f..0179c02 100644 --- a/src/test/java/inf112/fiasko/roborally/utility/BoardLoaderUtilTest.java +++ b/src/test/java/inf112/fiasko/roborally/utility/BoardLoaderUtilTest.java @@ -2,6 +2,7 @@ package inf112.fiasko.roborally.utility; import inf112.fiasko.roborally.objects.Robot; import org.junit.Test; + import java.io.IOException; import java.util.ArrayList; import java.util.List; diff --git a/src/test/java/inf112/fiasko/roborally/utility/TextureConverterUtilTest.java b/src/test/java/inf112/fiasko/roborally/utility/TextureConverterUtilTest.java index 48838c5..35de05c 100644 --- a/src/test/java/inf112/fiasko/roborally/utility/TextureConverterUtilTest.java +++ b/src/test/java/inf112/fiasko/roborally/utility/TextureConverterUtilTest.java @@ -13,7 +13,7 @@ import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -@RunWith (GdxTestRunner.class) +@RunWith(GdxTestRunner.class) public class TextureConverterUtilTest { private Tile tileNorth; private Tile holeNorth; @@ -34,20 +34,20 @@ public class TextureConverterUtilTest { @Test public void tileTileConversion() { - assertEquals(4*300, tileTextureRegion.getRegionX()); + assertEquals(4 * 300, tileTextureRegion.getRegionX()); assertEquals(0, tileTextureRegion.getRegionY()); } @Test public void tileHoleConversion() { - assertEquals(5*300, holeTextureRegion.getRegionX()); + assertEquals(5 * 300, holeTextureRegion.getRegionX()); assertEquals(0, holeTextureRegion.getRegionY()); } @Test public void tileTransportBandSlowFacingEastConversion() { - assertEquals(3*300, transportBandSlowEastTextureRegion.getRegionX()); - assertEquals(6*300, transportBandSlowEastTextureRegion.getRegionY()); + assertEquals(3 * 300, transportBandSlowEastTextureRegion.getRegionX()); + assertEquals(6 * 300, transportBandSlowEastTextureRegion.getRegionY()); } @Test