mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Rydder opp i PhaseTest og kjører automatisk opprydding
Prøver å forenkle PhaseTest tester der det er mulig
This commit is contained in:
parent
ddc0adc552
commit
fca361b750
@ -12,14 +12,14 @@ import inf112.fiasko.roborally.objects.RoboRallyGame;
|
|||||||
* This class acts as a wrapper around the different screens of the game
|
* This class acts as a wrapper around the different screens of the game
|
||||||
*/
|
*/
|
||||||
public class RoboRallyWrapper extends Game {
|
public class RoboRallyWrapper extends Game {
|
||||||
|
public final int defaultTCPPort = 54555;
|
||||||
|
public final int discoverUDPPort = 54777;
|
||||||
public SpriteBatch batch;
|
public SpriteBatch batch;
|
||||||
public BitmapFont font;
|
public BitmapFont font;
|
||||||
public ScreenManager screenManager;
|
public ScreenManager screenManager;
|
||||||
public RoboRallyGame roboRallyGame;
|
public RoboRallyGame roboRallyGame;
|
||||||
public RoboRallyServer server;
|
public RoboRallyServer server;
|
||||||
public RoboRallyClient client;
|
public RoboRallyClient client;
|
||||||
public int defaultTCPPort = 54555;
|
|
||||||
public int discoverUDPPort = 54777;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
|
@ -15,10 +15,10 @@ public abstract class AbstractScreen implements Screen {
|
|||||||
protected final int applicationWidth = 600;
|
protected final int applicationWidth = 600;
|
||||||
protected final int applicationHeight = 800;
|
protected final int applicationHeight = 800;
|
||||||
|
|
||||||
protected OrthographicCamera camera = new OrthographicCamera();
|
protected final OrthographicCamera camera = new OrthographicCamera();
|
||||||
|
protected final Stage stage = new Stage();
|
||||||
|
protected final InputMultiplexer inputMultiplexer = new InputMultiplexer();
|
||||||
protected Viewport viewport;
|
protected Viewport viewport;
|
||||||
protected Stage stage = new Stage();
|
|
||||||
protected InputMultiplexer inputMultiplexer = new InputMultiplexer();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
|
@ -12,7 +12,9 @@ import inf112.fiasko.roborally.elementproperties.GameState;
|
|||||||
import inf112.fiasko.roborally.elementproperties.RobotID;
|
import inf112.fiasko.roborally.elementproperties.RobotID;
|
||||||
import inf112.fiasko.roborally.elementproperties.TileType;
|
import inf112.fiasko.roborally.elementproperties.TileType;
|
||||||
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
|
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
|
||||||
|
import inf112.fiasko.roborally.objects.DrawableGame;
|
||||||
import inf112.fiasko.roborally.objects.DrawableObject;
|
import inf112.fiasko.roborally.objects.DrawableObject;
|
||||||
|
import inf112.fiasko.roborally.objects.InteractableGame;
|
||||||
import inf112.fiasko.roborally.objects.Player;
|
import inf112.fiasko.roborally.objects.Player;
|
||||||
import inf112.fiasko.roborally.objects.Robot;
|
import inf112.fiasko.roborally.objects.Robot;
|
||||||
import inf112.fiasko.roborally.objects.Tile;
|
import inf112.fiasko.roborally.objects.Tile;
|
||||||
@ -29,6 +31,8 @@ public class BoardActiveScreen extends InteractiveScreen {
|
|||||||
private final int tileDimensions = 64;
|
private final int tileDimensions = 64;
|
||||||
private final int viewPortWidth;
|
private final int viewPortWidth;
|
||||||
private final int viewPortHeight;
|
private final int viewPortHeight;
|
||||||
|
private final DrawableGame drawableGame;
|
||||||
|
private final InteractableGame interactableGame;
|
||||||
private float cameraZoom = 1;
|
private float cameraZoom = 1;
|
||||||
private int cameraX = 0;
|
private int cameraX = 0;
|
||||||
private int cameraY = 0;
|
private int cameraY = 0;
|
||||||
@ -41,9 +45,11 @@ public class BoardActiveScreen extends InteractiveScreen {
|
|||||||
*/
|
*/
|
||||||
public BoardActiveScreen(final RoboRallyWrapper roboRallyWrapper) {
|
public BoardActiveScreen(final RoboRallyWrapper roboRallyWrapper) {
|
||||||
this.roboRallyWrapper = roboRallyWrapper;
|
this.roboRallyWrapper = roboRallyWrapper;
|
||||||
|
this.drawableGame = this.roboRallyWrapper.roboRallyGame;
|
||||||
|
this.interactableGame = this.roboRallyWrapper.roboRallyGame;
|
||||||
|
|
||||||
viewPortWidth = roboRallyWrapper.roboRallyGame.getWidth() * tileDimensions;
|
viewPortWidth = drawableGame.getWidth() * tileDimensions;
|
||||||
viewPortHeight = roboRallyWrapper.roboRallyGame.getHeight() * tileDimensions;
|
viewPortHeight = drawableGame.getHeight() * tileDimensions;
|
||||||
|
|
||||||
camera.setToOrtho(false, viewPortWidth, viewPortHeight);
|
camera.setToOrtho(false, viewPortWidth, viewPortHeight);
|
||||||
camera.position.set(viewPortWidth / 2f, viewPortHeight / 2f, 0);
|
camera.position.set(viewPortWidth / 2f, viewPortHeight / 2f, 0);
|
||||||
@ -67,7 +73,7 @@ public class BoardActiveScreen extends InteractiveScreen {
|
|||||||
drawBoard(roboRallyWrapper.batch);
|
drawBoard(roboRallyWrapper.batch);
|
||||||
roboRallyWrapper.batch.end();
|
roboRallyWrapper.batch.end();
|
||||||
|
|
||||||
switch (roboRallyWrapper.roboRallyGame.getGameState()) {
|
switch (interactableGame.getGameState()) {
|
||||||
case GAME_IS_WON:
|
case GAME_IS_WON:
|
||||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getWinnerScreen(roboRallyWrapper));
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getWinnerScreen(roboRallyWrapper));
|
||||||
break;
|
break;
|
||||||
@ -93,7 +99,7 @@ public class BoardActiveScreen extends InteractiveScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyUp(int keyCode) {
|
public boolean keyUp(int keyCode) {
|
||||||
if (keyCode == Input.Keys.TAB && roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_CARDS) {
|
if (keyCode == Input.Keys.TAB && interactableGame.getGameState() == GameState.CHOOSING_CARDS) {
|
||||||
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getCardChoiceScreen(roboRallyWrapper));
|
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getCardChoiceScreen(roboRallyWrapper));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -163,7 +169,7 @@ public class BoardActiveScreen extends InteractiveScreen {
|
|||||||
*/
|
*/
|
||||||
private void drawBoard(SpriteBatch batch) {
|
private void drawBoard(SpriteBatch batch) {
|
||||||
List<DrawableObject> elementsToDraw =
|
List<DrawableObject> elementsToDraw =
|
||||||
IOUtil.getDrawableObjectsFromGame(roboRallyWrapper.roboRallyGame, tileDimensions, tileDimensions);
|
IOUtil.getDrawableObjectsFromGame(drawableGame, tileDimensions, tileDimensions);
|
||||||
for (DrawableObject object : elementsToDraw) {
|
for (DrawableObject object : elementsToDraw) {
|
||||||
TextureRegion objectTextureRegion = object.getTexture();
|
TextureRegion objectTextureRegion = object.getTexture();
|
||||||
batch.draw(objectTextureRegion.getTexture(), object.getXPosition(), object.getYPosition(),
|
batch.draw(objectTextureRegion.getTexture(), object.getXPosition(), object.getYPosition(),
|
||||||
@ -175,7 +181,7 @@ public class BoardActiveScreen extends InteractiveScreen {
|
|||||||
}
|
}
|
||||||
int index = 1;
|
int index = 1;
|
||||||
//Draws all participating players to the right of the board
|
//Draws all participating players to the right of the board
|
||||||
for (Player player : roboRallyWrapper.roboRallyGame.getPlayers()) {
|
for (Player player : drawableGame.getPlayers()) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
Robot robot = getPlayersRobot(player.getRobotID());
|
Robot robot = getPlayersRobot(player.getRobotID());
|
||||||
if (robot == null) {
|
if (robot == null) {
|
||||||
@ -210,7 +216,7 @@ public class BoardActiveScreen extends InteractiveScreen {
|
|||||||
* @return The robot with the robot id
|
* @return The robot with the robot id
|
||||||
*/
|
*/
|
||||||
private Robot getPlayersRobot(RobotID robotID) {
|
private Robot getPlayersRobot(RobotID robotID) {
|
||||||
for (Robot robot : roboRallyWrapper.roboRallyGame.getAllRobots()) {
|
for (Robot robot : drawableGame.getAllRobots()) {
|
||||||
if (robot.getRobotId() == robotID) {
|
if (robot.getRobotId() == robotID) {
|
||||||
return robot;
|
return robot;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package inf112.fiasko.roborally.gamewrapper.screens;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.InputMultiplexer;
|
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||||
@ -137,11 +136,6 @@ public class CardChoiceScreen extends InteractiveScreen implements Screen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void show() {
|
|
||||||
super.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(float v) {
|
public void render(float v) {
|
||||||
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
|
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
|
||||||
|
@ -3,7 +3,6 @@ package inf112.fiasko.roborally.gamewrapper.screens;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
|
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class RoboRallyClient {
|
public class RoboRallyClient {
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private RoboRallyWrapper wrapper;
|
private final RoboRallyWrapper wrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Robo Rally client
|
* Instantiates a new Robo Rally client
|
||||||
|
@ -39,9 +39,11 @@ public class PhaseTest {
|
|||||||
private Player player4 = new Player(RobotID.ROBOT_4, "Player 4");
|
private Player player4 = new Player(RobotID.ROBOT_4, "Player 4");
|
||||||
private Player player5 = new Player(RobotID.ROBOT_5, "Player 5");
|
private Player player5 = new Player(RobotID.ROBOT_5, "Player 5");
|
||||||
private Player player6 = new Player(RobotID.ROBOT_6, "Player 6");
|
private Player player6 = new Player(RobotID.ROBOT_6, "Player 6");
|
||||||
|
private FakeGame testGame;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws IOException {
|
||||||
|
testGame = new FakeGame();
|
||||||
robots.add(robot1);
|
robots.add(robot1);
|
||||||
robots.add(robot2);
|
robots.add(robot2);
|
||||||
robots.add(robot3);
|
robots.add(robot3);
|
||||||
@ -56,12 +58,8 @@ public class PhaseTest {
|
|||||||
playerList.add(player4);
|
playerList.add(player4);
|
||||||
playerList.add(player5);
|
playerList.add(player5);
|
||||||
playerList.add(player6);
|
playerList.add(player6);
|
||||||
try {
|
|
||||||
board = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
board = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
|
||||||
this.phase = new Phase(board, playerList, 0, null);
|
this.phase = new Phase(board, playerList, 0, null);
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -72,37 +70,39 @@ public class PhaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void playerWinsAfterTouchingAllFlagsInCorrectOrder() throws IOException {
|
public void playerWinsAfterTouchingAllFlagsInCorrectOrder() throws IOException {
|
||||||
FakeGame testGame = new FakeGame();
|
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> player = new ArrayList<>();
|
List<Player> players = getPlayers(1);
|
||||||
RobotID robotID = RobotID.ROBOT_1;
|
RobotID robotID = RobotID.ROBOT_1;
|
||||||
Robot robot = new Robot(robotID, new Position(0, 0));
|
Robot robot = new Robot(robotID, new Position(0, 0));
|
||||||
robots.add(robot);
|
robots.add(robot);
|
||||||
player.add(new Player(robotID, "Player 1"));
|
Phase testPhase = createPhaseAndLoadBoard(players, robots, "boards/win_test_board.txt");
|
||||||
board = BoardLoaderUtil.loadBoard("boards/win_test_board.txt", robots);
|
|
||||||
Phase testPhase = new Phase(board, player, 0, testGame);
|
|
||||||
|
|
||||||
|
//Should have registered 0 flags
|
||||||
assertEquals(0, robot.getLastFlagVisited());
|
assertEquals(0, robot.getLastFlagVisited());
|
||||||
assertFalse(robot.hasTouchedFlagThisTurn());
|
assertFalse(robot.hasTouchedFlagThisTurn());
|
||||||
testPhase.checkAllFlags();
|
testPhase.checkAllFlags();
|
||||||
|
//Should have registered first flag
|
||||||
assertEquals(1, robot.getLastFlagVisited());
|
assertEquals(1, robot.getLastFlagVisited());
|
||||||
assertTrue(robot.hasTouchedFlagThisTurn());
|
assertTrue(robot.hasTouchedFlagThisTurn());
|
||||||
robot.setHasTouchedFlagThisTurn(false);
|
robot.setHasTouchedFlagThisTurn(false);
|
||||||
assertNull(testGame.getWinningPlayerName());
|
assertNull(testGame.getWinningPlayerName());
|
||||||
board.moveRobot(robotID, Direction.EAST);
|
board.moveRobot(robotID, Direction.EAST);
|
||||||
testPhase.checkAllFlags();
|
testPhase.checkAllFlags();
|
||||||
|
//Should have registered second flag
|
||||||
assertEquals(2, robot.getLastFlagVisited());
|
assertEquals(2, robot.getLastFlagVisited());
|
||||||
assertTrue(robot.hasTouchedFlagThisTurn());
|
assertTrue(robot.hasTouchedFlagThisTurn());
|
||||||
assertNull(testGame.getWinningPlayerName());
|
assertNull(testGame.getWinningPlayerName());
|
||||||
robot.setHasTouchedFlagThisTurn(false);
|
robot.setHasTouchedFlagThisTurn(false);
|
||||||
board.moveRobot(robotID, Direction.EAST);
|
board.moveRobot(robotID, Direction.EAST);
|
||||||
testPhase.checkAllFlags();
|
testPhase.checkAllFlags();
|
||||||
|
//Should have registered third flag
|
||||||
assertEquals(3, robot.getLastFlagVisited());
|
assertEquals(3, robot.getLastFlagVisited());
|
||||||
assertTrue(robot.hasTouchedFlagThisTurn());
|
assertTrue(robot.hasTouchedFlagThisTurn());
|
||||||
assertNull(testGame.getWinningPlayerName());
|
assertNull(testGame.getWinningPlayerName());
|
||||||
robot.setHasTouchedFlagThisTurn(false);
|
robot.setHasTouchedFlagThisTurn(false);
|
||||||
board.moveRobot(robotID, Direction.EAST);
|
board.moveRobot(robotID, Direction.EAST);
|
||||||
testPhase.checkAllFlags();
|
testPhase.checkAllFlags();
|
||||||
|
//Should have registered fourth and last flag
|
||||||
assertEquals(4, robot.getLastFlagVisited());
|
assertEquals(4, robot.getLastFlagVisited());
|
||||||
assertTrue(robot.hasTouchedFlagThisTurn());
|
assertTrue(robot.hasTouchedFlagThisTurn());
|
||||||
assertEquals("Player 1", testGame.getWinningPlayerName());
|
assertEquals("Player 1", testGame.getWinningPlayerName());
|
||||||
@ -134,155 +134,85 @@ public class PhaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotFiresLaserAndHitsAnotherRobot() throws InterruptedException {
|
public void robotFiresLaserAndHitsAnotherRobot() throws InterruptedException, IOException {
|
||||||
FakeGame testGame = new FakeGame();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Robot> bot = new ArrayList<>();
|
List<Player> players = getPlayers(2);
|
||||||
List<Player> botPlayer = new ArrayList<>();
|
Robot robot1 = new Robot(RobotID.ROBOT_1, new Position(9, 12));
|
||||||
Position bot1Position = new Position(9, 12);
|
Robot robot2 = new Robot(RobotID.ROBOT_2, new Position(9, 13));
|
||||||
Position bot2Position = new Position(9, 13);
|
robots.add(robot1);
|
||||||
Robot bot1 = new Robot(RobotID.ROBOT_1, bot1Position);
|
robots.add(robot2);
|
||||||
Robot bot2 = new Robot(RobotID.ROBOT_2, bot2Position);
|
|
||||||
bot.add(bot1);
|
|
||||||
bot.add(bot2);
|
|
||||||
Player botPlayer1 = new Player(RobotID.ROBOT_1, "Player 1");
|
|
||||||
Player botPlayer2 = new Player(RobotID.ROBOT_2, "Player 2");
|
|
||||||
botPlayer.add(botPlayer1);
|
|
||||||
botPlayer.add(botPlayer2);
|
|
||||||
|
|
||||||
try {
|
Phase testPhase = createPhaseAndLoadBoard(players, robots, "boards/another_test_map.txt");
|
||||||
board = BoardLoaderUtil.loadBoard("boards/another_test_map.txt", bot);
|
assertEquals(0, robot2.getDamageTaken());
|
||||||
Phase testPhase = new Phase(board, botPlayer, 0, testGame);
|
assertEquals(0, robot1.getDamageTaken());
|
||||||
assertEquals(0, bot2.getDamageTaken());
|
|
||||||
assertEquals(0, bot1.getDamageTaken());
|
|
||||||
testPhase.fireAllLasers();
|
testPhase.fireAllLasers();
|
||||||
assertEquals(0, bot2.getDamageTaken());
|
assertEquals(0, robot2.getDamageTaken());
|
||||||
assertEquals(1, bot1.getDamageTaken());
|
assertEquals(1, robot1.getDamageTaken());
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotFiresLaserAndHitsAWallDoesNotDamageRobotOnOtherSide() throws InterruptedException {
|
public void robotFiresLaserAndHitsAWallDoesNotDamageRobotOnOtherSide() throws InterruptedException, IOException {
|
||||||
FakeGame testGame = new FakeGame();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Robot> bot = new ArrayList<>();
|
List<Player> players = getPlayers(2);
|
||||||
List<Player> botPlayer = new ArrayList<>();
|
Robot robot1 = new Robot(RobotID.ROBOT_1, new Position(9, 11));
|
||||||
Position bot1Position = new Position(9, 11);
|
Robot robot2 = new Robot(RobotID.ROBOT_2, new Position(9, 13));
|
||||||
Position bot2Position = new Position(9, 13);
|
robots.add(robot1);
|
||||||
Robot bot1 = new Robot(RobotID.ROBOT_1, bot1Position);
|
robots.add(robot2);
|
||||||
Robot bot2 = new Robot(RobotID.ROBOT_2, bot2Position);
|
|
||||||
bot.add(bot1);
|
|
||||||
bot.add(bot2);
|
|
||||||
Player botPlayer1 = new Player(RobotID.ROBOT_1, "Player 1");
|
|
||||||
Player botPlayer2 = new Player(RobotID.ROBOT_2, "Player 2");
|
|
||||||
botPlayer.add(botPlayer1);
|
|
||||||
botPlayer.add(botPlayer2);
|
|
||||||
|
|
||||||
try {
|
Phase testPhase = createPhaseAndLoadBoard(players, robots, "boards/another_test_map.txt");
|
||||||
board = BoardLoaderUtil.loadBoard("boards/another_test_map.txt", bot);
|
assertEquals(0, robot2.getDamageTaken());
|
||||||
Phase testPhase = new Phase(board, botPlayer, 0, testGame);
|
assertEquals(0, robot1.getDamageTaken());
|
||||||
assertEquals(0, bot2.getDamageTaken());
|
|
||||||
assertEquals(0, bot1.getDamageTaken());
|
|
||||||
testPhase.fireAllLasers();
|
testPhase.fireAllLasers();
|
||||||
assertEquals(0, bot2.getDamageTaken());
|
assertEquals(0, robot2.getDamageTaken());
|
||||||
assertEquals(0, bot1.getDamageTaken());
|
assertEquals(0, robot1.getDamageTaken());
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotGetsHitBy2Lasers() throws InterruptedException {
|
public void robotGetsHitBy2Lasers() throws InterruptedException, IOException {
|
||||||
FakeGame testGame = new FakeGame();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Robot> bot = new ArrayList<>();
|
List<Player> players = getPlayers(3);
|
||||||
List<Player> botPlayer = new ArrayList<>();
|
Robot robot = new Robot(RobotID.ROBOT_1, new Position(9, 12));
|
||||||
Position bot1Position = new Position(9, 12);
|
Robot robot3 = new Robot(RobotID.ROBOT_3, new Position(8, 12));
|
||||||
Position bot2Position = new Position(9, 13);
|
robots.add(robot);
|
||||||
Position bot3Position = new Position(8, 12);
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(9, 13)));
|
||||||
Robot bot1 = new Robot(RobotID.ROBOT_1, bot1Position);
|
robots.add(robot3);
|
||||||
Robot bot2 = new Robot(RobotID.ROBOT_2, bot2Position);
|
robot3.setFacingDirection(Direction.EAST);
|
||||||
Robot bot3 = new Robot(RobotID.ROBOT_3, bot3Position);
|
|
||||||
bot.add(bot1);
|
|
||||||
bot.add(bot2);
|
|
||||||
bot.add(bot3);
|
|
||||||
Player botPlayer1 = new Player(RobotID.ROBOT_1, "Player 1");
|
|
||||||
Player botPlayer2 = new Player(RobotID.ROBOT_2, "Player 2");
|
|
||||||
Player botPlayer3 = new Player(RobotID.ROBOT_3, "Player 3");
|
|
||||||
botPlayer.add(botPlayer1);
|
|
||||||
botPlayer.add(botPlayer2);
|
|
||||||
botPlayer.add(botPlayer3);
|
|
||||||
bot3.setFacingDirection(Direction.EAST);
|
|
||||||
|
|
||||||
try {
|
Phase testPhase = createPhaseAndLoadBoard(players, robots, "boards/another_test_map.txt");
|
||||||
board = BoardLoaderUtil.loadBoard("boards/another_test_map.txt", bot);
|
assertEquals(0, robot.getDamageTaken());
|
||||||
Phase testPhase = new Phase(board, botPlayer, 0, testGame);
|
|
||||||
assertEquals(0, bot1.getDamageTaken());
|
|
||||||
testPhase.fireAllLasers();
|
testPhase.fireAllLasers();
|
||||||
assertEquals(2, bot1.getDamageTaken());
|
assertEquals(2, robot.getDamageTaken());
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotFiresLaserAndHitsARobotDoesNotDamageRobotOnOtherSide() throws InterruptedException {
|
public void robotFiresLaserAndHitsARobotDoesNotDamageRobotOnOtherSide() throws InterruptedException, IOException {
|
||||||
FakeGame testGame = new FakeGame();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Robot> bot = new ArrayList<>();
|
List<Player> players = getPlayers(3);
|
||||||
List<Player> botPlayer = new ArrayList<>();
|
Robot bot1 = new Robot(RobotID.ROBOT_1, new Position(9, 12));
|
||||||
Position bot1Position = new Position(9, 12);
|
robots.add(bot1);
|
||||||
Position bot2Position = new Position(9, 13);
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(9, 13)));
|
||||||
Position bot3Position = new Position(9, 14);
|
robots.add(new Robot(RobotID.ROBOT_3, new Position(9, 14)));
|
||||||
Robot bot1 = new Robot(RobotID.ROBOT_1, bot1Position);
|
|
||||||
Robot bot2 = new Robot(RobotID.ROBOT_2, bot2Position);
|
|
||||||
Robot bot3 = new Robot(RobotID.ROBOT_3, bot3Position);
|
|
||||||
bot.add(bot1);
|
|
||||||
bot.add(bot2);
|
|
||||||
bot.add(bot3);
|
|
||||||
Player botPlayer1 = new Player(RobotID.ROBOT_1, "Player 1");
|
|
||||||
Player botPlayer2 = new Player(RobotID.ROBOT_2, "Player 2");
|
|
||||||
Player botPlayer3 = new Player(RobotID.ROBOT_3, "Player 3");
|
|
||||||
botPlayer.add(botPlayer1);
|
|
||||||
botPlayer.add(botPlayer2);
|
|
||||||
botPlayer.add(botPlayer3);
|
|
||||||
|
|
||||||
try {
|
Phase testPhase = createPhaseAndLoadBoard(players, robots, "boards/another_test_map.txt");
|
||||||
board = BoardLoaderUtil.loadBoard("boards/another_test_map.txt", bot);
|
|
||||||
Phase testPhase = new Phase(board, botPlayer, 0, testGame);
|
|
||||||
assertEquals(0, bot1.getDamageTaken());
|
assertEquals(0, bot1.getDamageTaken());
|
||||||
testPhase.fireAllLasers();
|
testPhase.fireAllLasers();
|
||||||
assertEquals(1, bot1.getDamageTaken());
|
assertEquals(1, bot1.getDamageTaken());
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotGetsRotatedByCog() throws InterruptedException {
|
public void robotGetsRotatedByCog() throws InterruptedException, IOException {
|
||||||
FakeGame testGame = new FakeGame();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Robot> bot = new ArrayList<>();
|
List<Player> players = getPlayers(2);
|
||||||
List<Player> botPlayer = new ArrayList<>();
|
Robot robot1 = new Robot(RobotID.ROBOT_1, new Position(0, 0));
|
||||||
Position bot1Position = new Position(0, 0);
|
robots.add(robot1);
|
||||||
Position bot2Position = new Position(1, 0);
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 0)));
|
||||||
Robot bot1 = new Robot(RobotID.ROBOT_1, bot1Position);
|
|
||||||
Robot bot2 = new Robot(RobotID.ROBOT_2, bot2Position);
|
|
||||||
bot.add(bot1);
|
|
||||||
bot.add(bot2);
|
|
||||||
Player botPlayer1 = new Player(RobotID.ROBOT_1, "Player 1");
|
|
||||||
botPlayer.add(botPlayer1);
|
|
||||||
Player botPlayer2 = new Player(RobotID.ROBOT_2, "Player 2");
|
|
||||||
botPlayer.add(botPlayer2);
|
|
||||||
|
|
||||||
try {
|
Phase testPhase = createPhaseAndLoadBoard(players, robots, "boards/another_test_map.txt");
|
||||||
board = BoardLoaderUtil.loadBoard("boards/another_test_map.txt", bot);
|
|
||||||
Phase testPhase = new Phase(board, botPlayer, 0, testGame);
|
assertEquals(Direction.NORTH, robot1.getFacingDirection());
|
||||||
assertEquals(Direction.NORTH, bot1.getFacingDirection());
|
|
||||||
testPhase.rotateCogwheels();
|
testPhase.rotateCogwheels();
|
||||||
assertEquals(Direction.EAST, bot1.getFacingDirection());
|
assertEquals(Direction.EAST, robot1.getFacingDirection());
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -311,26 +241,12 @@ public class PhaseTest {
|
|||||||
assertEquals(robot6.getRobotId(), board.getRobotOnPosition(new Position(2, 14)));
|
assertEquals(robot6.getRobotId(), board.getRobotOnPosition(new Position(2, 14)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the test board to the variable and creates a new phase
|
|
||||||
*
|
|
||||||
* @param players A list of players participating in the game
|
|
||||||
* @param robots A list of robots on the board
|
|
||||||
* @return A phase object
|
|
||||||
*/
|
|
||||||
private Phase createPhaseAndLoadBoard(List<Player> players, List<Robot> robots) throws IOException {
|
|
||||||
board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
|
|
||||||
return new Phase(board, players, 0, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotsOnConveyorBeltsFacingTheSameEmptyTileDoesNotMove() throws InterruptedException, IOException {
|
public void robotsOnConveyorBeltsFacingTheSameEmptyTileDoesNotMove() throws InterruptedException, IOException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(2);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(8, 11)));
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(8, 11)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(7, 10)));
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(7, 10)));
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
|
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
@ -342,60 +258,56 @@ public class PhaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void robotsOnConveyorBeltsFacingTheSameHoleTileDoesNotMove() throws IOException, InterruptedException {
|
public void robotsOnConveyorBeltsFacingTheSameHoleTileDoesNotMove() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(2);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(6, 7)));
|
Position robot1Position = new Position(6, 7);
|
||||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(7, 8)));
|
Position robot2Position = new Position(7, 8);
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
robots.add(new Robot(RobotID.ROBOT_1, robot1Position));
|
||||||
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
|
robots.add(new Robot(RobotID.ROBOT_2, robot2Position));
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
|
|
||||||
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(6, 7)));
|
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(robot1Position));
|
||||||
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(7, 8)));
|
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(robot2Position));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotOnConveyorBeltsFacingWallDoesNotMove() throws IOException, InterruptedException {
|
public void robotOnConveyorBeltsFacingWallDoesNotMove() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(1);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1)));
|
Position robotPosition = new Position(1, 1);
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
robots.add(new Robot(RobotID.ROBOT_1, robotPosition));
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
|
|
||||||
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(1, 1)));
|
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(robotPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotBehindAnotherRobotOnConveyorBeltsFacingWallDoesNotMove() throws IOException, InterruptedException {
|
public void robotBehindAnotherRobotOnConveyorBeltsFacingWallDoesNotMove() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(2);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1)));
|
Position robot1Position = new Position(1, 1);
|
||||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 2)));
|
Position robot2Position = new Position(1, 2);
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
robots.add(new Robot(RobotID.ROBOT_1, robot1Position));
|
||||||
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
|
robots.add(new Robot(RobotID.ROBOT_2, robot2Position));
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
|
|
||||||
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(1, 1)));
|
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(robot1Position));
|
||||||
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(1, 2)));
|
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(robot2Position));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void robotBehindOtherRobotsOnSlowConveyorBeltsFacingEmptyTilesMoves() throws IOException, InterruptedException {
|
public void robotBehindOtherRobotsOnSlowConveyorBeltsFacingEmptyTilesMoves() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(4);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(5, 7)));
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(5, 7)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(5, 8)));
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(5, 8)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_3, new Position(5, 9)));
|
robots.add(new Robot(RobotID.ROBOT_3, new Position(5, 9)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_4, new Position(5, 10)));
|
robots.add(new Robot(RobotID.ROBOT_4, new Position(5, 10)));
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_3, "Player 3"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_4, "Player 4"));
|
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
@ -409,15 +321,11 @@ public class PhaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void robotBehindOtherRobotsOnFastConveyorBeltsFacingEmptyTilesMoves() throws IOException, InterruptedException {
|
public void robotBehindOtherRobotsOnFastConveyorBeltsFacingEmptyTilesMoves() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(4);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(4, 7)));
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(4, 7)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(4, 8)));
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(4, 8)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_3, new Position(4, 9)));
|
robots.add(new Robot(RobotID.ROBOT_3, new Position(4, 9)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_4, new Position(4, 10)));
|
robots.add(new Robot(RobotID.ROBOT_4, new Position(4, 10)));
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_3, "Player 3"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_4, "Player 4"));
|
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
@ -432,15 +340,11 @@ public class PhaseTest {
|
|||||||
public void robotBehindOtherRobotsOnConveyorBeltsShapedAsARoundaboutMoves() throws IOException, InterruptedException {
|
public void robotBehindOtherRobotsOnConveyorBeltsShapedAsARoundaboutMoves() throws IOException, InterruptedException {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(4);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 8)));
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 8)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_2, new Position(2, 8)));
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(2, 8)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_3, new Position(2, 9)));
|
robots.add(new Robot(RobotID.ROBOT_3, new Position(2, 9)));
|
||||||
robots.add(new Robot(RobotID.ROBOT_4, new Position(1, 9)));
|
robots.add(new Robot(RobotID.ROBOT_4, new Position(1, 9)));
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_3, "Player 3"));
|
|
||||||
players.add(new Player(RobotID.ROBOT_4, "Player 4"));
|
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
@ -456,9 +360,8 @@ public class PhaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void robotOnConveyorBeltFacingHoleMovesAndDies() throws IOException, InterruptedException {
|
public void robotOnConveyorBeltFacingHoleMovesAndDies() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(1);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(6, 7)));
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(6, 7)));
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
@ -471,9 +374,8 @@ public class PhaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void robotOnConveyorBeltFacingOutOfMapMovesAndDies() throws IOException, InterruptedException {
|
public void robotOnConveyorBeltFacingOutOfMapMovesAndDies() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(1);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(7, 0)));
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(7, 0)));
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
@ -485,9 +387,8 @@ public class PhaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void robotOnConveyorBeltFacingOutOfMapMovesIntoWallIsBlocked() throws IOException, InterruptedException {
|
public void robotOnConveyorBeltFacingOutOfMapMovesIntoWallIsBlocked() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(1);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(0, 0)));
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(0, 0)));
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
@ -499,9 +400,8 @@ public class PhaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void robotOnConveyorBeltFacingOutOfMapWithOneTileBetweenCanBeMoved() throws IOException, InterruptedException {
|
public void robotOnConveyorBeltFacingOutOfMapWithOneTileBetweenCanBeMoved() throws IOException, InterruptedException {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
List<Player> players = new ArrayList<>();
|
List<Player> players = getPlayers(1);
|
||||||
robots.add(new Robot(RobotID.ROBOT_1, new Position(10, 10)));
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(10, 10)));
|
||||||
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
|
||||||
|
|
||||||
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
Phase testPhase = createPhaseAndLoadBoard(players, robots);
|
||||||
testPhase.moveAllConveyorBelts();
|
testPhase.moveAllConveyorBelts();
|
||||||
@ -509,4 +409,42 @@ public class PhaseTest {
|
|||||||
assertTrue(board.isRobotAlive(RobotID.ROBOT_1));
|
assertTrue(board.isRobotAlive(RobotID.ROBOT_1));
|
||||||
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(10, 11)));
|
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(10, 11)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of a specific number of players
|
||||||
|
*
|
||||||
|
* @param numberOfPlayers The number of players to generate
|
||||||
|
* @return A list of players
|
||||||
|
*/
|
||||||
|
private List<Player> getPlayers(int numberOfPlayers) {
|
||||||
|
List<Player> players = new ArrayList<>();
|
||||||
|
for (int i = 1; i <= numberOfPlayers; i++) {
|
||||||
|
players.add(new Player(RobotID.getRobotIDFromID(i), "Player " + i));
|
||||||
|
}
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a board to the variable and creates a new phase
|
||||||
|
*
|
||||||
|
* @param players A list of players participating in the game
|
||||||
|
* @param robots A list of robots on the board
|
||||||
|
* @param boardName The name of the board to load
|
||||||
|
* @return A phase object
|
||||||
|
*/
|
||||||
|
private Phase createPhaseAndLoadBoard(List<Player> players, List<Robot> robots, String boardName) throws IOException {
|
||||||
|
board = BoardLoaderUtil.loadBoard(boardName, robots);
|
||||||
|
return new Phase(board, players, 0, testGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the test board to the variable and creates a new phase
|
||||||
|
*
|
||||||
|
* @param players A list of players participating in the game
|
||||||
|
* @param robots A list of robots on the board
|
||||||
|
* @return A phase object
|
||||||
|
*/
|
||||||
|
private Phase createPhaseAndLoadBoard(List<Player> players, List<Robot> robots) throws IOException {
|
||||||
|
return createPhaseAndLoadBoard(players, robots, "boards/test_board.txt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user