This commit is contained in:
Torbjørn Lunde Jensen 2020-02-20 13:36:00 +01:00
commit ee308900c2
14 changed files with 336 additions and 63 deletions

View File

@ -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");
}
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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);