diff --git a/README.md b/README.md index 245fa0f..8b08a5c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,16 @@ Alle regler er hentet fra 2005 utgaven av spillguiden fra Wizards of the Coast, ## Spillstatus Ved kjøring av .jar filen blir det kjørt en demo, uten mulighet for bruker å bevege robot. +## Knapper og kontrollmekanismer +### Knapper +- Q: Tilbakestiller kamera og kamerarotasjon +- R: Roterer kameraet +- HOME: Bytter til en debug instans av spillet som lar en sjekke at alle teksturer vises riktig + +### Andre egenskaper ved brukergrensesnittet +- Rullehjulet vil forstørre og forminske spillbrettet +- Spillbrettet kan flyttes ved å holde inne venstre musetast og bevege musen i en retning + ## Bygging og kompilering ### Forkrav for å kunne kompilere og kjøre koden @@ -22,6 +32,7 @@ cd Fiasko mvn clean install ``` Dette vil også kjøre alle tester i koden + ### Kjøreprosedyre ```shell script cd target diff --git a/src/main/java/inf112/fiasko/roborally/Main.java b/src/main/java/inf112/fiasko/roborally/Main.java index c73f55a..e8c4978 100644 --- a/src/main/java/inf112/fiasko/roborally/Main.java +++ b/src/main/java/inf112/fiasko/roborally/Main.java @@ -2,6 +2,7 @@ package inf112.fiasko.roborally; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; +import inf112.fiasko.roborally.game_wrapper.RoboRallyWrapper; public class Main { @@ -10,7 +11,8 @@ public class Main { cfg.title = "Game Board"; cfg.width = 900; cfg.height = 900; + cfg.samples = 3; - new LwjglApplication(new GameLauncher(), cfg); + new LwjglApplication(new RoboRallyWrapper(), cfg); } } \ No newline at end of file diff --git a/src/main/java/inf112/fiasko/roborally/GameLauncher.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/BoardActiveScreen.java similarity index 59% rename from src/main/java/inf112/fiasko/roborally/GameLauncher.java rename to src/main/java/inf112/fiasko/roborally/game_wrapper/BoardActiveScreen.java index aaad23f..dc16260 100644 --- a/src/main/java/inf112/fiasko/roborally/GameLauncher.java +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/BoardActiveScreen.java @@ -1,35 +1,31 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.game_wrapper; -import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputProcessor; +import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; -import inf112.fiasko.roborally.game.Game; -import inf112.fiasko.roborally.game.IDrawableGame; +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.utils.viewport.ExtendViewport; +import com.badlogic.gdx.utils.viewport.Viewport; +import inf112.fiasko.roborally.objects.IDrawableGame; import inf112.fiasko.roborally.objects.IDrawableObject; +import inf112.fiasko.roborally.objects.RoboRallyGame; import inf112.fiasko.roborally.utility.IOUtil; +import inf112.fiasko.roborally.utility.TextureConverterUtil; import java.util.List; -/** - * This class renders a game using libgdx - */ -public class GameLauncher extends ApplicationAdapter implements InputProcessor { - private OrthographicCamera camera; - private SpriteBatch batch; - private IDrawableGame game; +public class BoardActiveScreen implements Screen, InputProcessor { + private final RoboRallyWrapper roboRallyWrapper; + private final OrthographicCamera camera; private IDrawableGame debugGame; - private Texture robotTexture; - private Texture textureSheet; - private final int tileDimensions = 64; private float cameraZoom = 1; private int cameraX = 0; @@ -37,57 +33,64 @@ public class GameLauncher extends ApplicationAdapter implements InputProcessor { private Vector2 lastTouch; private final int viewPortWidth = 12 * tileDimensions; private final int viewPortHeight = 12 * tileDimensions; + private final Viewport viewport; - @Override - public void create() { - //Loads some textures - robotTexture = new Texture(Gdx.files.internal("assets/Robot.png")); - textureSheet = new Texture(Gdx.files.internal("assets/tiles.png")); + public BoardActiveScreen(final RoboRallyWrapper roboRallyWrapper) { + this.roboRallyWrapper = roboRallyWrapper; + roboRallyWrapper.roboRallyGame = new RoboRallyGame(); + debugGame = new RoboRallyGame(true); - debugGame = new Game(true); - game = new Game(false); camera = new OrthographicCamera(); camera.setToOrtho(false, viewPortWidth, viewPortHeight); camera.position.set(viewPortWidth/2f, viewPortHeight/2f, 0); - batch = new SpriteBatch(); - /*MyTextInputListener listener = new MyTextInputListener(); - Gdx.input.getTextInput(listener, "Input name", "", "Name");*/ + viewport = new ExtendViewport(viewPortWidth, viewPortHeight, camera); + Gdx.input.setInputProcessor(this); lastTouch = new Vector2(); } - /** - * Renders all textures necessary to display a game - */ - public void render() { - Gdx.gl.glClearColor(0,0,0.2f,1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - camera.update(); - batch.setProjectionMatrix(camera.combined); - batch.begin(); - camera.translate(cameraX, cameraY); - cameraX = 0; - cameraY = 0; - camera.zoom = cameraZoom; - //Draws all elements the game wants to draw - List elementsToDraw = IOUtil.getDrawableObjectsFromGame(game, tileDimensions, tileDimensions); - for (IDrawableObject object : elementsToDraw) { - TextureRegion objectTextureRegion = object.getTexture(); - batch.draw(objectTextureRegion.getTexture(), object.getXPosition(), object.getYPosition(), - (float)object.getWidth()/2, (float)object.getHeight()/2, - object.getWidth(), object.getHeight(), 1, 1, object.getRotation(), - objectTextureRegion.getRegionX(), objectTextureRegion.getRegionY(), - objectTextureRegion.getRegionWidth(), objectTextureRegion.getRegionHeight(), - object.flipX(), object.flipY()); - } - batch.end(); + @Override + public void show() { + resetCamera(); + } + + @Override + public void resize(int width, int height) { + viewport.update(width, height); + } + + @Override + public void pause() { + //Nothing to do + } + + @Override + public void resume() { + //Nothing to do + } + + @Override + public void hide() { + //Nothing to do + } + + @Override + public void render(float delta) { + Gdx.gl.glClearColor(0,0,0,1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | + (Gdx.graphics.getBufferFormat().coverageSampling?GL20.GL_COVERAGE_BUFFER_BIT_NV:0)); + updateCamera(); + roboRallyWrapper.batch.setProjectionMatrix(camera.combined); + roboRallyWrapper.batch.begin(); + drawBoard(roboRallyWrapper.batch); + roboRallyWrapper.batch.end(); } @Override public void dispose() { - robotTexture.dispose(); - textureSheet.dispose(); - batch.dispose(); + for (Disposable disposable : TextureConverterUtil.getDisposableElements()) { + disposable.dispose(); + } } @Override @@ -97,26 +100,11 @@ public class GameLauncher extends ApplicationAdapter implements InputProcessor { @Override public boolean keyUp(int keycode) { - switch (keycode) { - case Input.Keys.PLUS: - if (Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT)) { - cameraZoom -= 0.1; - return true; - } - break; - case Input.Keys.MINUS: - if (Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT)) { - cameraZoom += 0.1; - return true; - } - break; - case Input.Keys.HOME: - IDrawableGame temp = game; - this.game = debugGame; - this.debugGame = temp; - return true; - default: - return false; + if (keycode == Input.Keys.HOME) { + IDrawableGame temp = roboRallyWrapper.roboRallyGame; + roboRallyWrapper.roboRallyGame = debugGame; + this.debugGame = temp; + return true; } return false; } @@ -130,11 +118,7 @@ public class GameLauncher extends ApplicationAdapter implements InputProcessor { new Vector3(0, 0, 1), 90); return true; } else if (character == 'q') { - camera.up.x = 0; - camera.up.y = 1; - cameraZoom = 1; - System.out.print((game.getHeight() * tileDimensions) - viewPortHeight/2f); - camera.position.set(viewPortWidth/2f, viewPortHeight/2f, 0); + resetCamera(); } return false; } @@ -157,11 +141,63 @@ public class GameLauncher extends ApplicationAdapter implements InputProcessor { Vector2 diff = newTouch.cpy().sub(lastTouch); lastTouch = newTouch; int[] positionChange = translateCoordinateAccountingForCameraRotation(diff.x, diff.y); - cameraX = positionChange[0]; - cameraY = positionChange[1]; + cameraX = (int)(positionChange[0] * cameraZoom); + cameraY = (int)(positionChange[1] * cameraZoom); return true; } + @Override + public boolean mouseMoved(int screenX, int screenY) { + return false; + } + + @Override + public boolean scrolled(int amount) { + if (amount < 0 && cameraZoom > 0.3 || amount > 0 && cameraZoom < 3) { + cameraZoom += 0.2 * amount; + } + return true; + } + + /** + * Resets the camera to its initial position + */ + private void resetCamera() { + camera.up.x = 0; + camera.up.y = 1; + cameraZoom = 1; + camera.position.set(viewPortWidth/2f, viewPortHeight/2f, 0); + } + + /** + * Renders all drawable objects on the board + * @param batch The sprite batch to use for drawing + */ + private void drawBoard(SpriteBatch batch) { + List elementsToDraw = + IOUtil.getDrawableObjectsFromGame(roboRallyWrapper.roboRallyGame, tileDimensions, tileDimensions); + for (IDrawableObject object : elementsToDraw) { + TextureRegion objectTextureRegion = object.getTexture(); + batch.draw(objectTextureRegion.getTexture(), object.getXPosition(), object.getYPosition(), + (float)object.getWidth()/2, (float)object.getHeight()/2, + object.getWidth(), object.getHeight(), 1, 1, object.getRotation(), + objectTextureRegion.getRegionX(), objectTextureRegion.getRegionY(), + objectTextureRegion.getRegionWidth(), objectTextureRegion.getRegionHeight(), + object.flipX(), object.flipY()); + } + } + + /** + * Updates the camera according to any user input + */ + private void updateCamera() { + camera.translate(cameraX, cameraY); + cameraX = 0; + cameraY = 0; + camera.zoom = cameraZoom; + camera.update(); + } + /** * Translates x and y coordinates according to the camera's direction * @param x The x coordinate to translate @@ -188,28 +224,4 @@ public class GameLauncher extends ApplicationAdapter implements InputProcessor { } return new int[]{outX, outY}; } - - @Override - public boolean mouseMoved(int screenX, int screenY) { - return false; - } - - @Override - public boolean scrolled(int amount) { - if (amount < 0 && cameraZoom > 0 || amount > 0 && cameraZoom < 2) { - cameraZoom += amount / 10.0; - } - return true; - } - - /*public static class MyTextInputListener implements Input.TextInputListener { - @Override - public void input (String text) { - System.out.println(text); - } - - @Override - public void canceled () { - } - }*/ -} \ No newline at end of file +} diff --git a/src/main/java/inf112/fiasko/roborally/game_wrapper/MainMenuScreen.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/MainMenuScreen.java new file mode 100644 index 0000000..e349670 --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/MainMenuScreen.java @@ -0,0 +1,71 @@ +package inf112.fiasko.roborally.game_wrapper; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.utils.viewport.ExtendViewport; +import com.badlogic.gdx.utils.viewport.Viewport; + +public class MainMenuScreen implements Screen { + private final RoboRallyWrapper roboRallyWrapper; + + private final OrthographicCamera camera; + private final Viewport viewport; + + public MainMenuScreen(final RoboRallyWrapper roboRallyWrapper) { + this.roboRallyWrapper = roboRallyWrapper; + camera = new OrthographicCamera(); + camera.setToOrtho(false, 400, 400); + viewport = new ExtendViewport(400, 400, camera); + } + + @Override + public void show() { + //Nothing to do + } + + @Override + public void render(float delta) { + Gdx.gl.glClearColor(0.2f, 1f, 0.2f, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + camera.update(); + 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.batch.end(); + + if (Gdx.input.isTouched()) { + roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper)); + dispose(); + } + } + + @Override + public void resize(int width, int height) { + viewport.update(width, height); + } + + @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 + } +} diff --git a/src/main/java/inf112/fiasko/roborally/game_wrapper/RoboRallyWrapper.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/RoboRallyWrapper.java new file mode 100644 index 0000000..af11147 --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/RoboRallyWrapper.java @@ -0,0 +1,25 @@ +package inf112.fiasko.roborally.game_wrapper; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import inf112.fiasko.roborally.objects.IDrawableGame; + +public class RoboRallyWrapper extends Game { + public SpriteBatch batch; + public BitmapFont font; + public ScreenManager screenManager; + public IDrawableGame roboRallyGame; + + @Override + public void create() { + batch = new SpriteBatch(); + font = new BitmapFont(); + this.screenManager = new ScreenManager(); + this.setScreen(screenManager.getMainMenuScreen(this)); + } + + public void dispose() { + batch.dispose(); + } +} diff --git a/src/main/java/inf112/fiasko/roborally/game_wrapper/ScreenManager.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/ScreenManager.java new file mode 100644 index 0000000..286f2ad --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/ScreenManager.java @@ -0,0 +1,33 @@ +package inf112.fiasko.roborally.game_wrapper; + +/** + * Keeps track of screen instances + */ +public class ScreenManager { + private MainMenuScreen mainMenuScreen; + private BoardActiveScreen boardActiveScreen; + + /** + * Gets an instance of the main menu screen + * @param roboRallyWrapper The robo rally launcher instance to use + * @return A main menu screen instance + */ + public synchronized MainMenuScreen getMainMenuScreen(RoboRallyWrapper roboRallyWrapper) { + if (this.mainMenuScreen == null) { + this.mainMenuScreen = new MainMenuScreen(roboRallyWrapper); + } + return mainMenuScreen; + } + + /** + * Gets an instance of the board active screen + * @param roboRallyWrapper The robo rally launcher instance to use + * @return A board active screen instance + */ + public synchronized BoardActiveScreen getBoardActiveScreen(RoboRallyWrapper roboRallyWrapper) { + if (this.boardActiveScreen == null) { + this.boardActiveScreen = new BoardActiveScreen(roboRallyWrapper); + } + return boardActiveScreen; + } +} diff --git a/src/main/java/inf112/fiasko/roborally/game/IDrawableGame.java b/src/main/java/inf112/fiasko/roborally/objects/IDrawableGame.java similarity index 86% rename from src/main/java/inf112/fiasko/roborally/game/IDrawableGame.java rename to src/main/java/inf112/fiasko/roborally/objects/IDrawableGame.java index ac25ae3..847f158 100644 --- a/src/main/java/inf112/fiasko/roborally/game/IDrawableGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/IDrawableGame.java @@ -1,8 +1,4 @@ -package inf112.fiasko.roborally.game; - -import inf112.fiasko.roborally.objects.Robot; -import inf112.fiasko.roborally.objects.Tile; -import inf112.fiasko.roborally.objects.Wall; +package inf112.fiasko.roborally.objects; import java.util.List; diff --git a/src/main/java/inf112/fiasko/roborally/game/Game.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java similarity index 89% rename from src/main/java/inf112/fiasko/roborally/game/Game.java rename to src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 521c6f4..f5dc4c2 100644 --- a/src/main/java/inf112/fiasko/roborally/game/Game.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -1,11 +1,7 @@ -package inf112.fiasko.roborally.game; +package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.Position; import inf112.fiasko.roborally.element_properties.RobotID; -import inf112.fiasko.roborally.objects.Board; -import inf112.fiasko.roborally.objects.Robot; -import inf112.fiasko.roborally.objects.Tile; -import inf112.fiasko.roborally.objects.Wall; import inf112.fiasko.roborally.utility.BoardLoaderUtil; import java.io.IOException; @@ -16,10 +12,10 @@ import java.util.concurrent.TimeUnit; /** * This class represent a game which is drawable using libgdx */ -public class Game implements IDrawableGame { +public class RoboRallyGame implements IDrawableGame { private Board gameBoard; - public Game(boolean debug) { + public RoboRallyGame(boolean debug) { if (debug) { initializeDebugMode(); } else { @@ -27,38 +23,10 @@ public class Game implements IDrawableGame { } } - public Game() { + public RoboRallyGame() { initializeGame(); } - private void initializeDebugMode() { - List robots = new ArrayList<>(); - try { - gameBoard = BoardLoaderUtil.loadBoard("boards/all_tiles_test_board.txt", robots); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void initializeGame() { - try { - List robots = new ArrayList<>(); - robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1))); - robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 2))); - robots.add(new Robot(RobotID.ROBOT_3, new Position(1, 3))); - gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots); - new Thread(() -> { - try { - runGameLoop(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - }).start(); - } catch (IOException e) { - e.printStackTrace(); - } - } - @Override public int getWidth() { return gameBoard.getBoardWidth(); @@ -84,6 +52,43 @@ public class Game implements IDrawableGame { return gameBoard.getAliveRobots(); } + /** + * Initializes the game with a debugging board + */ + private void initializeDebugMode() { + List robots = new ArrayList<>(); + robots.add(new Robot(RobotID.ROBOT_1, new Position(0, 16))); + robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 16))); + robots.add(new Robot(RobotID.ROBOT_3, new Position(2, 16))); + try { + gameBoard = BoardLoaderUtil.loadBoard("boards/all_tiles_test_board.txt", robots); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Initializes the game with a playable board + */ + private void initializeGame() { + try { + List robots = new ArrayList<>(); + robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1))); + robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 2))); + robots.add(new Robot(RobotID.ROBOT_3, new Position(1, 3))); + gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots); + new Thread(() -> { + try { + runGameLoop(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }).start(); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * Does whatever the game wants to do * @throws InterruptedException If interrupted while trying to sleep diff --git a/src/main/java/inf112/fiasko/roborally/objects/Wall.java b/src/main/java/inf112/fiasko/roborally/objects/Wall.java index 8f4c941..cbe3ab5 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Wall.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Wall.java @@ -17,6 +17,9 @@ public class Wall { * @param direction The direction of the wall */ public Wall (WallType wallType, Direction direction) { + if (direction.getDirectionID() % 2 == 0 && wallType != WallType.WALL_CORNER) { + throw new IllegalArgumentException("Invalid direction for wall type submitted"); + } this.wallType = wallType; this.direction = direction; } diff --git a/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java b/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java index 4f563b0..af34d36 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/BoardLoaderUtil.java @@ -86,7 +86,7 @@ public final class BoardLoaderUtil { WallType wallType = WallType.getWallTypeFromID(Integer.parseInt(wallData[0])); Direction direction = Direction.getDirectionFromID(Integer.parseInt(wallData[1])); if (direction == null) { - throw new IllegalArgumentException("Invalid direction for tile encountered when loading board file."); + throw new IllegalArgumentException("Invalid direction for wall encountered when loading board file."); } wallGrid.setElement(x, y, new Wall(wallType, direction)); } diff --git a/src/main/java/inf112/fiasko/roborally/utility/IOUtil.java b/src/main/java/inf112/fiasko/roborally/utility/IOUtil.java index 92fb30c..f200c7a 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/IOUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/IOUtil.java @@ -3,7 +3,7 @@ package inf112.fiasko.roborally.utility; import com.badlogic.gdx.graphics.g2d.TextureRegion; import inf112.fiasko.roborally.element_properties.Direction; import inf112.fiasko.roborally.element_properties.Position; -import inf112.fiasko.roborally.game.IDrawableGame; +import inf112.fiasko.roborally.objects.IDrawableGame; import inf112.fiasko.roborally.objects.DrawableObject; import inf112.fiasko.roborally.objects.IDrawableObject; import inf112.fiasko.roborally.objects.Robot; diff --git a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java index 69b55c7..8245b2a 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java @@ -3,6 +3,7 @@ package inf112.fiasko.roborally.utility; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.utils.Disposable; import inf112.fiasko.roborally.element_properties.Direction; import inf112.fiasko.roborally.element_properties.RobotID; import inf112.fiasko.roborally.element_properties.TileType; @@ -15,7 +16,9 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -32,6 +35,19 @@ public final class 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() { + List disposables = new ArrayList<>(); + disposables.add(textureSheet); + disposables.add(robot1Texture); + disposables.add(robot2Texture); + disposables.add(robot3Texture); + return disposables; + } + /** * Gets the texture representing the tile * @param tile The tile to draw diff --git a/src/main/resources/assets/tiles.png b/src/main/resources/assets/tiles.png index 1c16301..79c8969 100644 Binary files a/src/main/resources/assets/tiles.png and b/src/main/resources/assets/tiles.png differ diff --git a/src/main/resources/boards/all_tiles_test_board.txt b/src/main/resources/boards/all_tiles_test_board.txt index b188481..224b5eb 100644 --- a/src/main/resources/boards/all_tiles_test_board.txt +++ b/src/main/resources/boards/all_tiles_test_board.txt @@ -1,4 +1,4 @@ -8 16 +8 19 01;1 01;3 01;5 01;7 02;1 02;3 02;5 02;7 03;1 03;3 03;5 03;7 04;1 04;3 04;5 04;7 05;1 05;3 05;5 05;7 06;1 06;3 06;5 06;7 @@ -15,6 +15,9 @@ 27;1 27;3 27;5 27;7 28;1 28;3 28;5 28;7 29;1 29;3 29;5 29;7 30;1 30;3 30;5 30;7 31;1 31;3 31;5 31;7 01;1 01;1 01;1 01;1 +01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 +01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 +01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 @@ -30,4 +33,7 @@ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 \ No newline at end of file +0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 +1;1 1;3 1;5 1;7 2;2 2;4 2;6 2;8 +3;1 3;3 3;5 3;7 4;1 4;3 4;5 4;7 \ No newline at end of file diff --git a/src/main/resources/texture_sheet_wall_mapping.txt b/src/main/resources/texture_sheet_wall_mapping.txt index 646c71d..2c8ce61 100644 --- a/src/main/resources/texture_sheet_wall_mapping.txt +++ b/src/main/resources/texture_sheet_wall_mapping.txt @@ -1,4 +1,4 @@ WALL_NORMAL 6 3 6 2 4 3 5 3 -WALL_CORNER 7 0 7 1 7 3 7 2 +WALL_CORNER 7 1 7 0 7 3 7 2 WALL_LASER_SINGLE 4 5 5 5 4 4 5 4 -WALL_LASER_DOUBLE 5 11 6 11 6 10 5 11 \ No newline at end of file +WALL_LASER_DOUBLE 5 11 6 11 6 10 4 11 \ No newline at end of file diff --git a/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java b/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java index 880a397..4bf8f84 100644 --- a/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java +++ b/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java @@ -1,5 +1,6 @@ package inf112.fiasko.roborally.element_properties; +import inf112.fiasko.roborally.objects.Tile; import org.junit.Test; import java.util.ArrayList; @@ -44,6 +45,11 @@ public class TileTypeTest { assertNull(TileType.getTileTypeFromID(-1)); } + @Test (expected = IllegalArgumentException.class) + public void invalidTileDirectionThrowsError() { + new Tile(TileType.TILE, Direction.NORTH_EAST); + } + @Test public void allTilesHaveUniqueId() { /* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail diff --git a/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java b/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java index a622b43..88b7ea8 100644 --- a/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java +++ b/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java @@ -1,5 +1,6 @@ package inf112.fiasko.roborally.element_properties; +import inf112.fiasko.roborally.objects.Wall; import org.junit.Test; import java.util.ArrayList; @@ -44,6 +45,11 @@ public class WallTypeTest { assertNull(TileType.getTileTypeFromID(-1)); } + @Test (expected = IllegalArgumentException.class) + public void invalidWallDirectionThrowsError() { + new Wall(WallType.WALL_NORMAL, Direction.NORTH_EAST); + } + @Test public void allWallsHaveUniqueId() { /* This test is also done implicitly by the allTileTypesIDConversionToIDAndBack test, but that test may fail diff --git a/src/test/java/inf112/fiasko/roborally/game/GameTest.java b/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java similarity index 84% rename from src/test/java/inf112/fiasko/roborally/game/GameTest.java rename to src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java index 6d6621a..882f46f 100644 --- a/src/test/java/inf112/fiasko/roborally/game/GameTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java @@ -1,15 +1,16 @@ -package inf112.fiasko.roborally.game; +package inf112.fiasko.roborally.objects; import static org.junit.Assert.assertTrue; + import org.junit.Before; import org.junit.Test; -public class GameTest { +public class RoboRallyGameTest { private IDrawableGame game; @Before public void setUp() { - game = new Game(); + game = new RoboRallyGame(); } @Test