mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Legger til og forbedrer kommentarer i RoboRallyGame
This commit is contained in:
parent
f46d2f4e29
commit
b5eae63892
@ -29,6 +29,7 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
private List<BoardElementContainer<Tile>> conveyorBelts;
|
private List<BoardElementContainer<Tile>> conveyorBelts;
|
||||||
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
||||||
private List<BoardElementContainer<Tile>> repairTiles;
|
private List<BoardElementContainer<Tile>> repairTiles;
|
||||||
|
private List<BoardElementContainer<Tile>> flags;
|
||||||
private final List<Player> playerList;
|
private final List<Player> playerList;
|
||||||
private final boolean host;
|
private final boolean host;
|
||||||
private Deck<ProgrammingCard> mainDeck;
|
private Deck<ProgrammingCard> mainDeck;
|
||||||
@ -38,50 +39,19 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
private RoboRallyServer server;
|
private RoboRallyServer server;
|
||||||
private String winningPlayerName;
|
private String winningPlayerName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Robo Rally game
|
||||||
public String getPlayerName() {
|
* @param playerList A list of all the players participating in the game
|
||||||
return playerName;
|
* @param boardName The playerName of the board to use
|
||||||
}
|
* @param host Whether this player is the host
|
||||||
|
* @param playerName The name of the player of this instance of the game
|
||||||
public void setPlayerName(String playerName) {
|
* @param client The client used to send data to the server
|
||||||
|
* @param server The server if this player is host. Should be null otherwise
|
||||||
|
* @param debug Whether this game is to use the debugging board
|
||||||
|
*/
|
||||||
|
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName,
|
||||||
|
RoboRallyClient client, RoboRallyServer server, boolean debug) {
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getWinningPlayerName() {
|
|
||||||
return winningPlayerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWinningPlayerName(String winningPlayerName) {
|
|
||||||
this.winningPlayerName = winningPlayerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the gameState of the game
|
|
||||||
* @return the gameState of the game
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public GameState getGameState(){
|
|
||||||
return gameState;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the gameState of the game
|
|
||||||
* @param gameState the gameState
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setGameState(GameState gameState) {
|
|
||||||
this.gameState = gameState;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new robo rally game
|
|
||||||
* @param debug Whether to start the game in debugging mode
|
|
||||||
*/
|
|
||||||
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String name, RoboRallyClient client,
|
|
||||||
RoboRallyServer server, boolean debug) {
|
|
||||||
this.playerName = name;
|
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
@ -94,10 +64,16 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new robo rally game
|
* Instantiates a new Robo Rally game
|
||||||
|
* @param playerList A list of all the players participating in the game
|
||||||
|
* @param boardName The playerName of the board to use
|
||||||
|
* @param host Whether this player is the host
|
||||||
|
* @param playerName The name of the player of this instance of the game
|
||||||
|
* @param client The client used to send data to the server
|
||||||
|
* @param server The server if this player is host. Should be null otherwise
|
||||||
*/
|
*/
|
||||||
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName, RoboRallyClient client,
|
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName,
|
||||||
RoboRallyServer server) {
|
RoboRallyClient client, RoboRallyServer server) {
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
@ -136,6 +112,41 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
return gameBoard.getAliveRobots();
|
return gameBoard.getAliveRobots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GameState getGameState(){
|
||||||
|
return gameState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGameState(GameState gameState) {
|
||||||
|
this.gameState = gameState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of the player playing this instance of the game
|
||||||
|
* @return The name of this player
|
||||||
|
*/
|
||||||
|
public String getPlayerName() {
|
||||||
|
return playerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name of the player playing this instance of the game
|
||||||
|
* @param playerName The new name of this player
|
||||||
|
*/
|
||||||
|
public void setPlayerName(String playerName) {
|
||||||
|
this.playerName = playerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of the player that won the game
|
||||||
|
* @return The name of the winning player
|
||||||
|
*/
|
||||||
|
public String getWinningPlayerName() {
|
||||||
|
return winningPlayerName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the game thread wait a given time amount before continuing.
|
* Makes the game thread wait a given time amount before continuing.
|
||||||
* @throws InterruptedException If interrupted while trying to sleep.
|
* @throws InterruptedException If interrupted while trying to sleep.
|
||||||
@ -218,7 +229,15 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
|
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
|
||||||
repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
|
repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
|
||||||
TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
|
TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
|
||||||
|
flags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
|
||||||
|
TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a player object given a player name
|
||||||
|
* @param name The name of the player to get
|
||||||
|
* @return The corresponding player object or null if no such object exists
|
||||||
|
*/
|
||||||
private Player getPlayerFromName(String name) {
|
private Player getPlayerFromName(String name) {
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
if (player.getName().equals(name)) {
|
if (player.getName().equals(name)) {
|
||||||
@ -295,6 +314,9 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
resetHasTouchedFlagThisTurnForAllRobots();
|
resetHasTouchedFlagThisTurnForAllRobots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends information about players no longer part of the game to the server
|
||||||
|
*/
|
||||||
private void sendAllDeadPlayersToServer() {
|
private void sendAllDeadPlayersToServer() {
|
||||||
if (host) {
|
if (host) {
|
||||||
server.setDeadPlayers(gameBoard.getRealDeadRobots());
|
server.setDeadPlayers(gameBoard.getRealDeadRobots());
|
||||||
@ -385,6 +407,14 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name of the player that won the game
|
||||||
|
* @param winningPlayerName The player winning the game
|
||||||
|
*/
|
||||||
|
private void setWinningPlayerName(String winningPlayerName) {
|
||||||
|
this.winningPlayerName = winningPlayerName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs one phase as defined in the Robo Rally rulebook
|
* Runs one phase as defined in the Robo Rally rulebook
|
||||||
* @param phaseNumber The number of the phase to run
|
* @param phaseNumber The number of the phase to run
|
||||||
@ -550,9 +580,7 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
* Checks all flags for robots. Tries to update the flag of the robot.
|
* Checks all flags for robots. Tries to update the flag of the robot.
|
||||||
*/
|
*/
|
||||||
private void checkAllFlags() {
|
private void checkAllFlags() {
|
||||||
List<BoardElementContainer<Tile>> listOfFlags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
|
for (BoardElementContainer<Tile> flag:flags) {
|
||||||
TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
|
|
||||||
for (BoardElementContainer<Tile> flag:listOfFlags) {
|
|
||||||
Position flagPosition = flag.getPosition();
|
Position flagPosition = flag.getPosition();
|
||||||
if (gameBoard.hasRobotOnPosition(flagPosition)) {
|
if (gameBoard.hasRobotOnPosition(flagPosition)) {
|
||||||
RobotID robotID = gameBoard.getRobotOnPosition(flagPosition);
|
RobotID robotID = gameBoard.getRobotOnPosition(flagPosition);
|
||||||
@ -562,7 +590,7 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
}
|
}
|
||||||
gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
|
gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
|
||||||
robot.setHasTouchedFlagThisTurn(true);
|
robot.setHasTouchedFlagThisTurn(true);
|
||||||
if (victoryCheck(robot.getLastFlagVisited(), listOfFlags.size())) {
|
if (victoryCheck(robot.getLastFlagVisited(), flags.size())) {
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
if (player.getRobotID() != robotID) {
|
if (player.getRobotID() != robotID) {
|
||||||
continue;
|
continue;
|
||||||
@ -576,9 +604,17 @@ public class RoboRallyGame implements IRoboRallyGame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a player has won
|
||||||
|
* @param lastFlagVisited The last flag the player visited
|
||||||
|
* @param lastFlag The last flag of the board
|
||||||
|
* @return True if the player has visited the last flag
|
||||||
|
*/
|
||||||
private boolean victoryCheck(int lastFlagVisited, int lastFlag) {
|
private boolean victoryCheck(int lastFlagVisited, int lastFlag) {
|
||||||
return (lastFlagVisited == lastFlag);
|
return (lastFlagVisited == lastFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires all lasers on the game board
|
* Fires all lasers on the game board
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user