diff --git a/src/main/java/inf112/fiasko/roborally/TextureConverter.java b/src/main/java/inf112/fiasko/roborally/TextureConverter.java new file mode 100644 index 0000000..5e95cae --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/TextureConverter.java @@ -0,0 +1,204 @@ +package inf112.fiasko.roborally; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import inf112.fiasko.roborally.objects.Tile; + +public class TextureConverter { + private Texture textureSheet = new Texture(Gdx.files.internal("assets/tiles.png")); + + private TextureConverter() {} + + /** + * Gets the texture representing the tile + * @param tile The tile to draw + * @return The texture to draw + */ + public TextureRegion convertElement(Tile tile) { + final int tileTextureHeight = 300, tileTextureWidth = 300; + switch (tile.getTileType()) { + case TILE: + return getTextureOnSheet(4, 0); + case HOLE: + return getTextureOnSheet(5, 0); + case COGWHEEL_RIGHT: + return getTextureOnSheet(5, 6); + case COGWHEEL_LEFT: + return getTextureOnSheet(4, 6); + case TRANSPORT_BAND_SLOW: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(0, 6); + case EAST: + return getTextureOnSheet(3, 6); + case SOUTH: + return getTextureOnSheet(1, 6); + case WEST: + return getTextureOnSheet(2, 6); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + case TRANSPORT_BAND_SLOW_RIGHT: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(2, 5); + case EAST: + return getTextureOnSheet(2, 4); + case SOUTH: + return getTextureOnSheet(3, 4); + case WEST: + return getTextureOnSheet(3, 5); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + case TRANSPORT_BAND_SLOW_LEFT: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(1, 5); + case EAST: + return getTextureOnSheet(0, 5); + case SOUTH: + return getTextureOnSheet(0, 4); + case WEST: + return getTextureOnSheet(1, 4); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + case TRANSPORT_BAND_SLOW_SIDE_ENTRANCES: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(4, 8); + case EAST: + return getTextureOnSheet(0, 5); + case SOUTH: + return new TextureRegion(textureSheet, 0, 4*tileTextureHeight, + tileTextureWidth, tileTextureHeight); + case WEST: + return new TextureRegion(textureSheet, tileTextureWidth, 4*tileTextureHeight, + tileTextureWidth, tileTextureHeight); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + case TRANSPORT_BAND_SLOW_SIDE_ENTRANCE_RIGHT: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(0, 8); + case EAST: + return getTextureOnSheet(1, 8); + case SOUTH: + return getTextureOnSheet(2, 8); + case WEST: + return getTextureOnSheet(3, 8); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + case TRANSPORT_BAND_SLOW_SIDE_ENTRANCE_LEFT: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(0,7); + case EAST: + return getTextureOnSheet(1, 7); + case SOUTH: + return getTextureOnSheet(2, 7); + case WEST: + return getTextureOnSheet(3, 7); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + case TRANSPORT_BAND_FAST: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(4,1); + case EAST: + return getTextureOnSheet(5, 1); + case SOUTH: + return getTextureOnSheet(4, 2); + case WEST: + return getTextureOnSheet(5, 2); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + case TRANSPORT_BAND_FAST_RIGHT: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(2,3); + case EAST: + return getTextureOnSheet(2, 2); + case SOUTH: + return getTextureOnSheet(3, 2); + case WEST: + return getTextureOnSheet(3, 3); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + case TRANSPORT_BAND_FAST_LEFT: + switch (tile.getDirection()) { + case NORTH: + return getTextureOnSheet(1,3); + case EAST: + return getTextureOnSheet(0, 3); + case SOUTH: + return getTextureOnSheet(3, 2); + case WEST: + return getTextureOnSheet(3, 3); + default: + throw new IllegalArgumentException("Invalid direction for slow transport band encountered"); + } + default: + throw new IllegalArgumentException("Invalid or unimplemented tile type encountered"); + } + } + + /** + * 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 + */ + private TextureRegion getTextureOnSheet(int x, int y) { + final int tileTextureHeight = 300, tileTextureWidth = 300; + return new TextureRegion(textureSheet, x*tileTextureWidth, y*tileTextureHeight, + tileTextureWidth, tileTextureHeight); + } + + /** + * Checks whether a tile has textures for different rotations + * + * For a tile without a rotation 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 + */ + public boolean hasRotatedTexture(Tile tile) { + switch (tile.getTileType()) { + case TILE: + case HOLE: + case COGWHEEL_RIGHT: + case COGWHEEL_LEFT: + case FLAG_1: + case FLAG_2: + case FLAG_3: + case FLAG_4: + case WRENCH: + case WRENCH_AND_HAMMER: + case DEATH_TILE: + return false; + case TRANSPORT_BAND_SLOW: + case TRANSPORT_BAND_SLOW_RIGHT: + case TRANSPORT_BAND_SLOW_LEFT: + case TRANSPORT_BAND_SLOW_SIDE_ENTRANCES: + case TRANSPORT_BAND_SLOW_SIDE_ENTRANCE_LEFT: + case TRANSPORT_BAND_SLOW_SIDE_ENTRANCE_RIGHT: + case TRANSPORT_BAND_FAST: + case TRANSPORT_BAND_FAST_RIGHT: + case TRANSPORT_BAND_FAST_LEFT: + case TRANSPORT_BAND_FAST_SIDE_ENTRANCES: + case TRANSPORT_BAND_FAST_SIDE_ENTRANCE_LEFT: + case TRANSPORT_BAND_FAST_SIDE_ENTRANCE_RIGHT: + return true; + default: + throw new IllegalArgumentException("Invalid tile type encountered"); + } + } +} diff --git a/src/main/java/inf112/fiasko/roborally/element_properties/Wall.java b/src/main/java/inf112/fiasko/roborally/element_properties/Wall.java deleted file mode 100644 index fb8c8be..0000000 --- a/src/main/java/inf112/fiasko/roborally/element_properties/Wall.java +++ /dev/null @@ -1,39 +0,0 @@ -package inf112.fiasko.roborally.element_properties; - -public class Wall { - /** - * This class is a representation of a wall - */ - private WallType wall; - private Direction direction; - - /** - * Initializes the wall - * @param wall gives the type of wall eks. wall normal or wall corner - * @param direction gives the direction the wall is facing. - */ - public Wall (WallType wall,Direction direction){ - this.wall = wall; - this.direction = direction; - } - - /** - * Gets the type of the wall - * @return the wall type - */ - public WallType getWallType() { - return wall; - } - - /** - * Gets the direction of the wall - * @return the direction of the wall - */ - public Direction getDirection(){ - return direction; - } - - - - -} diff --git a/src/main/java/inf112/fiasko/roborally/objects/Robot.java b/src/main/java/inf112/fiasko/roborally/objects/Robot.java new file mode 100644 index 0000000..4e0ae97 --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/objects/Robot.java @@ -0,0 +1,43 @@ +package inf112.fiasko.roborally.objects; + +import inf112.fiasko.roborally.element_properties.Position; + +/** + * this class represents a robot + */ +public class Robot { + private int robotDamageTaken = 0; + private int playerId; //might not be needed + private boolean inPowerDown = false; + private int lastFlagVisited = 0; + private Position backupPosition; + private Position currentPosition; + + + public Robot (int playerId, Position spawnPosition){ + this.playerId=playerId; + this.backupPosition = spawnPosition; + this.currentPosition = spawnPosition; + } + + + public int getDamage(){ + return robotDamageTaken; + } + public void setDamage (int damage){ + this.robotDamageTaken = damage; + } + public Position getPosition(){ + return currentPosition; + } + public void setPosition( Position newPosition ){ + this.currentPosition = newPosition; + } + public void setPowerDown(Boolean powerDownStatus){ + this.inPowerDown = powerDownStatus; + } + public Boolean isInPowerDown(){ + return inPowerDown; + } + +} diff --git a/src/main/java/inf112/fiasko/roborally/objects/Tile.java b/src/main/java/inf112/fiasko/roborally/objects/Tile.java index 1022d6d..8522f59 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Tile.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Tile.java @@ -3,38 +3,38 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.Direction; import inf112.fiasko.roborally.element_properties.TileType; +/** + * This class represents a simple tile + */ public class Tile { - /** - * tileType stores the type of the specific tile. - */ private TileType tileType; - /** - * direction stores the direction of the specific tile. - */ private Direction direction; /** - * - * @param tileType sets the type of the tile. - * @param direction sets the direction the tile is facing. + * Instantiates a new tile + * @param tileType The type of the tile + * @param direction The direction of the tile */ public Tile(TileType tileType, Direction direction) { + if (direction.getDirectionID() % 2 == 0) { + throw new IllegalArgumentException("Invalid direction for tile submitted"); + } this.tileType = tileType; this.direction = direction; } /** - * - * @return the type of the specific tile. + * Gets the tile type of the tile + * @return The tile's tile type */ public TileType getTileType() { return tileType; } /** - * - * @return the direction of the specific tile. + * Gets the direction of the tile + * @return The tile's direction */ public Direction getDirection() { return direction; diff --git a/src/main/java/inf112/fiasko/roborally/objects/Wall.java b/src/main/java/inf112/fiasko/roborally/objects/Wall.java new file mode 100644 index 0000000..2057ec8 --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/objects/Wall.java @@ -0,0 +1,39 @@ +package inf112.fiasko.roborally.objects; + +import inf112.fiasko.roborally.element_properties.Direction; +import inf112.fiasko.roborally.element_properties.WallType; + +/** + * This class represents a wall + */ +public class Wall { + + private WallType wallType; + private Direction direction; + + /** + * Initializes a wall + * @param wallType The type of the wall + * @param direction The direction of the wall + */ + public Wall (WallType wallType, Direction direction) { + this.wallType = wallType; + this.direction = direction; + } + + /** + * Gets the type of the wall + * @return The wall type + */ + public WallType getWallType() { + return wallType; + } + + /** + * Gets the direction of the wall + * @return The direction of the wall + */ + public Direction getDirection(){ + return direction; + } +} diff --git a/src/test/java/inf112/fiasko/roborally/DirectionTest.java b/src/test/java/inf112/fiasko/roborally/element_properties/DirectionTest.java similarity index 97% rename from src/test/java/inf112/fiasko/roborally/DirectionTest.java rename to src/test/java/inf112/fiasko/roborally/element_properties/DirectionTest.java index 987f1fb..9a95c51 100644 --- a/src/test/java/inf112/fiasko/roborally/DirectionTest.java +++ b/src/test/java/inf112/fiasko/roborally/element_properties/DirectionTest.java @@ -1,4 +1,4 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.element_properties; import inf112.fiasko.roborally.element_properties.Direction; import org.junit.Test; diff --git a/src/test/java/inf112/fiasko/roborally/PositionTest.java b/src/test/java/inf112/fiasko/roborally/element_properties/PositionTest.java similarity index 90% rename from src/test/java/inf112/fiasko/roborally/PositionTest.java rename to src/test/java/inf112/fiasko/roborally/element_properties/PositionTest.java index 825e0c5..b0b05ae 100644 --- a/src/test/java/inf112/fiasko/roborally/PositionTest.java +++ b/src/test/java/inf112/fiasko/roborally/element_properties/PositionTest.java @@ -1,4 +1,4 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.element_properties; import inf112.fiasko.roborally.element_properties.Position; import org.junit.Before; diff --git a/src/test/java/inf112/fiasko/roborally/TileTypeTest.java b/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java similarity index 96% rename from src/test/java/inf112/fiasko/roborally/TileTypeTest.java rename to src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java index 266c6b3..368e941 100644 --- a/src/test/java/inf112/fiasko/roborally/TileTypeTest.java +++ b/src/test/java/inf112/fiasko/roborally/element_properties/TileTypeTest.java @@ -1,4 +1,4 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.element_properties; import inf112.fiasko.roborally.element_properties.TileType; import org.junit.Test; diff --git a/src/test/java/inf112/fiasko/roborally/WallTypeTest.java b/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java similarity index 97% rename from src/test/java/inf112/fiasko/roborally/WallTypeTest.java rename to src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java index 8ae480d..9236c87 100644 --- a/src/test/java/inf112/fiasko/roborally/WallTypeTest.java +++ b/src/test/java/inf112/fiasko/roborally/element_properties/WallTypeTest.java @@ -1,4 +1,4 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.element_properties; import inf112.fiasko.roborally.element_properties.TileType; import inf112.fiasko.roborally.element_properties.WallType; diff --git a/src/test/java/inf112/fiasko/roborally/GameTest.java b/src/test/java/inf112/fiasko/roborally/game/GameTest.java similarity index 95% rename from src/test/java/inf112/fiasko/roborally/GameTest.java rename to src/test/java/inf112/fiasko/roborally/game/GameTest.java index 9441102..2e2ae88 100644 --- a/src/test/java/inf112/fiasko/roborally/GameTest.java +++ b/src/test/java/inf112/fiasko/roborally/game/GameTest.java @@ -1,4 +1,4 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.game; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/inf112/fiasko/roborally/DrawableObjectTest.java b/src/test/java/inf112/fiasko/roborally/objects/DrawableObjectTest.java similarity index 98% rename from src/test/java/inf112/fiasko/roborally/DrawableObjectTest.java rename to src/test/java/inf112/fiasko/roborally/objects/DrawableObjectTest.java index 7c767d3..bc106af 100644 --- a/src/test/java/inf112/fiasko/roborally/DrawableObjectTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/DrawableObjectTest.java @@ -1,4 +1,4 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.objects.DrawableObject; import inf112.fiasko.roborally.element_properties.GameTexture; diff --git a/src/test/java/inf112/fiasko/roborally/objects/RobotTest.java b/src/test/java/inf112/fiasko/roborally/objects/RobotTest.java new file mode 100644 index 0000000..4182741 --- /dev/null +++ b/src/test/java/inf112/fiasko/roborally/objects/RobotTest.java @@ -0,0 +1,22 @@ +package inf112.fiasko.roborally.objects; + +import inf112.fiasko.roborally.element_properties.Position; +import inf112.fiasko.roborally.objects.Robot; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class RobotTest { + @Test + public void testRobotGetDamageOnInitializedRobot(){ + Position robotPosition = new Position(3,6); + Robot testRobotGetDamage = new Robot(6, robotPosition); + assertEquals(0, testRobotGetDamage.getDamage()); + } + @Test + public void testRobotSetDamage(){ + Position robotPosition = new Position(3,6); + Robot testRobotSetDamage = new Robot(6, robotPosition); + testRobotSetDamage.setDamage(2); + assertEquals(2, testRobotSetDamage.getDamage()); + } +} diff --git a/src/test/java/inf112/fiasko/roborally/TileTest.java b/src/test/java/inf112/fiasko/roborally/objects/TileTest.java similarity index 80% rename from src/test/java/inf112/fiasko/roborally/TileTest.java rename to src/test/java/inf112/fiasko/roborally/objects/TileTest.java index 287645f..a6dd76c 100644 --- a/src/test/java/inf112/fiasko/roborally/TileTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/TileTest.java @@ -1,8 +1,7 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.Direction; import inf112.fiasko.roborally.element_properties.TileType; -import inf112.fiasko.roborally.objects.Tile; import org.junit.Before; import org.junit.Test; @@ -38,4 +37,9 @@ public class TileTest { public void getDirectionFromTile2() { assertEquals(Direction.SOUTH, tile2.getDirection()); } + + @Test (expected = IllegalArgumentException.class) + public void invalidTileThrowsException() { + new Tile(TileType.TRANSPORT_BAND_FAST, Direction.NORTH_EAST); + } } \ No newline at end of file diff --git a/src/test/java/inf112/fiasko/roborally/TestWall.java b/src/test/java/inf112/fiasko/roborally/objects/WallTest.java similarity index 91% rename from src/test/java/inf112/fiasko/roborally/TestWall.java rename to src/test/java/inf112/fiasko/roborally/objects/WallTest.java index c94ec6a..5455c2c 100644 --- a/src/test/java/inf112/fiasko/roborally/TestWall.java +++ b/src/test/java/inf112/fiasko/roborally/objects/WallTest.java @@ -1,12 +1,12 @@ -package inf112.fiasko.roborally; +package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.element_properties.Direction; -import inf112.fiasko.roborally.element_properties.Wall; +import inf112.fiasko.roborally.objects.Wall; import inf112.fiasko.roborally.element_properties.WallType; import static org.junit.Assert.assertEquals; import org.junit.Test; -public class TestWall { +public class WallTest { @Test public void testWallGetWallTypeNormal(){ Wall testGetWall = new Wall(WallType.WALL_NORMAL, Direction.NORTH);