Auto reformaterer alle klasser for nettverk

This commit is contained in:
Kristian Knarvik 2020-04-20 13:12:07 +02:00
parent a19e616257
commit 36b934242d
9 changed files with 97 additions and 57 deletions

View File

@ -11,8 +11,10 @@ import java.io.IOException;
*/ */
public class RoboRallyClient { public class RoboRallyClient {
private final Client client; private final Client client;
/** /**
* Instantiates a new Robo Rally client * Instantiates a new Robo Rally client
*
* @param ipAddress The ip address of the server to connect to * @param ipAddress The ip address of the server to connect to
* @param wrapper The Robo Rally wrapper to be used * @param wrapper The Robo Rally wrapper to be used
* @throws IOException If the server cannot be reached * @throws IOException If the server cannot be reached
@ -28,11 +30,15 @@ public class RoboRallyClient {
/** /**
* Sends something to the server * Sends something to the server
*
* @param object The object to send to the server * @param object The object to send to the server
*/ */
public void sendElement(Object object) {try{ public void sendElement(Object object) {
client.sendTCP(object);} try {
catch(Exception e){e.printStackTrace();} client.sendTCP(object);
} catch (Exception e) {
e.printStackTrace();
}
} }
} }

View File

@ -6,7 +6,7 @@ import inf112.fiasko.roborally.elementproperties.GameState;
import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper;
import inf112.fiasko.roborally.networking.containers.ErrorResponse; import inf112.fiasko.roborally.networking.containers.ErrorResponse;
import inf112.fiasko.roborally.networking.containers.GameStartInfo; import inf112.fiasko.roborally.networking.containers.GameStartInfo;
import inf112.fiasko.roborally.networking.containers.PowerdownContainer; import inf112.fiasko.roborally.networking.containers.PowerDownContainer;
import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
import inf112.fiasko.roborally.objects.ProgrammingCardDeck; import inf112.fiasko.roborally.objects.ProgrammingCardDeck;
import inf112.fiasko.roborally.objects.RoboRallyGame; import inf112.fiasko.roborally.objects.RoboRallyGame;
@ -19,6 +19,7 @@ class RoboRallyClientListener extends Listener {
/** /**
* Instantiates a new Robo Rally client listener * Instantiates a new Robo Rally client listener
*
* @param wrapper The Robo Rally wrapper to interact with * @param wrapper The Robo Rally wrapper to interact with
*/ */
RoboRallyClientListener(RoboRallyWrapper wrapper) { RoboRallyClientListener(RoboRallyWrapper wrapper) {
@ -37,7 +38,7 @@ class RoboRallyClientListener extends Listener {
} else if (object instanceof GameStartInfo) { } else if (object instanceof GameStartInfo) {
GameStartInfo info = (GameStartInfo) object; GameStartInfo info = (GameStartInfo) object;
wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(), wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(),
wrapper.server != null, info.getPlayerName(), wrapper.client, wrapper.server); wrapper.server != null, info.getPlayerName(), wrapper.server);
} else if (object instanceof ProgrammingCardDeck) { } else if (object instanceof ProgrammingCardDeck) {
wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS); wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS);
wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object); wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object);
@ -47,8 +48,8 @@ class RoboRallyClientListener extends Listener {
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} else if (object instanceof PowerdownContainer) { } else if (object instanceof PowerDownContainer) {
wrapper.roboRallyGame.receiveStayInPowerDown((PowerdownContainer) object); wrapper.roboRallyGame.receiveStayInPowerDown((PowerDownContainer) object);
} }
} }

View File

