Opprydding av ubrukte klasser og metoder

Fjerner Action.java
Endrer Checkmate.txt tilbake til det offisielle brettet
Endrer Game til å bevege roboten framover i stedet for en spesifikk retning
Fjerner konseptet om døde roboter i Board
Fjerner interface for kort
Fjerner metoder for å sjekke om vegger og roboter har roterte teksturer
Fjerner utkommentert testkode av tekst input
Endrer litt testkode slik at alle roboter er brukt i koden
This commit is contained in:
Kristian Knarvik 2020-02-25 17:45:39 +01:00
parent e51ac1da92
commit 8e60e1558e
10 changed files with 80 additions and 117 deletions

View File

@ -38,8 +38,6 @@ public class GameLauncher extends ApplicationAdapter {
camera.setToOrtho(false, game.getWidth() * tileDimensions, camera.setToOrtho(false, game.getWidth() * tileDimensions,
game.getHeight() * tileDimensions); game.getHeight() * tileDimensions);
batch = new SpriteBatch(); batch = new SpriteBatch();
/*MyTextInputListener listener = new MyTextInputListener();
Gdx.input.getTextInput(listener, "Input name", "", "Name");*/
} }
/** /**
@ -71,15 +69,4 @@ public class GameLauncher extends ApplicationAdapter {
textureSheet.dispose(); textureSheet.dispose();
batch.dispose(); batch.dispose();
} }
/*public static class MyTextInputListener implements Input.TextInputListener {
@Override
public void input (String text) {
System.out.println(text);
}
@Override
public void canceled () {
}
}*/
} }

View File

@ -1,14 +0,0 @@
package inf112.fiasko.roborally.element_properties;
/**
* This enum represents an action on a programming card
*/
public enum Action {
ROTATE_RIGHT,
ROTATE_LEFT,
U_TURN,
MOVE_1,
MOVE_2,
MOVE_3,
BACK_UP
}

View File

