Legger til manglende kode i kommentarer og forbedrer en del kode

This commit is contained in:
Kristian Knarvik 2020-05-07 18:56:37 +02:00
parent 114d166723
commit 7b3b653b6a
26 changed files with 240 additions and 140 deletions

10
docs/index.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fiasko pages</title>
</head>
<body>
<a href="javadoc/">Javadoc</a>
</body>
</html>

View File

@ -9,12 +9,12 @@ import inf112.fiasko.roborally.ui.RoboRallyWrapper;
*/ */
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); LwjglApplicationConfiguration configuration = new LwjglApplicationConfiguration();
cfg.title = "Robo Rally"; configuration.title = "Robo Rally";
cfg.width = 900; configuration.width = 900;
cfg.height = 900; configuration.height = 900;
cfg.samples = 3; configuration.samples = 3;
new LwjglApplication(new RoboRallyWrapper(), cfg); new LwjglApplication(new RoboRallyWrapper(), configuration);
} }
} }

View File

@ -104,7 +104,7 @@ class RoboRallyClientListener extends Listener {
*/ */
private void receiveHand(HandResponse newHand) { private void receiveHand(HandResponse newHand) {
new Thread(() -> { new Thread(() -> {
//Prevents a bug where the game //Prevents a bug where the game enters an infinite loading screen
while (wrapper.getGame().getGameState() != GameState.WAITING_FOR_CARDS_FROM_SERVER) { while (wrapper.getGame().getGameState() != GameState.WAITING_FOR_CARDS_FROM_SERVER) {
try { try {
TimeUnit.MILLISECONDS.sleep(100); TimeUnit.MILLISECONDS.sleep(100);

View File

@ -7,7 +7,7 @@ import inf112.fiasko.roborally.networking.containers.ErrorResponse;
import inf112.fiasko.roborally.networking.containers.HurryResponse; import inf112.fiasko.roborally.networking.containers.HurryResponse;
import inf112.fiasko.roborally.networking.containers.OkayResponse; import inf112.fiasko.roborally.networking.containers.OkayResponse;
import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse; import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; import inf112.fiasko.roborally.networking.containers.ProgramAndPowerDownRequest;
import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse; import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse;
import inf112.fiasko.roborally.networking.containers.UsernameRequest; import inf112.fiasko.roborally.networking.containers.UsernameRequest;
import inf112.fiasko.roborally.objects.ProgrammingCard; import inf112.fiasko.roborally.objects.ProgrammingCard;
@ -28,7 +28,7 @@ class RoboRallyServerListener extends Listener {
private final RoboRallyServer server; private final RoboRallyServer server;
private Connection host; private Connection host;
private Map<Connection, Boolean> stayInPowerDown; private Map<Connection, Boolean> stayInPowerDown;
private Map<Connection, ProgramAndPowerdownRequest> programs; private Map<Connection, ProgramAndPowerDownRequest> programs;
private boolean gameStarted = false; private boolean gameStarted = false;
/** /**
@ -111,8 +111,8 @@ class RoboRallyServerListener extends Listener {
receivedUsername(connection, (UsernameRequest) object); receivedUsername(connection, (UsernameRequest) object);
} else if (object instanceof Boolean) { } else if (object instanceof Boolean) {
receiveContinuePowerDown(connection, (Boolean) object); receiveContinuePowerDown(connection, (Boolean) object);
} else if (object instanceof ProgramAndPowerdownRequest) { } else if (object instanceof ProgramAndPowerDownRequest) {
receiveProgramAndPowerDownRequest(connection, (ProgramAndPowerdownRequest) object); receiveProgramAndPowerDownRequest(connection, (ProgramAndPowerDownRequest) object);
} }
} }
@ -157,14 +157,14 @@ class RoboRallyServerListener extends Listener {
* @param connection The connection sending the program and power down request * @param connection The connection sending the program and power down request
* @param request The program and power down request received * @param request The program and power down request received
*/ */
private void receiveProgramAndPowerDownRequest(Connection connection, ProgramAndPowerdownRequest request) { private void receiveProgramAndPowerDownRequest(Connection connection, ProgramAndPowerDownRequest request) {
programs.put(connection, request); programs.put(connection, request);
connection.sendTCP(new OkayResponse()); connection.sendTCP(new OkayResponse());
if (receivedDataFromAllConnections(programs)) { if (receivedDataFromAllConnections(programs)) {
Map<String, Boolean> powerDown = new HashMap<>(); Map<String, Boolean> powerDown = new HashMap<>();
Map<String, List<ProgrammingCard>> program = new HashMap<>(); Map<String, List<ProgrammingCard>> program = new HashMap<>();
for (Connection connected : programs.keySet()) { for (Connection connected : programs.keySet()) {
powerDown.put(playerNames.get(connected), programs.get(connected).getPowerdown()); powerDown.put(playerNames.get(connected), programs.get(connected).getPowerDown());
program.put(playerNames.get(connected), programs.get(connected).getProgram()); program.put(playerNames.get(connected), programs.get(connected).getProgram());
} }
server.sendToAllClients(new ProgramsContainerResponse(program, powerDown)); server.sendToAllClients(new ProgramsContainerResponse(program, powerDown));

View File

@ -21,7 +21,6 @@ public class ErrorResponse {
* Empty constructor required by KryoNet. DO NOT REMOVE THIS!!! * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
*/ */
public ErrorResponse() { public ErrorResponse() {
} }
/** /**

View File

@ -0,0 +1,48 @@
package inf112.fiasko.roborally.networking.containers;
import inf112.fiasko.roborally.objects.ProgrammingCard;
import java.util.List;
/**
* A request containing a player's program and whether it wants to enter power down next round
*/
public class ProgramAndPowerDownRequest {
private Boolean powerDown;
private List<ProgrammingCard> program;
/**
* Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
*/
public ProgramAndPowerDownRequest() {
}
/**
* Instantiates a new program and power down request
*
* @param powerDown Whether the player wants to enter power down next round
* @param program The program the player has programmed
*/
public ProgramAndPowerDownRequest(Boolean powerDown, List<ProgrammingCard> program) {
this.program = program;
this.powerDown = powerDown;
}
/**
* Gets the program contained within this request
*
* @return The program sent by the player
*/
public List<ProgrammingCard> getProgram() {
return program;
}
/**
* Gets the power down status contained within this request
*
* @return Whether the player wants to power down next round
*/
public Boolean getPowerDown() {
return powerDown;
}
}

View File

@ -1,29 +0,0 @@
package inf112.fiasko.roborally.networking.containers;
import inf112.fiasko.roborally.objects.ProgrammingCard;
import java.util.List;
public class ProgramAndPowerdownRequest {
private Boolean powerdown;
private List<ProgrammingCard> program;
/**
* Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
*/
public ProgramAndPowerdownRequest() {
}
public ProgramAndPowerdownRequest(Boolean powerdown, List<ProgrammingCard> program) {
this.program = program;
this.powerdown = powerdown;
}
public List<ProgrammingCard> getProgram() {
return program;
}
public Boolean getPowerdown() {
return powerdown;
}
}

View File

@ -10,7 +10,6 @@ public class UsernameRequest {
* Empty constructor required by KryoNet. DO NOT REMOVE THIS!!! * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
*/ */
public UsernameRequest() { public UsernameRequest() {
} }
/** /**

View File

@ -10,6 +10,9 @@ import java.util.Random;
public abstract class AbstractDeck<T> implements Deck<T> { public abstract class AbstractDeck<T> implements Deck<T> {
private final List<T> cardList; private final List<T> cardList;
/**
* Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
*/
public AbstractDeck() { public AbstractDeck() {
this.cardList = new ArrayList<>(); this.cardList = new ArrayList<>();
} }

View File

@ -26,8 +26,8 @@ public class Board {
private Map<RobotID, Robot> robots; private Map<RobotID, Robot> robots;
private List<Robot> deadRobots; private List<Robot> deadRobots;
private List<RobotID> realDeadRobots; private List<RobotID> realDeadRobots;
private List<TileType> dangerousTiles;
private List<BoardElementContainer<Wall>> wallLasers; private List<BoardElementContainer<Wall>> wallLasers;
private List<BoardElementContainer<Tile>> repairTiles;
/** /**
* Initializes the board * Initializes the board
@ -54,22 +54,10 @@ public class Board {
this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight()); this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight());
this.deadRobots = new ArrayList<>(); this.deadRobots = new ArrayList<>();
this.realDeadRobots = new ArrayList<>(); this.realDeadRobots = new ArrayList<>();
this.dangerousTiles = new ArrayList<>();
loadDangerousTileTypes();
wallLasers = getPositionsOfWallsOnBoard(WallType.WALL_LASER_SINGLE, wallLasers = getPositionsOfWallsOnBoard(WallType.WALL_LASER_SINGLE,
WallType.WALL_LASER_DOUBLE, WallType.WALL_LASER_TRIPLE); WallType.WALL_LASER_DOUBLE, WallType.WALL_LASER_TRIPLE);
} repairTiles = getPositionsOfTilesOnBoard(TileType.WRENCH,
TileType.WRENCH_AND_HAMMER, TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
/**
* Adds tile types which will kill the robot to the dangerousTiles list
*/
private void loadDangerousTileTypes() {
dangerousTiles.add(TileType.HOLE);
dangerousTiles.add(TileType.PIT_CORNER);
dangerousTiles.add(TileType.PIT_EMPTY);
dangerousTiles.add(TileType.PIT_FULL);
dangerousTiles.add(TileType.PIT_NORMAL);
dangerousTiles.add(TileType.PIT_U);
} }
/** /**
@ -241,7 +229,7 @@ public class Board {
/** /**
* Removes one damage for a given robot given that it has taken som damage before * Removes one damage for a given robot given that it has taken som damage before
* *
* @param robotID the ID of the robot * @param robotID The ID of the robot
*/ */
public void repairRobotOnTile(RobotID robotID) { public void repairRobotOnTile(RobotID robotID) {
Robot robot = robots.get(robotID); Robot robot = robots.get(robotID);
@ -264,7 +252,7 @@ public class Board {
* Get the damage of a specific robot * Get the damage of a specific robot
* *
* @param robot The RobotID of a robot * @param robot The RobotID of a robot
* @return The amount of damage the robot has currently * @return The amount of damage the robot currently has
*/ */
public int getRobotDamage(RobotID robot) { public int getRobotDamage(RobotID robot) {
return robots.get(robot).getDamageTaken(); return robots.get(robot).getDamageTaken();
@ -299,7 +287,7 @@ public class Board {
} }
robot.setPosition(newPosition); robot.setPosition(newPosition);
//Some tiles may kill the robot if stepped on. //Some tiles may kill the robot if stepped on.
killRobotIfStepsOnDangerousTile(robot, newPosition); killRobotIfStepsInHole(robot, newPosition);
return true; return true;
} }
@ -443,7 +431,7 @@ public class Board {
/** /**
* Moves all dead robots to their backups and makes them part of the board again, and if a robot has no lives * Moves all dead robots to their backups and makes them part of the board again, and if a robot has no lives
* it will be removed from the game. * it will be removed from the game
*/ */
public void respawnRobots() { public void respawnRobots() {
for (Robot robot : deadRobots) { for (Robot robot : deadRobots) {
@ -478,14 +466,14 @@ public class Board {
} }
return; return;
} }
int circleSize = 1; int squareSize = 1;
boolean hasRespawned = false; boolean hasRespawned = false;
while (!hasRespawned) { while (!hasRespawned) {
hasRespawned = tryRobotRespawn(robot, circleSize, startX, startY, Direction.NORTH) || hasRespawned = tryRobotRespawn(robot, squareSize, startX, startY, Direction.NORTH) ||
tryRobotRespawn(robot, circleSize, startX, startY, Direction.EAST) || tryRobotRespawn(robot, squareSize, startX, startY, Direction.EAST) ||
tryRobotRespawn(robot, circleSize, startX, startY, Direction.SOUTH) || tryRobotRespawn(robot, squareSize, startX, startY, Direction.SOUTH) ||
tryRobotRespawn(robot, circleSize, startX, startY, Direction.WEST); tryRobotRespawn(robot, squareSize, startX, startY, Direction.WEST);
circleSize++; squareSize++;
} }
} }
@ -560,8 +548,6 @@ public class Board {
* Updates backup position of all robots on a repair tile * Updates backup position of all robots on a repair tile
*/ */
public void updateRobotBackups() { public void updateRobotBackups() {
List<BoardElementContainer<Tile>> repairTiles = getPositionsOfTilesOnBoard(TileType.WRENCH,
TileType.WRENCH_AND_HAMMER, TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
for (BoardElementContainer<Tile> repairTile : repairTiles) { for (BoardElementContainer<Tile> repairTile : repairTiles) {
Position position = repairTile.getPosition(); Position position = repairTile.getPosition();
if (hasRobotOnPosition(position)) { if (hasRobotOnPosition(position)) {
@ -751,13 +737,8 @@ public class Board {
* @param robot The robot attempting to move * @param robot The robot attempting to move
* @param newPosition The position the robot is attempting to move to * @param newPosition The position the robot is attempting to move to
*/ */
private void killRobotIfStepsOnDangerousTile(Robot robot, Position newPosition) { private void killRobotIfStepsInHole(Robot robot, Position newPosition) {
Tile tileRobotStepsOn = tiles.getElement(newPosition.getXCoordinate(), newPosition.getYCoordinate()); if (hasHole(newPosition)) {
if (tileRobotStepsOn == null) {
throw new IllegalArgumentException("The game board is missing a tile. This should not happen.");
}
TileType tileTypeRobotStepsOn = tileRobotStepsOn.getType();
if (dangerousTiles.contains(tileTypeRobotStepsOn)) {
killRobot(robot); killRobot(robot);
} }
} }
@ -815,12 +796,16 @@ public class Board {
* @param wallLaser The wall laser being fired * @param wallLaser The wall laser being fired
*/ */
private void fireWallLaser(BoardElementContainer<Wall> wallLaser) { private void fireWallLaser(BoardElementContainer<Wall> wallLaser) {
//Reverses direction since a laser points the opposite direction of the wall it's attached to
Direction laserDirection = Direction.getReverseDirection(wallLaser.getElement().getDirection()); Direction laserDirection = Direction.getReverseDirection(wallLaser.getElement().getDirection());
List<Position> laserTargets = new ArrayList<>(); List<Position> laserTargets = new ArrayList<>();
//Stores all positions visited by the laser beam in laserTargets
getLaserTarget(laserDirection, wallLaser.getPosition(), laserTargets); getLaserTarget(laserDirection, wallLaser.getPosition(), laserTargets);
Position hitPosition = laserTargets.get(laserTargets.size() - 1); Position hitPosition = laserTargets.get(laserTargets.size() - 1);
WallType laserType = wallLaser.getElement().getType(); WallType laserType = wallLaser.getElement().getType();
//Displays the laser beam in the particle grid
updateLaserDisplay(laserTargets, laserDirection, laserType); updateLaserDisplay(laserTargets, laserDirection, laserType);
//Applies damage if the laser stops because it hits a robot
if (getRobotOnPosition(hitPosition) != null) { if (getRobotOnPosition(hitPosition) != null) {
applyLaserDamage(laserType, robots.get(getRobotOnPosition(hitPosition))); applyLaserDamage(laserType, robots.get(getRobotOnPosition(hitPosition)));
} }

View File

@ -148,15 +148,22 @@ public class Phase {
List<ProgrammingCard> playerProgram = player.getProgram(); List<ProgrammingCard> playerProgram = player.getProgram();
if (!playerProgram.isEmpty()) { if (!playerProgram.isEmpty()) {
ProgrammingCard programmingCard = playerProgram.get(phase - 1); ProgrammingCard programmingCard = playerProgram.get(phase - 1);
//Stores the original priority of the program
originalPriority.add(programmingCard.getPriority()); originalPriority.add(programmingCard.getPriority());
//Stores the player's robot
robotsToDoAction.add(player.getRobotID()); robotsToDoAction.add(player.getRobotID());
//Stores the programming card to be run
programToBeRun.add(programmingCard); programToBeRun.add(programmingCard);
} }
} }
//Sorts the programming cards
Collections.sort(programToBeRun); Collections.sort(programToBeRun);
for (ProgrammingCard card : programToBeRun) { for (ProgrammingCard card : programToBeRun) {
int i = originalPriority.indexOf(card.getPriority()); //Gets the index of the priority of the card which is equal to the index of the robot
RobotID robot = robotsToDoAction.get(i); int robotIndex = originalPriority.indexOf(card.getPriority());
//Gets the robot belonging to the player which played the programming card
RobotID robot = robotsToDoAction.get(robotIndex);
//Moves the robot according to the programming card
makeMove(robot, card.getAction()); makeMove(robot, card.getAction());
} }
} }
@ -253,6 +260,7 @@ public class Phase {
if (game != null) { if (game != null) {
game.setWinningPlayerName(player.getName()); game.setWinningPlayerName(player.getName());
game.setGameState(GameState.GAME_IS_WON); game.setGameState(GameState.GAME_IS_WON);
//Sleeps to prevent the game state to change before the wrapper catches up
try { try {
Thread.sleep(1000 * cycleDelay); Thread.sleep(1000 * cycleDelay);
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@ -30,7 +30,7 @@ public class Player {
} }
/** /**
* Empty constructor required by kryo * Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
*/ */
public Player() { public Player() {
} }

View File

@ -8,7 +8,6 @@ import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.ExtendViewport;
import inf112.fiasko.roborally.objects.DrawableGame; import inf112.fiasko.roborally.objects.DrawableGame;
import inf112.fiasko.roborally.ui.DrawableObject;
import inf112.fiasko.roborally.objects.InteractableGame; 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;
@ -17,6 +16,7 @@ import inf112.fiasko.roborally.objects.properties.Direction;
import inf112.fiasko.roborally.objects.properties.GameState; import inf112.fiasko.roborally.objects.properties.GameState;
import inf112.fiasko.roborally.objects.properties.RobotID; import inf112.fiasko.roborally.objects.properties.RobotID;
import inf112.fiasko.roborally.objects.properties.TileType; import inf112.fiasko.roborally.objects.properties.TileType;
import inf112.fiasko.roborally.ui.DrawableObject;
import inf112.fiasko.roborally.ui.RoboRallyWrapper; import inf112.fiasko.roborally.ui.RoboRallyWrapper;
import inf112.fiasko.roborally.utility.IOUtil; import inf112.fiasko.roborally.utility.IOUtil;
import inf112.fiasko.roborally.utility.TextureConverterUtil; import inf112.fiasko.roborally.utility.TextureConverterUtil;

View File

@ -12,7 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; import inf112.fiasko.roborally.networking.containers.ProgramAndPowerDownRequest;
import inf112.fiasko.roborally.objects.InteractableGame; import inf112.fiasko.roborally.objects.InteractableGame;
import inf112.fiasko.roborally.objects.ProgrammingCard; import inf112.fiasko.roborally.objects.ProgrammingCard;
import inf112.fiasko.roborally.objects.ProgrammingCardDeck; import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
@ -121,7 +121,9 @@ public class CardChoiceScreen extends InteractiveScreen {
} }
/** /**
* Confirm cards and send to server if all are chosen * Confirm cards and send to server together with power down choice if all are chosen
*
* @param requestPowerDown Whether the user wants to enter power down
*/ */
private void confirmCards(Boolean requestPowerDown) { private void confirmCards(Boolean requestPowerDown) {
if (chosenCards.size() == maxCards) { if (chosenCards.size() == maxCards) {
@ -131,7 +133,7 @@ public class CardChoiceScreen extends InteractiveScreen {
game.setProgram(newProgram); game.setProgram(newProgram);
game.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS); game.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(requestPowerDown, newProgram)); roboRallyWrapper.client.sendElement(new ProgramAndPowerDownRequest(requestPowerDown, newProgram));
} else { } else {
JOptionPane.showMessageDialog(null, "You need to choose all your cards" JOptionPane.showMessageDialog(null, "You need to choose all your cards"
+ " before confirming."); + " before confirming.");

View File

@ -51,7 +51,27 @@ public class IPAddressScreen extends AbstractScreen {
stage.addActor(selectBox); stage.addActor(selectBox);
joinButton.addListener(new ClickListener() { joinButton.addListener(getJoinButtonListener(selectBox));
textInput = new TextField("", skin);
textInput.setPosition(applicationWidth / 2f - textInput.getWidth() / 2f, 250);
textInput.setSize(150, 40);
stage.addActor(textInput);
stage.addActor(joinButton);
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
stage.setViewport(viewport);
}
/**
* Gets the listener to use for the join button
*
* @param selectBox The select box containing ip addresses of local servers
* @return A click listener to trigger on the join button
*/
private ClickListener getJoinButtonListener(SelectBox<String> selectBox) {
return new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true; return true;
@ -77,21 +97,11 @@ public class IPAddressScreen extends AbstractScreen {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper));
} catch (IOException | NumberFormatException ex) { } catch (IOException | NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "Could not connect to the server." JOptionPane.showMessageDialog(null, "Could not connect to the server."
+ " Please make sure the ip address you typed is correct, and that the server is online.", + " Please make sure the ip address you typed is correct, and that the server is " +
"Error", JOptionPane.ERROR_MESSAGE); "online.", "Error", JOptionPane.ERROR_MESSAGE);
} }
} }
}); };
textInput = new TextField("", skin);
textInput.setPosition(applicationWidth / 2f - textInput.getWidth() / 2f, 250);
textInput.setSize(150, 40);
stage.addActor(textInput);
stage.addActor(joinButton);
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
stage.setViewport(viewport);
} }
@Override @Override

View File

@ -3,7 +3,7 @@ package inf112.fiasko.roborally.ui.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.ExtendViewport;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; import inf112.fiasko.roborally.networking.containers.ProgramAndPowerDownRequest;
import inf112.fiasko.roborally.objects.properties.GameState; import inf112.fiasko.roborally.objects.properties.GameState;
import inf112.fiasko.roborally.ui.RoboRallyWrapper; import inf112.fiasko.roborally.ui.RoboRallyWrapper;
@ -68,7 +68,7 @@ public class LoadingScreen extends AbstractScreen {
case SKIP_STAY_IN_POWER_DOWN: case SKIP_STAY_IN_POWER_DOWN:
return "Waiting for players to choose whether to stay in power down..."; return "Waiting for players to choose whether to stay in power down...";
default: default:
return "Waiting for something..."; return "Loading...";
} }
} }
@ -94,7 +94,7 @@ public class LoadingScreen extends AbstractScreen {
case SKIP_POWER_DOWN_SCREEN: case SKIP_POWER_DOWN_SCREEN:
roboRallyWrapper.roboRallyGame.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS); roboRallyWrapper.roboRallyGame.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS);
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper));
roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(false, new ArrayList<>())); roboRallyWrapper.client.sendElement(new ProgramAndPowerDownRequest(false, new ArrayList<>()));
break; break;
default: default:
//Ignored //Ignored

View File

@ -42,7 +42,32 @@ public class StartMenuScreen extends AbstractScreen {
textInput.setText(String.valueOf(roboRallyWrapper.networkPort)); textInput.setText(String.valueOf(roboRallyWrapper.networkPort));
stage.addActor(textInput); stage.addActor(textInput);
serverButton.addListener(new ClickListener() { serverButton.addListener(getCreateButtonListener());
TextButton clientButton = new SimpleButton("Join", roboRallyWrapper.font).getButton();
stage.addActor(clientButton);
clientButton.setY(applicationHeight / 2f);
camera.setToOrtho(false, applicationWidth, applicationHeight);
Gdx.input.setInputProcessor(stage);
clientButton.addListener(getJoinButtonListener());
TextButton quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton();
stage.addActor(quitButton);
quitButton.setY(applicationHeight / 2f);
camera.setToOrtho(false, applicationWidth, applicationHeight);
quitButton.addListener(getQuitButtonListener());
serverButton.setX(applicationWidth / 2f - serverButton.getWidth() - clientButton.getWidth() / 2 - 10);
clientButton.setX(applicationWidth / 2f - clientButton.getWidth() / 2);
quitButton.setX(applicationWidth / 2f + clientButton.getWidth() / 2 + 10);
}
/**
* Gets the listener for the create button
*
* @return A click listener to trigger on the create button
*/
private ClickListener getCreateButtonListener() {
return new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true; return true;
@ -61,14 +86,16 @@ public class StartMenuScreen extends AbstractScreen {
roboRallyWrapper.quit("Server could not be started"); roboRallyWrapper.quit("Server could not be started");
} }
} }
}); };
}
TextButton clientButton = new SimpleButton("Join", roboRallyWrapper.font).getButton(); /**
stage.addActor(clientButton); * Gets the listener for the join button
clientButton.setY(applicationHeight / 2f); *
camera.setToOrtho(false, applicationWidth, applicationHeight); * @return A click listener to trigger on the join button
Gdx.input.setInputProcessor(stage); */
clientButton.addListener(new ClickListener() { private ClickListener getJoinButtonListener() {
return new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true; return true;
@ -78,13 +105,16 @@ public class StartMenuScreen extends AbstractScreen {
public void touchUp(InputEvent event, float x, float y, int pointer, int button) { public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper)); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper));
} }
}); };
}
TextButton quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton(); /**
stage.addActor(quitButton); * Gets the listener for the quit button
quitButton.setY(applicationHeight / 2f); *
camera.setToOrtho(false, applicationWidth, applicationHeight); * @return A click listener to trigger on the quit button
quitButton.addListener(new ClickListener() { */
private ClickListener getQuitButtonListener() {
return new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true; return true;
@ -94,10 +124,7 @@ public class StartMenuScreen extends AbstractScreen {
public void touchUp(InputEvent event, float x, float y, int pointer, int button) { public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
roboRallyWrapper.quit(); roboRallyWrapper.quit();
} }
}); };
serverButton.setX(applicationWidth / 2f - serverButton.getWidth() - clientButton.getWidth() / 2 - 10);
clientButton.setX(applicationWidth / 2f - clientButton.getWidth() / 2);
quitButton.setX(applicationWidth / 2f + clientButton.getWidth() / 2 + 10);
} }
@Override @Override

View File

@ -32,7 +32,26 @@ public class UsernameScreen extends AbstractScreen {
TextButton confirm = new TextButton("Confirm", skin); TextButton confirm = new TextButton("Confirm", skin);
confirm.setSize(300, 60); confirm.setSize(300, 60);
confirm.setPosition(applicationWidth / 2f - confirm.getWidth() / 2, 300); confirm.setPosition(applicationWidth / 2f - confirm.getWidth() / 2, 300);
confirm.addListener(new ClickListener() { confirm.addListener(getConfirmButtonClickListener());
textInput = new TextField("", skin);
textInput.setPosition(applicationWidth / 2f - textInput.getWidth() / 2, 250);
textInput.setSize(150, 40);
stage.addActor(textInput);
stage.addActor(confirm);
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
stage.setViewport(viewport);
}
/**
* Gets the listener for the confirm button
*
* @return A click listener to trigger on the confirm button
*/
private ClickListener getConfirmButtonClickListener() {
return new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true; return true;
@ -52,17 +71,7 @@ public class UsernameScreen extends AbstractScreen {
} }
} }
}); };
textInput = new TextField("", skin);
textInput.setPosition(applicationWidth / 2f - textInput.getWidth() / 2, 250);
textInput.setSize(150, 40);
stage.addActor(textInput);
stage.addActor(confirm);
viewport = new FitViewport(applicationWidth, applicationHeight, camera);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
stage.setViewport(viewport);
} }
/** /**

View File

@ -26,7 +26,19 @@ public class WinnerScreen extends AbstractScreen {
stage.addActor(quitButton); stage.addActor(quitButton);
quitButton.setY(applicationHeight / 2f); quitButton.setY(applicationHeight / 2f);
camera.setToOrtho(false, applicationWidth, applicationHeight); camera.setToOrtho(false, applicationWidth, applicationHeight);
quitButton.addListener(new ClickListener() { quitButton.addListener(getQuitButtonListener());
quitButton.setX(applicationWidth / 2f + quitButton.getWidth() / 2);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
}
/**
* Gets the listener for the quit button
*
* @return A click listener to trigger on the quit button
*/
private ClickListener getQuitButtonListener() {
return new ClickListener() {
@Override @Override
public boolean touchDown(InputEvent e, float x, float y, int point, int button) { public boolean touchDown(InputEvent e, float x, float y, int point, int button) {
return true; return true;
@ -36,10 +48,7 @@ public class WinnerScreen extends AbstractScreen {
public void touchUp(InputEvent event, float x, float y, int pointer, int button) { public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.exit(); Gdx.app.exit();
} }
}); };
quitButton.setX(applicationWidth / 2f + quitButton.getWidth() / 2);
this.roboRallyWrapper = roboRallyWrapper;
camera.setToOrtho(false, applicationWidth, applicationHeight);
} }
@Override @Override

View File

@ -15,6 +15,9 @@ import java.util.List;
*/ */
public final class DeckLoaderUtil { public final class DeckLoaderUtil {
private DeckLoaderUtil() {
}
/** /**
* Returns a programming card deck containing all official programming cards * Returns a programming card deck containing all official programming cards
* *

View File

@ -13,6 +13,9 @@ import java.util.List;
*/ */
public final class GridUtil { public final class GridUtil {
private GridUtil() {
}
/** /**
* Gets all elements in a grid * Gets all elements in a grid
* *

View File

@ -3,7 +3,6 @@ package inf112.fiasko.roborally.utility;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.esotericsoftware.kryonet.Connection; import com.esotericsoftware.kryonet.Connection;
import inf112.fiasko.roborally.objects.DrawableGame; import inf112.fiasko.roborally.objects.DrawableGame;
import inf112.fiasko.roborally.ui.DrawableObject;
import inf112.fiasko.roborally.objects.Particle; import inf112.fiasko.roborally.objects.Particle;
import inf112.fiasko.roborally.objects.Player; import inf112.fiasko.roborally.objects.Player;
import inf112.fiasko.roborally.objects.Robot; import inf112.fiasko.roborally.objects.Robot;
@ -12,6 +11,7 @@ import inf112.fiasko.roborally.objects.Wall;
import inf112.fiasko.roborally.objects.properties.Direction; import inf112.fiasko.roborally.objects.properties.Direction;
import inf112.fiasko.roborally.objects.properties.Position; import inf112.fiasko.roborally.objects.properties.Position;
import inf112.fiasko.roborally.objects.properties.RobotID; import inf112.fiasko.roborally.objects.properties.RobotID;
import inf112.fiasko.roborally.ui.DrawableObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -21,6 +21,7 @@ import java.util.Map;
* This class helps with tasks which mix primitive classes and classes from external libraries * This class helps with tasks which mix primitive classes and classes from external libraries
*/ */
public final class IOUtil { public final class IOUtil {
private IOUtil() { private IOUtil() {
} }

View File

@ -10,6 +10,9 @@ import inf112.fiasko.roborally.objects.properties.WallType;
*/ */
public final class LaserHelper { public final class LaserHelper {
private LaserHelper() {
}
/** /**
* Gets the correct particle type from a laser type * Gets the correct particle type from a laser type
* *

View File

@ -7,7 +7,7 @@ import inf112.fiasko.roborally.networking.containers.HandResponse;
import inf112.fiasko.roborally.networking.containers.HurryResponse; import inf112.fiasko.roborally.networking.containers.HurryResponse;
import inf112.fiasko.roborally.networking.containers.OkayResponse; import inf112.fiasko.roborally.networking.containers.OkayResponse;
import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse; import inf112.fiasko.roborally.networking.containers.PowerDownContainerResponse;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; import inf112.fiasko.roborally.networking.containers.ProgramAndPowerDownRequest;
import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse; import inf112.fiasko.roborally.networking.containers.ProgramsContainerResponse;
import inf112.fiasko.roborally.networking.containers.UsernameRequest; import inf112.fiasko.roborally.networking.containers.UsernameRequest;
import inf112.fiasko.roborally.objects.Deck; import inf112.fiasko.roborally.objects.Deck;
@ -25,6 +25,9 @@ import java.util.HashMap;
*/ */
public final class NetworkUtil { public final class NetworkUtil {
private NetworkUtil() {
}
/** /**
* Registers all classes which can be sent between a server and a client * Registers all classes which can be sent between a server and a client
* *
@ -40,7 +43,7 @@ public final class NetworkUtil {
kryo.register(RobotID.class); kryo.register(RobotID.class);
kryo.register(ProgrammingCardDeck.class); kryo.register(ProgrammingCardDeck.class);
kryo.register(Action.class); kryo.register(Action.class);
kryo.register(ProgramAndPowerdownRequest.class); kryo.register(ProgramAndPowerDownRequest.class);
kryo.register(ProgramsContainerResponse.class); kryo.register(ProgramsContainerResponse.class);
kryo.register(PowerDownContainerResponse.class); kryo.register(PowerDownContainerResponse.class);
kryo.register(HashMap.class); kryo.register(HashMap.class);

View File

@ -6,6 +6,7 @@ import java.io.InputStream;
* This class helps with tasks related to resource loading * This class helps with tasks related to resource loading
*/ */
public final class ResourceUtil { public final class ResourceUtil {
private ResourceUtil() { private ResourceUtil() {
} }

View File

@ -1,7 +1,13 @@
package inf112.fiasko.roborally.utility; package inf112.fiasko.roborally.utility;
/**
* This class helps with tasks related to string manipulation
*/
public final class StringUtil { public final class StringUtil {
private StringUtil() {
}
/** /**
* Adds zeros to a number until it reaches a set length and converts it to a string * Adds zeros to a number until it reaches a set length and converts it to a string
* *