@ -4,6 +4,7 @@ import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Server; import com.esotericsoftware.kryonet.Server;
import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.elementproperties.RobotID;
import inf112.fiasko.roborally.utility.NetworkUtil; import inf112.fiasko.roborally.utility.NetworkUtil;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -17,6 +18,7 @@ public class RoboRallyServer {
/** /**
* Instantiates a new Robo Rally server * Instantiates a new Robo Rally server
*
* @throws IOException If the server cannot be started * @throws IOException If the server cannot be started
*/ */
public RoboRallyServer() throws IOException { public RoboRallyServer() throws IOException {
@ -30,6 +32,7 @@ public class RoboRallyServer {
/** /**
* Makes notice of players which are dead and as such should not be expected to send anything * Makes notice of players which are dead and as such should not be expected to send anything
*
* @param deadRobotList A list of robot ids of robots which are permanently dead * @param deadRobotList A list of robot ids of robots which are permanently dead
*/ */
public void setDeadPlayers(List<RobotID> deadRobotList) { public void setDeadPlayers(List<RobotID> deadRobotList) {
@ -38,6 +41,7 @@ public class RoboRallyServer {
/** /**
* Gets a map between connections and their robot id * Gets a map between connections and their robot id
*
* @return A mapping between connections and robot ids * @return A mapping between connections and robot ids
*/ */
public Map<Connection, RobotID> getRobotID() { public Map<Connection, RobotID> getRobotID() {
@ -46,6 +50,7 @@ public class RoboRallyServer {
/** /**
* Gets a map between connections and their player name * Gets a map between connections and their player name
*
* @return A mapping between connections and robot ids * @return A mapping between connections and robot ids
*/ */
public Map<Connection, String> getPlayerNames() { public Map<Connection, String> getPlayerNames() {
@ -54,6 +59,7 @@ public class RoboRallyServer {
/** /**
* Sends an object to all clients * Sends an object to all clients
*
* @param object The object to send * @param object The object to send
*/ */
public void sendToAllClients(Object object) { public void sendToAllClients(Object object) {
@ -62,6 +68,7 @@ public class RoboRallyServer {
/** /**
* Sends an object to a specific client * Sends an object to a specific client
*
* @param connection The connection to send the object to * @param connection The connection to send the object to
* @param object The object to send * @param object The object to send
*/ */

View File

@ -5,12 +5,11 @@ import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener; import com.esotericsoftware.kryonet.Listener;
import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.elementproperties.RobotID;
import inf112.fiasko.roborally.networking.containers.ErrorResponse; import inf112.fiasko.roborally.networking.containers.ErrorResponse;
import inf112.fiasko.roborally.networking.containers.PowerdownContainer; import inf112.fiasko.roborally.networking.containers.PowerDownContainer;
import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import inf112.fiasko.roborally.networking.containers.ProgamsContainer;
import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest;
import inf112.fiasko.roborally.objects.ProgrammingCard; import inf112.fiasko.roborally.objects.ProgrammingCard;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -21,16 +20,17 @@ import java.util.Set;
* This listener handles all sending and responses for the server * This listener handles all sending and responses for the server
*/ */
class RoboRallyServerListener extends Listener { class RoboRallyServerListener extends Listener {
private Connection host;
private final Map<Connection, RobotID> clients; private final Map<Connection, RobotID> clients;
private final Map<Connection, String> playerNames; private final Map<Connection, String> playerNames;
private final List<Connection> deadPlayers; private final List<Connection> deadPlayers;
private final RoboRallyServer server;
private Connection host;
private Map<Connection, Boolean> stayInPowerDown; private Map<Connection, Boolean> stayInPowerDown;
private Map<Connection, ProgramAndPowerdownRequest> programs; private Map<Connection, ProgramAndPowerdownRequest> programs;
private final RoboRallyServer server;
/** /**
* Instantiates a new Robo Rally server listener * Instantiates a new Robo Rally server listener
*
* @param server The Robo Rally server using the listener * @param server The Robo Rally server using the listener
*/ */
RoboRallyServerListener(RoboRallyServer server) { RoboRallyServerListener(RoboRallyServer server) {
@ -45,6 +45,7 @@ class RoboRallyServerListener extends Listener {
/** /**
* Lets the server know which players have lost this game. * Lets the server know which players have lost this game.
*
* @param deadRobots List of RobotID * @param deadRobots List of RobotID
*/ */
public void setDeadPlayers(List<RobotID> deadRobots) { public void setDeadPlayers(List<RobotID> deadRobots) {
@ -59,6 +60,7 @@ class RoboRallyServerListener extends Listener {
/** /**
* Gets a map between connections and their player name * Gets a map between connections and their player name
*
* @return A mapping between connections and robot ids * @return A mapping between connections and robot ids
*/ */
public Map<Connection, String> getPlayerNames() { public Map<Connection, String> getPlayerNames() {
@ -67,6 +69,7 @@ class RoboRallyServerListener extends Listener {
/** /**
* Gets a map between connections and their robot id * Gets a map between connections and their robot id
*
* @return A mapping between connections and robot ids * @return A mapping between connections and robot ids
*/ */
public Map<Connection, RobotID> getRobotID() { public Map<Connection, RobotID> getRobotID() {
@ -86,6 +89,7 @@ class RoboRallyServerListener extends Listener {
/** /**
* Handles the receiving of a string, handled as a player name in this context * Handles the receiving of a string, handled as a player name in this context
*
* @param connection The connection sending the string * @param connection The connection sending the string
* @param playerName The player name received * @param playerName The player name received
*/ */
@ -100,6 +104,7 @@ class RoboRallyServerListener extends Listener {
/** /**
* Handles the receiving of continuing power down * Handles the receiving of continuing power down
*
* @param connection The connection sending the stay in power down value * @param connection The connection sending the stay in power down value
* @param bool The stay in power down value received * @param bool The stay in power down value received
*/ */
@ -110,13 +115,14 @@ class RoboRallyServerListener extends Listener {
for (Connection connected : stayInPowerDown.keySet()) { for (Connection connected : stayInPowerDown.keySet()) {
powerDowns.put(playerNames.get(connected), stayInPowerDown.get(connected)); powerDowns.put(playerNames.get(connected), stayInPowerDown.get(connected));
} }
server.sendToAllClients(new PowerdownContainer(powerDowns)); server.sendToAllClients(new PowerDownContainer(powerDowns));
stayInPowerDown = new HashMap<>(); stayInPowerDown = new HashMap<>();
} }
} }
/** /**
* Handles the receiving of a player's program and whether they want to power down * Handles the receiving of a player's program and whether they want to power down
*
* @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
*/ */
@ -136,6 +142,7 @@ class RoboRallyServerListener extends Listener {
/** /**
* Checks whether the input map contains data received by all expected connections * Checks whether the input map contains data received by all expected connections
*
* @param data A map between connections and some type of data * @param data A map between connections and some type of data
* @param <K> The type of the data contained in the map * @param <K> The type of the data contained in the map
* @return True if information has been received by all alive players * @return True if information has been received by all alive players

View File

@ -9,6 +9,7 @@ public class ErrorResponse {
/** /**
* Constructs a new error response * Constructs a new error response
*
* @param errorMessage The error message describing the error * @param errorMessage The error message describing the error
*/ */
public ErrorResponse(String errorMessage) { public ErrorResponse(String errorMessage) {
@ -18,6 +19,7 @@ public class ErrorResponse {
/** /**
* Constructs a new error response * Constructs a new error response
*
* @param errorMessage The error message describing the error * @param errorMessage The error message describing the error
* @param critical Whether the error is critical * @param critical Whether the error is critical
*/ */
@ -28,6 +30,7 @@ public class ErrorResponse {
/** /**
* Gets the error message attached to the error response * Gets the error message attached to the error response
*
* @return An error message * @return An error message
*/ */
public String getErrorMessage() { public String getErrorMessage() {
@ -36,6 +39,7 @@ public class ErrorResponse {
/** /**
* Gets whether the error is critical or not * Gets whether the error is critical or not
*
* @return True if the error is critical. False otherwise * @return True if the error is critical. False otherwise
*/ */
public boolean isCritical() { public boolean isCritical() {

View File

@ -15,42 +15,12 @@ public class GameStartInfo {
/** /**
* Empty initialization method required by kryo * Empty initialization method required by kryo
*/ */
public GameStartInfo() {} public GameStartInfo() {
/**
* 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 player name of the current player
* @return The player name of the current player
*/
public String getPlayerName() {
return playerName;
}
/**
* 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;
}
/**
* Sets the list of players for the game
* @param playerList List of players for the game
*/
public void setPlayerList(List<Player> playerList) {
this.playerList = playerList;
} }
/** /**
* Instantiates a new GameStartInfo object * Instantiates a new GameStartInfo object
*
* @param boardName The name of the board to be used, with extension * @param boardName The name of the board to be used, with extension
* @param playerList List of players for the game * @param playerList List of players for the game
*/ */
@ -60,20 +30,58 @@ public class GameStartInfo {
this.playerList = playerList; this.playerList = playerList;
} }
/**
* Gets the player name of the current player
*
* @return The player name of the current player
*/
public String getPlayerName() {
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 * Gets the list of players
*
* @return A list of players * @return A list of players
*/ */
public List<Player> getPlayerList() { public List<Player> getPlayerList() {
return playerList; return playerList;
} }
/**
* Sets the list of players for the game
*
* @param playerList List of players for the game
*/
public void setPlayerList(List<Player> playerList) {
this.playerList = playerList;
}
/** /**
* Gets the board name * Gets the board name
*
* @return The board name * @return The board name
*/ */
public String getBoardName() { public String getBoardName() {
return boardName; 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;
}
} }

View File

@ -5,19 +5,21 @@ import java.util.Map;
/** /**
* This class is used to contain power down status for all players * This class is used to contain power down status for all players
*/ */
public class PowerdownContainer { public class PowerDownContainer {
private final Map<String, Boolean> powerDown; private final Map<String, Boolean> powerDown;
/** /**
* Instantiates a new power down container * Instantiates a new power down container
*
* @param powerDown A map between player names and whether they should remain in power down * @param powerDown A map between player names and whether they should remain in power down
*/ */
public PowerdownContainer(Map<String, Boolean> powerDown) { public PowerDownContainer(Map<String, Boolean> powerDown) {
this.powerDown = powerDown; this.powerDown = powerDown;
} }
/** /**
* Gets the power down map stored in the container * Gets the power down map stored in the container
*
* @return A map between player name and stay in power down * @return A map between player name and stay in power down
*/ */
public Map<String, Boolean> getPowerDown() { public Map<String, Boolean> getPowerDown() {

View File

@ -9,7 +9,9 @@ public class ProgamsContainer {
private Map<String, List<ProgrammingCard>> program; private Map<String, List<ProgrammingCard>> program;
private Map<String, Boolean> powerdown; private Map<String, Boolean> powerdown;
public ProgamsContainer(){} public ProgamsContainer() {
}
public ProgamsContainer(Map<String, List<ProgrammingCard>> program, Map<String, Boolean> powerdown) { public ProgamsContainer(Map<String, List<ProgrammingCard>> program, Map<String, Boolean> powerdown) {
this.program = program; this.program = program;
this.powerdown = powerdown; this.powerdown = powerdown;
@ -18,6 +20,7 @@ public class ProgamsContainer {
public Map<String, List<ProgrammingCard>> getProgram() { public Map<String, List<ProgrammingCard>> getProgram() {
return program; return program;
} }
public Map<String, Boolean> getPowerdown() { public Map<String, Boolean> getPowerdown() {
return powerdown; return powerdown;
} }

View File

@ -8,7 +8,9 @@ public class ProgramAndPowerdownRequest {
private Boolean powerdown; private Boolean powerdown;
private List<ProgrammingCard> program; private List<ProgrammingCard> program;
public ProgramAndPowerdownRequest(){} public ProgramAndPowerdownRequest() {
}
public ProgramAndPowerdownRequest(Boolean powerdown, List<ProgrammingCard> program) { public ProgramAndPowerdownRequest(Boolean powerdown, List<ProgrammingCard> program) {
this.program = program; this.program = program;
this.powerdown = powerdown; this.powerdown = powerdown;