mirror of
				https://github.com/inf112-v20/Fiasko.git
				synced 2025-11-04 11:43:44 +01:00 
			
		
		
		
	Merge branch 'master' of https://github.com/inf112-v20/Fiasko
Conflicts: src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java
This commit is contained in:
		@@ -29,6 +29,7 @@ public class RoboRallyGame implements IRoboRallyGame {
 | 
			
		||||
    private List<BoardElementContainer<Tile>> conveyorBelts;
 | 
			
		||||
    private List<BoardElementContainer<Tile>> fastConveyorBelts;
 | 
			
		||||
    private List<BoardElementContainer<Tile>> repairTiles;
 | 
			
		||||
    private List<BoardElementContainer<Tile>> flags;
 | 
			
		||||
    private final List<Player> playerList;
 | 
			
		||||
    private final boolean host;
 | 
			
		||||
    private Deck<ProgrammingCard> mainDeck;
 | 
			
		||||
@@ -38,50 +39,19 @@ public class RoboRallyGame implements IRoboRallyGame {
 | 
			
		||||
    private RoboRallyServer server;
 | 
			
		||||
    private String winningPlayerName;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public String getPlayerName() {
 | 
			
		||||
        return playerName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPlayerName(String playerName) {
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     * @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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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.playerList = playerList;
 | 
			
		||||
        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,
 | 
			
		||||
                         RoboRallyServer server) {
 | 
			
		||||
    public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName,
 | 
			
		||||
                         RoboRallyClient client, RoboRallyServer server) {
 | 
			
		||||
        this.playerName = playerName;
 | 
			
		||||
        this.host = host;
 | 
			
		||||
        this.playerList = playerList;
 | 
			
		||||
@@ -136,6 +112,41 @@ public class RoboRallyGame implements IRoboRallyGame {
 | 
			
		||||
        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.
 | 
			
		||||
     * @throws InterruptedException If interrupted while trying to sleep.
 | 
			
		||||
@@ -218,10 +229,18 @@ public class RoboRallyGame implements IRoboRallyGame {
 | 
			
		||||
                TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
 | 
			
		||||
        repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
 | 
			
		||||
                TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
 | 
			
		||||
        flags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
 | 
			
		||||
                TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
 | 
			
		||||
    }
 | 
			
		||||
    private Player getPlayerFromName(String name){
 | 
			
		||||
        for (Player player:playerList) {
 | 
			
		||||
            if(player.getName().equals(name)){
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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) {
 | 
			
		||||
        for (Player player : playerList) {
 | 
			
		||||
            if (player.getName().equals(name)) {
 | 
			
		||||
                return player;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -295,6 +314,9 @@ public class RoboRallyGame implements IRoboRallyGame {
 | 
			
		||||
        resetHasTouchedFlagThisTurnForAllRobots();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sends information about players no longer part of the game to the server
 | 
			
		||||
     */
 | 
			
		||||
    private void sendAllDeadPlayersToServer() {
 | 
			
		||||
        if (host) {
 | 
			
		||||
            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
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    private void checkAllFlags() {
 | 
			
		||||
        List<BoardElementContainer<Tile>> listOfFlags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
 | 
			
		||||
                TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
 | 
			
		||||
        for (BoardElementContainer<Tile> flag:listOfFlags) {
 | 
			
		||||
        for (BoardElementContainer<Tile> flag:flags) {
 | 
			
		||||
            Position flagPosition = flag.getPosition();
 | 
			
		||||
            if (!gameBoard.hasRobotOnPosition(flagPosition)) {
 | 
			
		||||
                continue;
 | 
			
		||||
@@ -563,7 +591,7 @@ public class RoboRallyGame implements IRoboRallyGame {
 | 
			
		||||
            }
 | 
			
		||||
            gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType());
 | 
			
		||||
            gameBoard.setHasTouchedFlagThisTurnFromRobotID(robotID,true);
 | 
			
		||||
            checkIfPlayerWon(robotID, listOfFlags.size());
 | 
			
		||||
            checkIfPlayerWon(robotID, flags.size());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -585,10 +613,10 @@ public class RoboRallyGame implements IRoboRallyGame {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks if last flag visited is the last flag
 | 
			
		||||
     * @param lastFlagVisited The last flag a robot visited
 | 
			
		||||
     * @param lastFlag The last flag on the map
 | 
			
		||||
     * @return If the robot won
 | 
			
		||||
     * 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) {
 | 
			
		||||
        return (lastFlagVisited == lastFlag);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user