@ -1,6 +1,5 @@
package inf112.fiasko.roborally.game; package inf112.fiasko.roborally.game;
import inf112.fiasko.roborally.element_properties.Direction;
import inf112.fiasko.roborally.element_properties.Position; import inf112.fiasko.roborally.element_properties.Position;
import inf112.fiasko.roborally.element_properties.RobotID; import inf112.fiasko.roborally.element_properties.RobotID;
import inf112.fiasko.roborally.objects.Board; import inf112.fiasko.roborally.objects.Board;
@ -47,29 +46,40 @@ public class Game implements IDrawableGame {
gameBoard.rotateRobotRight(RobotID.ROBOT_1); gameBoard.rotateRobotRight(RobotID.ROBOT_1);
gameBoard.rotateRobotRight(RobotID.ROBOT_1); gameBoard.rotateRobotRight(RobotID.ROBOT_1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.SOUTH); gameBoard.moveRobotForward(RobotID.ROBOT_1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.rotateRobotLeft(RobotID.ROBOT_1); gameBoard.rotateRobotLeft(RobotID.ROBOT_1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.EAST); gameBoard.moveRobotForward(RobotID.ROBOT_1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.EAST); gameBoard.moveRobotForward(RobotID.ROBOT_1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.rotateRobotRight(RobotID.ROBOT_1); gameBoard.rotateRobotRight(RobotID.ROBOT_1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_1, Direction.SOUTH); gameBoard.moveRobotForward(RobotID.ROBOT_1);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_2, Direction.EAST); gameBoard.rotateRobotRight(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_2, Direction.WEST); gameBoard.moveRobotForward(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_2, Direction.EAST); gameBoard.rotateRobotRight(RobotID.ROBOT_2);
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_2, Direction.EAST); gameBoard.moveRobotForward(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_2, Direction.WEST); gameBoard.rotateRobotRight(RobotID.ROBOT_2);
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobot(RobotID.ROBOT_2, Direction.WEST); gameBoard.moveRobotForward(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobotForward(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1);
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
gameBoard.rotateRobotRight(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobotForward(RobotID.ROBOT_2);
TimeUnit.SECONDS.sleep(1);
gameBoard.moveRobotForward(RobotID.ROBOT_2);
} }
@Override @Override

View File

@ -19,7 +19,6 @@ public class Board {
private IGrid<Wall> walls; private IGrid<Wall> walls;
private IGrid<Tile> tiles; private IGrid<Tile> tiles;
private Map<RobotID, Robot> robots; private Map<RobotID, Robot> robots;
private List<Robot> deadRobots;
/** /**
* Initializes the board * Initializes the board
@ -38,7 +37,6 @@ public class Board {
} }
this.robots.put(robot.getRobotId(), robot); this.robots.put(robot.getRobotId(), robot);
} }
this.deadRobots = new ArrayList<>();
this.boardWidth = tiles.getWidth(); this.boardWidth = tiles.getWidth();
this.boardHeight = tiles.getHeight(); this.boardHeight = tiles.getHeight();
this.walls = walls; this.walls = walls;
@ -61,18 +59,6 @@ public class Board {
return boardWidth; return boardWidth;
} }
/**
* Moves all dead robots to their backups and makes them part of the board again
*/
public void respawnRobots() {
for (Robot robot : deadRobots) {
robot.setPosition(robot.getBackupPosition());
robot.setFacingDirection(Direction.NORTH);
robots.put(robot.getRobotId(), robot);
}
deadRobots = new ArrayList<>();
}
/** /**
* Gets all alive robots from the board * Gets all alive robots from the board
* @return A list of alive robots * @return A list of alive robots
@ -103,7 +89,6 @@ public class Board {
*/ */
public void removeDeadRobotFromBoard(Robot robot) { public void removeDeadRobotFromBoard(Robot robot) {
robots.remove(robot.getRobotId()); robots.remove(robot.getRobotId());
deadRobots.add(robot);
} }
/** /**
@ -126,6 +111,14 @@ public class Board {
robot.setFacingDirection(newDirection); robot.setFacingDirection(newDirection);
} }
/**
* Moves a robot one unit forward according to the direction it's currently facing
* @param robotID The robot to move
*/
public void moveRobotForward(RobotID robotID) {
moveRobot(robotID, robots.get(robotID).getFacingDirection());
}
/** /**
* Moves a robot one unit in a specified direction * Moves a robot one unit in a specified direction
* @param robotID ID of the robot to move * @param robotID ID of the robot to move

View File

@ -1,20 +0,0 @@
package inf112.fiasko.roborally.objects;
/**
* This Interface describes a card without a card suit
* @param <S> The value type
* @param <T> The symbol type
*/
public interface ICardWithoutSuit<S,T> {
/**
* Gets the value of the card
* @return The card value
*/
S getValue();
/**
* Gets the symbol of the card
* @return The card symbol
*/
T getSymbol();
}

View File

@ -108,7 +108,7 @@ public final class IOUtil {
Direction direction; Direction direction;
if (element.getClass().isAssignableFrom(Robot.class)) { if (element.getClass().isAssignableFrom(Robot.class)) {
Robot robot = (Robot) element; Robot robot = (Robot) element;
hasRotatedTexture = TextureConverterUtil.hasRotatedTexture(robot); hasRotatedTexture = false;
direction = robot.getFacingDirection(); direction = robot.getFacingDirection();
} else if (element.getClass().isAssignableFrom(Tile.class)) { } else if (element.getClass().isAssignableFrom(Tile.class)) {
Tile tile = (Tile) element; Tile tile = (Tile) element;
@ -116,7 +116,7 @@ public final class IOUtil {
direction = tile.getDirection(); direction = tile.getDirection();
} else if (element.getClass().isAssignableFrom(Wall.class)) { } else if (element.getClass().isAssignableFrom(Wall.class)) {
Wall wall = (Wall) element; Wall wall = (Wall) element;
hasRotatedTexture = TextureConverterUtil.hasRotatedTexture(wall); hasRotatedTexture = true;
direction = wall.getDirection(); direction = wall.getDirection();
} else { } else {
throw new IllegalArgumentException("Unknown element type passed to function."); throw new IllegalArgumentException("Unknown element type passed to function.");

View File

@ -110,24 +110,6 @@ public final class TextureConverterUtil {
return tileSheetTileHasRotatedTextureMappings.get(tile.getTileType()); return tileSheetTileHasRotatedTextureMappings.get(tile.getTileType());
} }
/**
* Checks whether a wall has textures for different rotations
* @param wall The wall to check
* @return True if rotated versions of the texture exists. False otherwise
*/
public static boolean hasRotatedTexture(Wall wall) {
return true;
}
/**
* Checks whether a robot has textures for different rotations
* @param robot The robot to check
* @return True if rotated versions of the texture exists. False otherwise
*/
public static boolean hasRotatedTexture(Robot robot) {
return false;
}
/** /**
* Loads mappings between a tile and texture * Loads mappings between a tile and texture
* *

View File

@ -1,4 +1,4 @@
12 13 12 12
01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 21;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 21;1
01;1 12;3 11;3 11;3 11;3 11;3 11;3 11;3 11;3 11;3 12;5 01;1 01;1 12;3 11;3 11;3 11;3 11;3 11;3 11;3 11;3 11;3 12;5 01;1
01;1 11;1 05;3 01;1 05;3 01;1 05;7 17;1 05;7 01;1 11;5 01;1 01;1 11;1 05;3 01;1 05;3 01;1 05;7 17;1 05;7 01;1 11;5 01;1
@ -11,7 +11,6 @@
01;1 11;1 01;1 05;3 01;1 05;3 01;1 05;7 01;1 05;7 11;5 01;1 01;1 11;1 01;1 05;3 01;1 05;3 01;1 05;7 01;1 05;7 11;5 01;1
01;1 12;1 11;7 11;7 11;7 11;7 11;7 11;7 11;7 11;7 12;7 01;1 01;1 12;1 11;7 11;7 11;7 11;7 11;7 11;7 11;7 11;7 12;7 01;1
21;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 21;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 1;1 0 1;1 0 0 1;1 0 1;1 0 0 0 0 1;1 0 1;1 0 0 1;1 0 1;1 0 0
0 0 0 1;5 0 1;5 1;5 0 1;5 0 0 0 0 0 0 1;5 0 1;5 1;5 0 1;5 0 0 0
1;7 0 0 0 0 0 0 0 0 0 0 1;3 1;7 0 0 0 0 0 0 0 0 0 0 1;3
@ -24,4 +23,3 @@
1;7 0 0 0 0 0 0 0 0 0 0 1;3 1;7 0 0 0 0 0 0 0 0 0 0 1;3
0 0 0 1;1 0 1;1 1;1 0 1;1 0 0 0 0 0 0 1;1 0 1;1 1;1 0 1;1 0 0 0
0 0 1;5 0 1;5 0 0 1;5 0 1;5 0 0 0 0 1;5 0 1;5 0 0 1;5 0 1;5 0 0
0 0 0 0 0 0 0 0 0 0 0 0

View File

@ -13,12 +13,16 @@ import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class BoardTest { public class BoardTest {
private Grid<Tile> tileGrid; private Grid<Tile> tileGrid;
private Grid<Wall> wallGrid; private Grid<Wall> wallGrid;
private Position someValidPosition; private Position someValidPosition1;
private Position someValidPosition5;
private Position someValidPosition6;
private Position someValidPosition7;
private List<Robot> robotList; private List<Robot> robotList;
private Board board; private Board board;
@ -26,16 +30,38 @@ public class BoardTest {
public void setUp() { public void setUp() {
tileGrid = new Grid<>(5, 5, new Tile(TileType.TILE, Direction.NORTH)); tileGrid = new Grid<>(5, 5, new Tile(TileType.TILE, Direction.NORTH));
wallGrid = new Grid<>(5, 5); wallGrid = new Grid<>(5, 5);
someValidPosition = new Position(2, 2); someValidPosition1 = new Position(2, 2);
Position someValidPosition2 = new Position(2, 1);
Position someValidPosition3 = new Position(2, 3);
Position someValidPosition4 = new Position(2, 4);
someValidPosition5 = new Position(3, 1);
someValidPosition6 = new Position(3, 2);
someValidPosition7 = new Position(3, 3);
Position someValidPosition8 = new Position(3, 4);
robotList = new ArrayList<>(); robotList = new ArrayList<>();
robotList.add(new Robot(RobotID.ROBOT_1, someValidPosition)); robotList.add(new Robot(RobotID.ROBOT_1, someValidPosition1));
robotList.add(new Robot(RobotID.ROBOT_2, someValidPosition)); robotList.add(new Robot(RobotID.ROBOT_2, someValidPosition2));
robotList.add(new Robot(RobotID.ROBOT_3, someValidPosition3));
robotList.add(new Robot(RobotID.ROBOT_4, someValidPosition4));
robotList.add(new Robot(RobotID.ROBOT_5, someValidPosition5));
robotList.add(new Robot(RobotID.ROBOT_6, someValidPosition6));
robotList.add(new Robot(RobotID.ROBOT_7, someValidPosition7));
robotList.add(new Robot(RobotID.ROBOT_8, someValidPosition8));
wallGrid.setElement(2, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); wallGrid.setElement(2, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH));
wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST)); wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST));
wallGrid.setElement(1, 2, new Wall(WallType.WALL_CORNER, Direction.NORTH_EAST)); wallGrid.setElement(1, 2, new Wall(WallType.WALL_CORNER, Direction.NORTH_EAST));
board = new Board(tileGrid, wallGrid, robotList); board = new Board(tileGrid, wallGrid, robotList);
} }
@Test
public void robotCanPushRobots() {
board.moveRobot(RobotID.ROBOT_5, Direction.SOUTH);
assertNotEquals(someValidPosition5, robotList.get(4).getPosition());
assertNotEquals(someValidPosition6, robotList.get(5).getPosition());
assertNotEquals(someValidPosition7, robotList.get(6).getPosition());
assertFalse(board.getAliveRobots().contains(robotList.get(7)));
}
@Test @Test
public void robotCanMove() { public void robotCanMove() {
assertTrue(board.moveRobot(RobotID.ROBOT_1, Direction.SOUTH)); assertTrue(board.moveRobot(RobotID.ROBOT_1, Direction.SOUTH));
@ -71,15 +97,15 @@ public class BoardTest {
@Test @Test
public void robotCanBeRotatedRight() { public void robotCanBeRotatedRight() {
assertEquals(Direction.NORTH, robotList.get(1).getFacingDirection()); assertEquals(Direction.NORTH, robotList.get(0).getFacingDirection());
board.rotateRobotRight(RobotID.ROBOT_2); board.rotateRobotRight(RobotID.ROBOT_1);
assertEquals(Direction.EAST, robotList.get(1).getFacingDirection()); assertEquals(Direction.EAST, robotList.get(0).getFacingDirection());
board.rotateRobotRight(RobotID.ROBOT_2); board.rotateRobotRight(RobotID.ROBOT_1);
assertEquals(Direction.SOUTH, robotList.get(1).getFacingDirection()); assertEquals(Direction.SOUTH, robotList.get(0).getFacingDirection());
board.rotateRobotRight(RobotID.ROBOT_2); board.rotateRobotRight(RobotID.ROBOT_1);
assertEquals(Direction.WEST, robotList.get(1).getFacingDirection()); assertEquals(Direction.WEST, robotList.get(0).getFacingDirection());
board.rotateRobotRight(RobotID.ROBOT_2); board.rotateRobotRight(RobotID.ROBOT_1);
assertEquals(Direction.NORTH, robotList.get(1).getFacingDirection()); assertEquals(Direction.NORTH, robotList.get(0).getFacingDirection());
} }
@Test (expected = IllegalArgumentException.class) @Test (expected = IllegalArgumentException.class)
@ -90,16 +116,17 @@ public class BoardTest {
@Test (expected = IllegalArgumentException.class) @Test (expected = IllegalArgumentException.class)
public void multipleRobotsWithSameIDThrowsError() { public void multipleRobotsWithSameIDThrowsError() {
Robot robot = new Robot(RobotID.ROBOT_1, someValidPosition); Robot robot = new Robot(RobotID.ROBOT_1, someValidPosition1);
robotList.add(robot); robotList.add(robot);
new Board(tileGrid, wallGrid, robotList); new Board(tileGrid, wallGrid, robotList);
} }
@Test @Test
public void killRobotReducesAmountOfLivesByOne() { public void killRobotReducesAmountOfLivesByOne() {
Robot robot = board.getAliveRobots().get(0); Robot robot = board.getAliveRobots().get(1);
for (int i = 0; i < 3; i++) { assertEquals(3, robot.getAmountOfLives());
board.moveRobot(robot.getRobotId(), Direction.SOUTH); robot.setPosition(new Position(0, 0));
} board.moveRobot(robot.getRobotId(), Direction.NORTH);
assertEquals(2, robot.getAmountOfLives()); assertEquals(2, robot.getAmountOfLives());
} }
} }

View File

@ -10,7 +10,7 @@ import org.junit.Test;
public class RobotTest { public class RobotTest {
private Position robotPosition; private Position robotPosition;
private Robot testRobot; private Robot testRobot;
private int nextFlag = 1; private final int nextFlag = 1;
@Before @Before
public void setUp() { public void setUp() {