mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-07-28 18:55:26 +02:00
Rydder kraftig opp i koden
Legger til alle manglende kommentarer Fikser en del variabelnavn med feil camelCase Legger til en boks som gir beskjed om at et navn ikke kan være tomt Oppdaterer versjon i pom og readme Forenkler noen av testene Fjerner duplisert kode i tester Fikser problemer rapportert av Codacy Bytter navn på respons beholdere for å tydeliggjøre bruk Fjerner ubrukte metoder Fikser noen skrivefeil
This commit is contained in:
@@ -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()) {
|
||||
|
@@ -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
|
||||
|
@@ -25,7 +25,7 @@ public class Phase {
|
||||
private List<BoardElementContainer<Tile>> conveyorBelts;
|
||||
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
||||
private List<BoardElementContainer<Tile>> flags;
|
||||
private InteractableGame game;
|
||||
private final InteractableGame game;
|
||||
|
||||
/**
|
||||
* Instantiates a new phase
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -21,8 +21,10 @@ public class ProgrammingCard implements Comparable<ProgrammingCard> {
|
||||
this.cardAction = cardAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
|
||||
*/
|
||||
public ProgrammingCard() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,6 +16,9 @@ public class ProgrammingCardDeck extends AbstractDeck<ProgrammingCard> {
|
||||
super(cardList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty constructor required by KryoNet. DO NOT REMOVE THIS!!!
|
||||
*/
|
||||
public ProgrammingCardDeck() {
|
||||
}
|
||||
}
|
||||
|
@@ -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<ProgrammingCard> 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<String, List<ProgrammingCard>> programMap = programs.getProgram();
|
||||
Map<String, Boolean> powerDown = programs.getPowerdown();
|
||||
Map<String, List<ProgrammingCard>> programMap = programs.getProgramsMap();
|
||||
Map<String, Boolean> 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<Robot> 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<BoardElementContainer<Tile>> 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<Tile> spawnTileContainer = spawnTileContainerList.get(0);
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user