diff --git a/README.md b/README.md
index 48aed3e..541016b 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,6 @@ Dette vil også kjøre alle tester i koden
### Kjøreprosedyre
```shell script
cd target
-java -jar roborally-0.2-alpha-jar-with-dependencies.jar
+java -jar roborally-0.4-alpha-jar-with-dependencies.jar
```
Den produserte .jar filen kan alternativt flyttes til en annen mappe og dobbeltklikkes for å kjøres.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 7b08cfa..96efbcd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
inf112.fiasko.roborally
roborally
- 0.3-alpha
+ 0.4-alpha
jar
diff --git a/src/main/java/inf112/fiasko/roborally/Main.java b/src/main/java/inf112/fiasko/roborally/Main.java
index 50ceb62..24442bc 100644
--- a/src/main/java/inf112/fiasko/roborally/Main.java
+++ b/src/main/java/inf112/fiasko/roborally/Main.java
@@ -4,11 +4,13 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
-
+/**
+ * The mail class which runs the game
+ */
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
- cfg.title = "Game Board";
+ cfg.title = "Robo Rally";
cfg.width = 900;
cfg.height = 900;
cfg.samples = 3;
diff --git a/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java b/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java
index 47ea1ae..7006db1 100644
--- a/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java
+++ b/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java
@@ -6,7 +6,7 @@ package inf112.fiasko.roborally.elementproperties;
public enum GameState {
/**
- * At the absolute start of the game, before anything has happended
+ * At the absolute start of the game, before anything has happened
*/
BEGINNING_OF_GAME,
/**
@@ -45,9 +45,13 @@ public enum GameState {
* Indicates that the game is no longer running
*/
EXITED,
-
+ /**
+ * Indicates that the game is in the process of skipping the power down screen
+ */
SKIP_POWER_DOWN_SCREEN,
-
+ /**
+ * Indicates that the game is in the process of skipping the stay in power down screen
+ */
SKIP_STAY_IN_POWER_DOWN
}
diff --git a/src/main/java/inf112/fiasko/roborally/elementproperties/ParticleType.java b/src/main/java/inf112/fiasko/roborally/elementproperties/ParticleType.java
index e830e91..fd0f624 100644
--- a/src/main/java/inf112/fiasko/roborally/elementproperties/ParticleType.java
+++ b/src/main/java/inf112/fiasko/roborally/elementproperties/ParticleType.java
@@ -1,5 +1,8 @@
package inf112.fiasko.roborally.elementproperties;
+/**
+ * This enum represents all possible particle types
+ */
public enum ParticleType {
/**
* The beam emitting from a single laser
diff --git a/src/main/java/inf112/fiasko/roborally/elementproperties/TileType.java b/src/main/java/inf112/fiasko/roborally/elementproperties/TileType.java
index 965567f..68eba0b 100644
--- a/src/main/java/inf112/fiasko/roborally/elementproperties/TileType.java
+++ b/src/main/java/inf112/fiasko/roborally/elementproperties/TileType.java
@@ -68,24 +68,81 @@ public enum TileType {
* A fast conveyor belt with one entrance on the right and one from behind
*/
CONVEYOR_BELT_FAST_SIDE_ENTRANCE_RIGHT(16),
+ /**
+ * The first flag a robot has to visit to win the game
+ */
FLAG_1(17),
+ /**
+ * The second flag a robot has to visit to win the game
+ */
FLAG_2(18),
+ /**
+ * The third flag a robot has to visit to win the game
+ */
FLAG_3(19),
+ /**
+ * The fourth flag a robot has to visit to win the game
+ */
FLAG_4(20),
+ /**
+ * A wrench which repairs a robot
+ */
WRENCH(21),
+ /**
+ * A wrench and hammer which repairs a robot
+ */
WRENCH_AND_HAMMER(22),
+ /**
+ * The spawn location belonging to the first robot
+ */
ROBOT_SPAWN_1(23),
+ /**
+ * The spawn location belonging to the second robot
+ */
ROBOT_SPAWN_2(24),
+ /**
+ * The spawn location belonging to the third robot
+ */
ROBOT_SPAWN_3(25),
+ /**
+ * The spawn location belonging to the fourth robot
+ */
ROBOT_SPAWN_4(26),
+ /**
+ * The spawn location belonging to the fifth robot
+ */
ROBOT_SPAWN_5(27),
+ /**
+ * The spawn location belonging to the sixth robot
+ */
ROBOT_SPAWN_6(28),
+ /**
+ * The spawn location belonging to the seventh robot
+ */
ROBOT_SPAWN_7(29),
+ /**
+ * The spawn location belonging to the eight robot
+ */
ROBOT_SPAWN_8(30),
+ /**
+ * A pit without edges a robot may fall into
+ */
PIT_EMPTY(31),
+ /**
+ * A pit with all edges a robot may fall into
+ */
PIT_FULL(32),
+ /**
+ * A pit with one edge a robot may fall into
+ */
PIT_NORMAL(33),
+ /**
+ * A pit with two connected edges the robot may fall into
+ */
PIT_CORNER(34),
+ /**
+ * A pit with three edges the robot may fall into
+ */
PIT_U(35);
private final int tileTypeID;
diff --git a/src/main/java/inf112/fiasko/roborally/elementproperties/WallType.java b/src/main/java/inf112/fiasko/roborally/elementproperties/WallType.java
index bfc72bc..98870f3 100644
--- a/src/main/java/inf112/fiasko/roborally/elementproperties/WallType.java
+++ b/src/main/java/inf112/fiasko/roborally/elementproperties/WallType.java
@@ -4,9 +4,21 @@ package inf112.fiasko.roborally.elementproperties;
* This enum represents all possible wall types
*/
public enum WallType {
+ /**
+ * A normal wall
+ */
WALL_NORMAL(1),
+ /**
+ * A wall which consists of two connected walls
+ */
WALL_CORNER(2),
+ /**
+ * A wall with a laser
+ */
WALL_LASER_SINGLE(3),
+ /**
+ * A wall with two lasers
+ */
WALL_LASER_DOUBLE(4);
private final int wallTypeID;
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java
index e104062..396c175 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java
@@ -15,7 +15,6 @@ import inf112.fiasko.roborally.gamewrapper.screens.WinnerScreen;
*/
public class ScreenManager {
private BoardActiveScreen boardActiveScreen;
- private PowerDownScreen powerDownScreen;
private LoadingScreen loadingScreen;
private UsernameScreen usernameScreen;
private IPAddressScreen ipAddressScreen;
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java
index 5daff71..7954027 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java
@@ -86,7 +86,6 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper));
break;
case SKIP_STAY_IN_POWER_DOWN:
- System.out.println("Sent false to server");
roboRallyWrapper.client.sendElement(false);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
break;
@@ -212,6 +211,12 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor
}
+ /**
+ * Gets the robot with the corresponding robot id
+ *
+ * @param robotID The robot id to get robot for
+ * @return The robot with the robot id
+ */
private Robot getPlayersRobot(RobotID robotID) {
for (Robot robot : roboRallyWrapper.roboRallyGame.getAllRobots()) {
if (robot.getRobotId() == robotID) {
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/CardChoiceScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/CardChoiceScreen.java
index 04c9988..d3ec659 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/CardChoiceScreen.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/CardChoiceScreen.java
@@ -98,8 +98,6 @@ public class CardChoiceScreen extends InputAdapter implements Screen {
for (int i = 4; i > (4 - lockedCardsInt); i--) {
newProgram.add(oldProgram.get(i));
}
- System.out.println("fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuasdasdasda234234234: " + newProgram.size());
- System.out.println(newProgram);
roboRallyWrapper.roboRallyGame.setProgram(newProgram);
roboRallyWrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN);
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/IPAddressScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/IPAddressScreen.java
index 8bbff05..6c2ebb7 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/IPAddressScreen.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/IPAddressScreen.java
@@ -27,7 +27,7 @@ public class IPAddressScreen extends AbstractScreen {
private final OrthographicCamera camera;
private final Viewport viewport;
private final Stage stage;
- private TextField txtinput;
+ private TextField textInput;
/**
* Instantiates a new ip address screen
@@ -50,7 +50,7 @@ public class IPAddressScreen extends AbstractScreen {
@Override
public void touchUp(InputEvent e, float x, float y, int point, int button) {
try {
- roboRallyWrapper.client = new RoboRallyClient(txtinput.getText(), roboRallyWrapper);
+ roboRallyWrapper.client = new RoboRallyClient(textInput.getText(), roboRallyWrapper);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper));
} catch (IOException ex) {
ex.printStackTrace();
@@ -59,10 +59,10 @@ public class IPAddressScreen extends AbstractScreen {
}
}
});
- txtinput = new TextField("", skin);
- txtinput.setPosition(applicationWidth / 2f - txtinput.getWidth() / 2f, 250);
- txtinput.setSize(150, 40);
- stage.addActor(txtinput);
+ textInput = new TextField("", skin);
+ textInput.setPosition(applicationWidth / 2f - textInput.getWidth() / 2f, 250);
+ textInput.setSize(150, 40);
+ stage.addActor(textInput);
stage.addActor(joinButton);
camera = new OrthographicCamera();
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java
index 8ce4c9c..3c8a526 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java
@@ -46,7 +46,6 @@ public class LoadingScreen extends AbstractScreen {
if (roboRallyWrapper.roboRallyGame != null) {
GameState gameState = roboRallyWrapper.roboRallyGame.getGameState();
- System.out.println(gameState);
if (gameState != GameState.LOADING) {
handleScreenChange(gameState);
}
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java
index 01d0835..08341dd 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java
@@ -11,7 +11,7 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.gamewrapper.SimpleButton;
-import inf112.fiasko.roborally.networking.containers.GameStartInfo;
+import inf112.fiasko.roborally.networking.containers.GameStartInfoResponse;
import inf112.fiasko.roborally.objects.Player;
import inf112.fiasko.roborally.utility.IOUtil;
import com.esotericsoftware.kryonet.Connection;
@@ -48,12 +48,12 @@ public class LobbyScreen extends AbstractScreen {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
roboRallyWrapper.server.startGame();
- Map playernames = roboRallyWrapper.server.getPlayerNames();
- List playerlist = IOUtil.playerGenerator(playernames,
+ Map playerNames = roboRallyWrapper.server.getPlayerNames();
+ List playerList = IOUtil.playerGenerator(playerNames,
roboRallyWrapper.server.getRobotID());
- for (Connection connection : playernames.keySet()) {
- roboRallyWrapper.server.sendToClient(connection, new GameStartInfo("Checkmate.txt"
- , playerlist, playernames.get(connection)));
+ for (Connection connection : playerNames.keySet()) {
+ roboRallyWrapper.server.sendToClient(connection, new GameStartInfoResponse("Checkmate.txt"
+ , playerList, playerNames.get(connection)));
}
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper));
return true;
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java
index 0d01851..40e4465 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java
@@ -53,30 +53,30 @@ public class PowerDownScreen extends AbstractScreen {
@Override
public void render(float delta) {
- Gdx.gl.glClearColor(0.2f, 1f, 0.2f, 1);
+ Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
- String descriptiontext;
+ String descriptionText;
if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_POWER_DOWN) {
- descriptiontext = "click the button to enter powerdown next round";
+ descriptionText = "Click the button to enter power down next round";
} else {
- descriptiontext = "continue powerdown?";
+ descriptionText = "Click the button to continue your power down the next round";
}
int elapsedTime = (int) Math.floor((System.currentTimeMillis() - startTime) / 1000f);
roboRallyWrapper.batch.begin();
- roboRallyWrapper.font.draw(roboRallyWrapper.batch, descriptiontext,
+ roboRallyWrapper.font.draw(roboRallyWrapper.batch, descriptionText,
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1,
true);
- roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(10 - elapsedTime),
+ roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(5 - elapsedTime),
applicationWidth / 2f - 40 / 2f, applicationHeight / 2f - 100, 40, 1,
true);
roboRallyWrapper.batch.end();
stage.draw();
- if (elapsedTime > 10) {
+ if (elapsedTime > 5) {
sendPowerDownStatus(Boolean.FALSE);
}
}
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/UsernameScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/UsernameScreen.java
index 448a770..0c758d6 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/UsernameScreen.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/UsernameScreen.java
@@ -13,6 +13,8 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
+import javax.swing.*;
+
/**
* This screen allows a user to choose their player name
*/
@@ -46,6 +48,7 @@ public class UsernameScreen extends AbstractScreen {
public void touchUp(InputEvent e, float x, float y, int point, int button) {
String userName = textInput.getText();
if (nameInvalid(userName)) {
+ JOptionPane.showMessageDialog(null, "Username cannot be empty.");
return;
}
roboRallyWrapper.client.sendElement(userName);
diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/WinnerScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/WinnerScreen.java
index 07ddef5..f1975f3 100644
--- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/WinnerScreen.java
+++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/WinnerScreen.java
@@ -11,8 +11,10 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.gamewrapper.SimpleButton;
-import inf112.fiasko.roborally.gamewrapper.screens.AbstractScreen;
+/**
+ * This screen shows which player won the game
+ */
public class WinnerScreen extends AbstractScreen {
private final RoboRallyWrapper roboRallyWrapper;
diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java
index 94c6115..53a90c8 100644
--- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java
+++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java
@@ -5,9 +5,9 @@ import com.esotericsoftware.kryonet.Listener;
import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
-import inf112.fiasko.roborally.networking.containers.GameStartInfo;
-import inf112.fiasko.roborally.networking.containers.PowerDownContainer;
-import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
+import inf112.fiasko.roborally.networking.containers.GameStartInfoResponse;
+import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse;
+import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse;
import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
import inf112.fiasko.roborally.objects.RoboRallyGame;
@@ -42,14 +42,14 @@ class RoboRallyClientListener extends Listener {
wrapper.quit(errorResponse.getErrorMessage());
}
System.out.println(errorResponse.getErrorMessage());
- } else if (object instanceof GameStartInfo) {
- GameStartInfo info = (GameStartInfo) object;
+ } else if (object instanceof GameStartInfoResponse) {
+ GameStartInfoResponse info = (GameStartInfoResponse) object;
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
wrapper.server != null, info.getPlayerName(), wrapper.server);
} else if (object instanceof ProgrammingCardDeck) {
if (((ProgrammingCardDeck) object).isEmpty()) {
wrapper.roboRallyGame.setProgram(new ArrayList<>());
- if (wrapper.roboRallyGame.getRobotPowerdown()) {
+ if (wrapper.roboRallyGame.getRobotPowerDown()) {
wrapper.roboRallyGame.setGameState(GameState.SKIP_POWER_DOWN_SCREEN);
} else {
wrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN);
@@ -58,16 +58,16 @@ class RoboRallyClientListener extends Listener {
wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS);
}
new Thread(() -> wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object)).start();
- } else if (object instanceof ProgamsContainer) {
+ } else if (object instanceof ProgramsContainerResponse) {
new Thread(() -> {
try {
- wrapper.roboRallyGame.receiveAllPrograms((ProgamsContainer) object);
+ wrapper.roboRallyGame.receiveAllPrograms((ProgramsContainerResponse) object);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
- } else if (object instanceof PowerDownContainer) {
- new Thread(() -> wrapper.roboRallyGame.receiveStayInPowerDown((PowerDownContainer) object)).start();
+ } else if (object instanceof PowerDownContainerResponse) {
+ new Thread(() -> wrapper.roboRallyGame.receiveStayInPowerDown((PowerDownContainerResponse) object)).start();
}
}
diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java
index a4968b9..2e9ef89 100644
--- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java
+++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java
@@ -5,8 +5,8 @@ import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import inf112.fiasko.roborally.elementproperties.RobotID;
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
-import inf112.fiasko.roborally.networking.containers.PowerDownContainer;
-import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
+import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse;
+import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
import inf112.fiasko.roborally.objects.ProgrammingCard;
@@ -136,7 +136,7 @@ class RoboRallyServerListener extends Listener {
for (Connection connected : stayInPowerDown.keySet()) {
powerDowns.put(playerNames.get(connected), stayInPowerDown.get(connected));
}
- server.sendToAllClients(new PowerDownContainer(powerDowns));
+ server.sendToAllClients(new PowerDownContainerResponse(powerDowns));
stayInPowerDown = new HashMap<>();
}
}
@@ -156,7 +156,7 @@ class RoboRallyServerListener extends Listener {
powerDown.put(playerNames.get(connected), programs.get(connected).getPowerdown());
program.put(playerNames.get(connected), programs.get(connected).getProgram());
}
- server.sendToAllClients(new ProgamsContainer(program, powerDown));
+ server.sendToAllClients(new ProgramsContainerResponse(program, powerDown));
programs = new HashMap<>();
}
}
diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ErrorResponse.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ErrorResponse.java
index ca9b17b..2b4a538 100644
--- a/src/main/java/inf112/fiasko/roborally/networking/containers/ErrorResponse.java
+++ b/src/main/java/inf112/fiasko/roborally/networking/containers/ErrorResponse.java
@@ -17,6 +17,9 @@ public class ErrorResponse {
this.critical = false;
}
+ /**
+ * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
+ */
public ErrorResponse() {
}
diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfo.java b/src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfoResponse.java
similarity index 55%
rename from src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfo.java
rename to src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfoResponse.java
index e16b1ac..6a349a1 100644
--- a/src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfo.java
+++ b/src/main/java/inf112/fiasko/roborally/networking/containers/GameStartInfoResponse.java
@@ -7,25 +7,25 @@ import java.util.List;
/**
* This class contains information about the game board to be used and the game's players
*/
-public class GameStartInfo {
+public class GameStartInfoResponse {
private String boardName;
private List playerList;
private String playerName;
/**
- * Empty initialization method required by kryo
+ * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
*/
- public GameStartInfo() {
+ public GameStartInfoResponse() {
}
/**
- * Instantiates a new GameStartInfo object
+ * Instantiates a new GameStartInfoResponse object
*
* @param boardName The name of the board to be used, with extension
* @param playerList List of players for the game
* @param playerName The player name of the receiver
*/
- public GameStartInfo(String boardName, List playerList, String playerName) {
+ public GameStartInfoResponse(String boardName, List playerList, String playerName) {
this.playerName = playerName;
this.boardName = boardName;
this.playerList = playerList;
@@ -40,15 +40,6 @@ public class GameStartInfo {
return playerName;
}
- /**
- * Sets the player name of the current player
- *
- * @param playerName The player name of the current player
- */
- public void setPlayerName(String playerName) {
- this.playerName = playerName;
- }
-
/**
* Gets the list of players
*
@@ -58,15 +49,6 @@ public class GameStartInfo {
return playerList;
}
- /**
- * Sets the list of players for the game
- *
- * @param playerList List of players for the game
- */
- public void setPlayerList(List playerList) {
- this.playerList = playerList;
- }
-
/**
* Gets the board name
*
@@ -76,13 +58,4 @@ public class GameStartInfo {
return boardName;
}
- /**
- * Sets the name of the board to be used
- *
- * @param boardName The name of the board to be used, with extension
- */
- public void setBoardName(String boardName) {
- this.boardName = boardName;
- }
-
}
diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainer.java b/src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainerResponse.java
similarity index 72%
rename from src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainer.java
rename to src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainerResponse.java
index 55ef6b0..163dd33 100644
--- a/src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainer.java
+++ b/src/main/java/inf112/fiasko/roborally/networking/containers/PowerDownContainerResponse.java
@@ -5,15 +5,13 @@ import java.util.Map;
/**
* This class is used to contain power down status for all players
*/
-public class PowerDownContainer {
+public class PowerDownContainerResponse {
private Map powerDown;
/**
- * IMPORTANT!!!
- * DO NOT USE!
- * Kryonet demands a no args constructor or else it throws a exception
+ * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
*/
- public PowerDownContainer() {
+ public PowerDownContainerResponse() {
}
/**
@@ -21,7 +19,7 @@ public class PowerDownContainer {
*
* @param powerDown A map between player names and whether they should remain in power down
*/
- public PowerDownContainer(Map powerDown) {
+ public PowerDownContainerResponse(Map powerDown) {
this.powerDown = powerDown;
}
diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java
deleted file mode 100644
index d2b17ea..0000000
--- a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package inf112.fiasko.roborally.networking.containers;
-
-import inf112.fiasko.roborally.objects.ProgrammingCard;
-
-import java.util.List;
-import java.util.Map;
-
-public class ProgamsContainer {
- private Map> program;
- private Map powerdown;
-
- public ProgamsContainer() {
- }
-
- public ProgamsContainer(Map> program, Map powerdown) {
- this.program = program;
- this.powerdown = powerdown;
- }
-
- public Map> getProgram() {
- return program;
- }
-
- public Map getPowerdown() {
- return powerdown;
- }
-}
diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java
index 8e31b92..112e148 100644
--- a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java
+++ b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java
@@ -8,6 +8,9 @@ public class ProgramAndPowerdownRequest {
private Boolean powerdown;
private List program;
+ /**
+ * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
+ */
public ProgramAndPowerdownRequest() {
}
diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramsContainerResponse.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramsContainerResponse.java
new file mode 100644
index 0000000..124863b
--- /dev/null
+++ b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramsContainerResponse.java
@@ -0,0 +1,49 @@
+package inf112.fiasko.roborally.networking.containers;
+
+import inf112.fiasko.roborally.objects.ProgrammingCard;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class contains information about all players' programs and whether they want to enter power down
+ */
+public class ProgramsContainerResponse {
+ private Map> programsMap;
+ private Map powerDownMap;
+
+ /**
+ * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
+ */
+ public ProgramsContainerResponse() {
+ }
+
+ /**
+ * Instantiates a new programs container
+ *
+ * @param programsMap A map between a player name and a player's program
+ * @param powerDownMap A map between a player name and power down
+ */
+ public ProgramsContainerResponse(Map> programsMap, Map powerDownMap) {
+ this.programsMap = programsMap;
+ this.powerDownMap = powerDownMap;
+ }
+
+ /**
+ * Gets the map of programs
+ *
+ * @return A map between a player name and a player's program
+ */
+ public Map> getProgramsMap() {
+ return programsMap;
+ }
+
+ /**
+ * Gets the map of power down
+ *
+ * @return A map between a player name and power down
+ */
+ public Map getPowerDownMap() {
+ return powerDownMap;
+ }
+}
diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java
index c4a83af..0b86cc3 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/Board.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java
@@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
/**
* This class represents a board
@@ -179,10 +180,16 @@ public class Board {
if (robots.containsKey(robotID)) {
robots.get(robotID).setPowerDown(powerDown);
} else if (getRobotFromDeadRobots(robotID) != null) {
- getRobotFromDeadRobots(robotID).setPowerDown(powerDown);
+ Objects.requireNonNull(getRobotFromDeadRobots(robotID)).setPowerDown(powerDown);
}
}
+ /**
+ * Sets the backup position of a given robot to a given position
+ *
+ * @param robotID The robot to change backup position for
+ * @param pos The robot's new backup position
+ */
public void setBackupPositionOfRobot(RobotID robotID, Position pos) {
robots.get(robotID).setBackupPosition(pos);
}
@@ -197,11 +204,17 @@ public class Board {
if (robots.containsKey(robotID)) {
return robots.get(robotID).isInPowerDown();
} else if (getRobotFromDeadRobots(robotID) != null) {
- return getRobotFromDeadRobots(robotID).isInPowerDown();
+ return Objects.requireNonNull(getRobotFromDeadRobots(robotID)).isInPowerDown();
}
return false;
}
+ /**
+ * Gets a robot from the list of dead robots
+ *
+ * @param robotID The id of the robot to get
+ * @return The dead robot
+ */
private Robot getRobotFromDeadRobots(RobotID robotID) {
for (Robot robot : deadRobots) {
if (robot.getRobotId() == robotID) {
@@ -223,7 +236,7 @@ public class Board {
}
/**
- * sets the damage taken of robots in powerdown to 0
+ * sets the damage taken of robots in power down to 0
*/
public void executePowerDown() {
for (Robot robot : robots.values()) {
diff --git a/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java b/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java
index 4856669..dab9f22 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java
@@ -1,13 +1,13 @@
package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.elementproperties.GameState;
-import inf112.fiasko.roborally.networking.containers.PowerDownContainer;
-import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
+import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse;
+import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse;
import java.util.List;
/**
- * This interface describes
+ * This interface describes a game which can be interacted with
*/
public interface InteractableGame {
/**
@@ -44,14 +44,14 @@ public interface InteractableGame {
* @param programs The programs container received from the server
* @throws InterruptedException If interrupted during sleep
*/
- void receiveAllPrograms(ProgamsContainer programs) throws InterruptedException;
+ void receiveAllPrograms(ProgramsContainerResponse programs) throws InterruptedException;
/**
* Continues turn when stay in power down is received from all players
*
* @param powerDowns The power down container received from the server
*/
- void receiveStayInPowerDown(PowerDownContainer powerDowns);
+ void receiveStayInPowerDown(PowerDownContainerResponse powerDowns);
/**
* Gets the hand of this player
diff --git a/src/main/java/inf112/fiasko/roborally/objects/Phase.java b/src/main/java/inf112/fiasko/roborally/objects/Phase.java
index 616d23b..d6d2dac 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/Phase.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/Phase.java
@@ -25,7 +25,7 @@ public class Phase {
private List> conveyorBelts;
private List> fastConveyorBelts;
private List> flags;
- private InteractableGame game;
+ private final InteractableGame game;
/**
* Instantiates a new phase
diff --git a/src/main/java/inf112/fiasko/roborally/objects/Player.java b/src/main/java/inf112/fiasko/roborally/objects/Player.java
index c0c1922..5757020 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/Player.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/Player.java
@@ -36,7 +36,7 @@ public class Player {
}
/**
- * Gives you the RobotID of a player
+ * Gets the RobotID of a player
*
* @return A RobotID
*/
@@ -45,7 +45,7 @@ public class Player {
}
/**
- * Gives you the Name of the player
+ * Gets the name of the player
*
* @return A player Name
*/
@@ -54,16 +54,7 @@ public class Player {
}
/**
- * Sets the name of the robot
- *
- * @param name The new name of the robot
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * Gives you the players program
+ * Gets the players program
*
* @return A list of programming cards
*/
@@ -85,16 +76,16 @@ public class Player {
}
/**
- * Gives you the player hand/deck
+ * Gets the player hand/deck
*
- * @return a deck
+ * @return A deck
*/
public ProgrammingCardDeck getProgrammingCardDeck() {
return playerDeck;
}
/**
- * Set the players deck to the given deck
+ * Sets the players deck to the given deck
*
* @param playerDeck A deck of cards given to the player
*/
@@ -103,7 +94,7 @@ public class Player {
}
/**
- * Gives you the player deck with locked cards
+ * Gets the player deck with locked cards
*
* @return a deck with locked cards
*/
@@ -112,7 +103,7 @@ public class Player {
}
/**
- * Gives you the players power down status
+ * Gets the players power down status
*
* @return Whether the player is to power down
*/
diff --git a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java
index 31e8f64..86eac96 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java
@@ -21,8 +21,10 @@ public class ProgrammingCard implements Comparable {
this.cardAction = cardAction;
}
+ /**
+ * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
+ */
public ProgrammingCard() {
-
}
/**
diff --git a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java
index 9a59be2..1c96dea 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCardDeck.java
@@ -16,6 +16,9 @@ public class ProgrammingCardDeck extends AbstractDeck {
super(cardList);
}
+ /**
+ * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
+ */
public ProgrammingCardDeck() {
}
}
diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
index 63f3f77..504366d 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
@@ -6,8 +6,8 @@ import inf112.fiasko.roborally.elementproperties.Position;
import inf112.fiasko.roborally.elementproperties.RobotID;
import inf112.fiasko.roborally.elementproperties.TileType;
import inf112.fiasko.roborally.networking.RoboRallyServer;
-import inf112.fiasko.roborally.networking.containers.PowerDownContainer;
-import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
+import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse;
+import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse;
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
import inf112.fiasko.roborally.utility.DeckLoaderUtil;
@@ -32,7 +32,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
private String winningPlayerName;
private List program;
private ProgrammingCardDeck playerHand;
- private Phase phase;
+ private final Phase phase;
/**
* Instantiates a new Robo Rally game
@@ -53,7 +53,12 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
this.phase = new Phase(gameBoard, playerList, 600, this);
}
- public Boolean getRobotPowerdown() {
+ /**
+ * Gets the power down status of the client playing this instance of the game
+ *
+ * @return Whether this player's robot is in power down
+ */
+ public Boolean getRobotPowerDown() {
if (getPlayerFromName(this.playerName) != null) {
return gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID());
}
@@ -140,10 +145,10 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
}
@Override
- public void receiveAllPrograms(ProgamsContainer programs) throws InterruptedException {
+ public void receiveAllPrograms(ProgramsContainerResponse programs) throws InterruptedException {
//Reads data from server and updates player objects
- Map> programMap = programs.getProgram();
- Map powerDown = programs.getPowerdown();
+ Map> programMap = programs.getProgramsMap();
+ Map powerDown = programs.getPowerDownMap();
String playerName;
for (Player player : playerList) {
playerName = player.getName();
@@ -175,7 +180,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
}
@Override
- public void receiveStayInPowerDown(PowerDownContainer powerDowns) {
+ public void receiveStayInPowerDown(PowerDownContainerResponse powerDowns) {
for (Player player : playerList) {
if (gameBoard.getPowerDown(player.getRobotID())) {
player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName()));
@@ -198,26 +203,6 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
this.winningPlayerName = winningPlayerName;
}
- /**
- * Initializes the game with a debugging board
- */
- private void initializeDebugMode() {
- List robots = new ArrayList<>();
- robots.add(new Robot(RobotID.ROBOT_1, new Position(0, 18)));
- robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 18)));
- robots.add(new Robot(RobotID.ROBOT_3, new Position(2, 18)));
- robots.add(new Robot(RobotID.ROBOT_4, new Position(3, 18)));
- robots.add(new Robot(RobotID.ROBOT_5, new Position(4, 18)));
- robots.add(new Robot(RobotID.ROBOT_6, new Position(5, 18)));
- robots.add(new Robot(RobotID.ROBOT_7, new Position(6, 18)));
- robots.add(new Robot(RobotID.ROBOT_8, new Position(7, 18)));
- try {
- gameBoard = BoardLoaderUtil.loadBoard("boards/all_tiles_test_board.txt", robots);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
/**
* Initializes the game with a playable board
*/
@@ -255,7 +240,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
RobotID robotID = player.getRobotID();
TileType robotSpawn = TileType.getTileTypeFromID(robotID.getRobotIDID() + 22);
List> spawnTileContainerList = gameBoard.getPositionsOfTileOnBoard(robotSpawn);
- if (spawnTileContainerList.size() != 1) {
+ if (spawnTileContainerList.size() < 1) {
throw new IllegalArgumentException("The chosen board seems to be missing a robot spawn");
}
BoardElementContainer spawnTileContainer = spawnTileContainerList.get(0);
diff --git a/src/main/java/inf112/fiasko/roborally/objects/Robot.java b/src/main/java/inf112/fiasko/roborally/objects/Robot.java
index 34437fe..94e4c99 100644
--- a/src/main/java/inf112/fiasko/roborally/objects/Robot.java
+++ b/src/main/java/inf112/fiasko/roborally/objects/Robot.java
@@ -132,9 +132,9 @@ public class Robot {
}
/**
- * setBackupPosition
+ * Sets the backup position of the robot
*
- * @param backupPosition
+ * @param backupPosition The new backup position of the robot
*/
public void setBackupPosition(Position backupPosition) {
this.backupPosition = backupPosition;
diff --git a/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java b/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java
index 5109624..cc2966f 100644
--- a/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java
+++ b/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java
@@ -4,9 +4,9 @@ import com.esotericsoftware.kryo.Kryo;
import inf112.fiasko.roborally.elementproperties.Action;
import inf112.fiasko.roborally.elementproperties.RobotID;
import inf112.fiasko.roborally.networking.containers.ErrorResponse;
-import inf112.fiasko.roborally.networking.containers.GameStartInfo;
-import inf112.fiasko.roborally.networking.containers.PowerDownContainer;
-import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
+import inf112.fiasko.roborally.networking.containers.GameStartInfoResponse;
+import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse;
+import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
import inf112.fiasko.roborally.objects.Deck;
import inf112.fiasko.roborally.objects.Player;
@@ -30,17 +30,15 @@ public final class NetworkUtil {
kryo.register(ErrorResponse.class);
kryo.register(Deck.class);
kryo.register(ProgrammingCard.class);
- kryo.register(GameStartInfo.class);
+ kryo.register(GameStartInfoResponse.class);
kryo.register(ArrayList.class);
kryo.register(Player.class);
kryo.register(RobotID.class);
kryo.register(ProgrammingCardDeck.class);
kryo.register(Action.class);
kryo.register(ProgramAndPowerdownRequest.class);
- kryo.register(ProgamsContainer.class);
- kryo.register(PowerDownContainer.class);
+ kryo.register(ProgramsContainerResponse.class);
+ kryo.register(PowerDownContainerResponse.class);
kryo.register(HashMap.class);
-
-
}
}
diff --git a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java
index 0732e60..21e2b61 100644
--- a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java
+++ b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java
@@ -366,6 +366,18 @@ public final class TextureConverterUtil {
private final int xWest;
private final int yWest;
+ /**
+ * Instantiates a new texture converter container
+ *
+ * @param xNorth The x position of the texture for a north-facing instance of the object
+ * @param yNorth The y position of the texture for a north-facing instance of the object
+ * @param xEast The x position of the texture for a east-facing instance of the object
+ * @param yEast The y position of the texture for a east-facing instance of the object
+ * @param xSouth The x position of the texture for a south-facing instance of the object
+ * @param ySouth The y position of the texture for a south-facing instance of the object
+ * @param xWest The x position of the texture for a west-facing instance of the object
+ * @param yWest The y position of the texture for a west-facing instance of the object
+ */
TextureConverterContainer(int xNorth, int yNorth, int xEast, int yEast, int xSouth, int ySouth,
int xWest, int yWest) {
this.xNorth = xNorth;
@@ -378,34 +390,74 @@ public final class TextureConverterUtil {
this.yWest = yWest;
}
+ /**
+ * Gets the x position of the texture for a north-facing instance of the object
+ *
+ * @return The x position of the texture for a north-facing instance of the object
+ */
public int getXNorth() {
return xNorth;
}
+ /**
+ * Gets the y position of the texture for a north-facing instance of the object
+ *
+ * @return The y position of the texture for a north-facing instance of the object
+ */
public int getYNorth() {
return yNorth;
}
+ /**
+ * Gets the x position of the texture for a east-facing instance of the object
+ *
+ * @return The x position of the texture for a east-facing instance of the object
+ */
public int getXEast() {
return xEast;
}
+ /**
+ * Gets the y position of the texture for a east-facing instance of the object
+ *
+ * @return The y position of the texture for a east-facing instance of the object
+ */
public int getYEast() {
return yEast;
}
+ /**
+ * Gets the x position of the texture for a south-facing instance of the object
+ *
+ * @return The x position of the texture for a south-facing instance of the object
+ */
public int getXSouth() {
return xSouth;
}
+ /**
+ * Gets the y position of the texture for a south-facing instance of the object
+ *
+ * @return The y position of the texture for a south-facing instance of the object
+ */
public int getYSouth() {
return ySouth;
}
+ /**
+ * Gets the x position of the texture for a west-facing instance of the object
+ *
+ * @return The x position of the texture for a west-facing instance of the object
+ */
public int getXWest() {
return xWest;
}
+ /**
+ * Gets the y position of the texture for a west-facing instance of the object
+ *
+ * @return The y position of the texture for a west-facing instance of the object
+ */
public int getYWest() {
return yWest;
}
diff --git a/src/test/java/inf112/fiasko/roborally/objects/FakeGame.java b/src/test/java/inf112/fiasko/roborally/objects/FakeGame.java
index a43548e..fcf6f7b 100644
--- a/src/test/java/inf112/fiasko/roborally/objects/FakeGame.java
+++ b/src/test/java/inf112/fiasko/roborally/objects/FakeGame.java
@@ -1,11 +1,14 @@
package inf112.fiasko.roborally.objects;
import inf112.fiasko.roborally.elementproperties.GameState;
-import inf112.fiasko.roborally.networking.containers.PowerDownContainer;
-import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
+import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse;
+import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse;
import java.util.List;
+/**
+ * A class implementing just enough features of an interactable game to be able to test a phase
+ */
public class FakeGame implements InteractableGame {
private String winningPlayerName;
@@ -30,12 +33,12 @@ public class FakeGame implements InteractableGame {
}
@Override
- public void receiveAllPrograms(ProgamsContainer programs) throws InterruptedException {
+ public void receiveAllPrograms(ProgramsContainerResponse programs) {
//Not needed for testing
}
@Override
- public void receiveStayInPowerDown(PowerDownContainer powerDowns) {
+ public void receiveStayInPowerDown(PowerDownContainerResponse powerDowns) {
//Not needed for testing
}
diff --git a/src/test/java/inf112/fiasko/roborally/objects/PhaseTest.java b/src/test/java/inf112/fiasko/roborally/objects/PhaseTest.java
index f5daffb..9b2bd43 100644
--- a/src/test/java/inf112/fiasko/roborally/objects/PhaseTest.java
+++ b/src/test/java/inf112/fiasko/roborally/objects/PhaseTest.java
@@ -12,10 +12,13 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import static junit.framework.TestCase.*;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
public class PhaseTest {
- List robots = new ArrayList<>();
+ private List robots = new ArrayList<>();
private Phase phase;
private Board board;
private Position robot1Position = new Position(2, 2);
@@ -267,36 +270,14 @@ public class PhaseTest {
List testProgram1 = new ArrayList<>();
List testProgram2 = new ArrayList<>();
List testProgram3 = new ArrayList<>();
- ProgrammingCard card1 = new ProgrammingCard(1, Action.MOVE_1);
- ProgrammingCard card2 = new ProgrammingCard(2, Action.ROTATE_RIGHT);
- ProgrammingCard card3 = new ProgrammingCard(3, Action.MOVE_1);
- ProgrammingCard card4 = new ProgrammingCard(4, Action.MOVE_1);
- ProgrammingCard card5 = new ProgrammingCard(5, Action.MOVE_1);
- ProgrammingCard card6 = new ProgrammingCard(10, Action.MOVE_1);
- ProgrammingCard card7 = new ProgrammingCard(11, Action.ROTATE_RIGHT);
- ProgrammingCard card8 = new ProgrammingCard(12, Action.MOVE_1);
- ProgrammingCard card9 = new ProgrammingCard(13, Action.MOVE_1);
- ProgrammingCard card10 = new ProgrammingCard(14, Action.MOVE_1);
- ProgrammingCard card11 = new ProgrammingCard(100, Action.ROTATE_LEFT);
- ProgrammingCard card12 = new ProgrammingCard(200, Action.ROTATE_LEFT);
- ProgrammingCard card13 = new ProgrammingCard(300, Action.ROTATE_LEFT);
- ProgrammingCard card14 = new ProgrammingCard(400, Action.ROTATE_LEFT);
- ProgrammingCard card15 = new ProgrammingCard(500, Action.ROTATE_LEFT);
- testProgram1.add(card1);
- testProgram1.add(card2);
- testProgram1.add(card3);
- testProgram1.add(card4);
- testProgram1.add(card5);
- testProgram2.add(card6);
- testProgram2.add(card7);
- testProgram2.add(card8);
- testProgram2.add(card9);
- testProgram2.add(card10);
- testProgram3.add(card11);
- testProgram3.add(card12);
- testProgram3.add(card13);
- testProgram3.add(card14);
- testProgram3.add(card15);
+ testProgram1.add(new ProgrammingCard(1, Action.MOVE_1));
+ testProgram2.add(new ProgrammingCard(10, Action.MOVE_1));
+ testProgram3.add(new ProgrammingCard(100, Action.ROTATE_LEFT));
+ for (int i = 0; i < 4; i++) {
+ testProgram1.add(null);
+ testProgram2.add(null);
+ testProgram3.add(null);
+ }
player1.setProgram(testProgram3);
player2.setProgram(testProgram3);
player3.setProgram(testProgram3);
@@ -310,8 +291,20 @@ public class PhaseTest {
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 players, List robots) throws IOException {
+ board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
+ return new Phase(board, players, 0, null);
+ }
+
@Test
- public void robotsOnConveyorBeltsFacingTheSameEmptyTileDoesNotMove() {
+ public void robotsOnConveyorBeltsFacingTheSameEmptyTileDoesNotMove() throws InterruptedException, IOException {
List robots = new ArrayList<>();
List players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(8, 11)));
@@ -319,19 +312,15 @@ public class PhaseTest {
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(8, 11)));
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(7, 10)));
}
@Test
- public void robotsOnConveyorBeltsFacingTheSameHoleTileDoesNotMove() {
+ public void robotsOnConveyorBeltsFacingTheSameHoleTileDoesNotMove() throws IOException, InterruptedException {
List robots = new ArrayList<>();
List players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(6, 7)));
@@ -339,36 +328,28 @@ public class PhaseTest {
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(6, 7)));
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(7, 8)));
}
@Test
- public void robotOnConveyorBeltsFacingWallDoesNotMove() {
+ public void robotOnConveyorBeltsFacingWallDoesNotMove() throws IOException, InterruptedException {
List robots = new ArrayList<>();
List players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1)));
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(1, 1)));
}
@Test
- public void robotBehindAnotherRobotOnConveyorBeltsFacingWallDoesNotMove() {
+ public void robotBehindAnotherRobotOnConveyorBeltsFacingWallDoesNotMove() throws IOException, InterruptedException {
List robots = new ArrayList<>();
List players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1)));
@@ -376,19 +357,15 @@ public class PhaseTest {
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(1, 1)));
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(1, 2)));
}
@Test
- public void robotBehindOtherRobotsOnSlowConveyorBeltsFacingEmptyTilesMoves() {
+ public void robotBehindOtherRobotsOnSlowConveyorBeltsFacingEmptyTilesMoves() throws IOException, InterruptedException {
List robots = new ArrayList<>();
List players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(5, 7)));
@@ -400,13 +377,9 @@ public class PhaseTest {
players.add(new Player(RobotID.ROBOT_3, "Player 3"));
players.add(new Player(RobotID.ROBOT_4, "Player 4"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(5, 6)));
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(5, 7)));
assertEquals(RobotID.ROBOT_3, board.getRobotOnPosition(new Position(5, 8)));
@@ -414,7 +387,7 @@ public class PhaseTest {
}
@Test
- public void robotBehindOtherRobotsOnFastConveyorBeltsFacingEmptyTilesMoves() {
+ public void robotBehindOtherRobotsOnFastConveyorBeltsFacingEmptyTilesMoves() throws IOException, InterruptedException {
List robots = new ArrayList<>();
List players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(4, 7)));
@@ -426,13 +399,9 @@ public class PhaseTest {
players.add(new Player(RobotID.ROBOT_3, "Player 3"));
players.add(new Player(RobotID.ROBOT_4, "Player 4"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(4, 5)));
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(4, 6)));
assertEquals(RobotID.ROBOT_3, board.getRobotOnPosition(new Position(4, 7)));
@@ -440,7 +409,7 @@ public class PhaseTest {
}
@Test
- public void robotBehindOtherRobotsOnConveyorBeltsShapedAsARoundaboutMoves() {
+ public void robotBehindOtherRobotsOnConveyorBeltsShapedAsARoundaboutMoves() throws IOException, InterruptedException {
long startTime = System.currentTimeMillis();
List robots = new ArrayList<>();
List players = new ArrayList<>();
@@ -453,13 +422,9 @@ public class PhaseTest {
players.add(new Player(RobotID.ROBOT_3, "Player 3"));
players.add(new Player(RobotID.ROBOT_4, "Player 4"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(1, 9)));
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(1, 8)));
assertEquals(RobotID.ROBOT_3, board.getRobotOnPosition(new Position(2, 8)));
@@ -469,38 +434,30 @@ public class PhaseTest {
}
@Test
- public void robotOnConveyorBeltFacingHoleMovesAndDies() {
+ public void robotOnConveyorBeltFacingHoleMovesAndDies() throws IOException, InterruptedException {
List robots = new ArrayList<>();
List players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(6, 7)));
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertFalse(board.isRobotAlive(RobotID.ROBOT_1));
assertNull(board.getRobotOnPosition(new Position(6, 7)));
assertNull(board.getRobotOnPosition(new Position(7, 7)));
}
@Test
- public void robotOnConveyorBeltFacingOutOfMapMovesAndDies() {
+ public void robotOnConveyorBeltFacingOutOfMapMovesAndDies() throws IOException, InterruptedException {
List robots = new ArrayList<>();
List players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(7, 0)));
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
- try {
- board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
- Phase testPhase = new Phase(board, players, 0, null);
- testPhase.moveAllConveyorBelts();
- } catch (IOException | InterruptedException e) {
- e.printStackTrace();
- }
+ Phase testPhase = createPhaseAndLoadBoard(players, robots);
+ testPhase.moveAllConveyorBelts();
+
assertFalse(board.isRobotAlive(RobotID.ROBOT_1));
assertNull(board.getRobotOnPosition(new Position(7, 0)));
}