mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Forbedrer kommentarer og metodenavn
This commit is contained in:
parent
03c7e95e01
commit
d8acbc661d
@ -23,9 +23,10 @@ public class GameStartInfo {
|
|||||||
*
|
*
|
||||||
* @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
|
||||||
|
* @param playerName The player name of the receiver
|
||||||
*/
|
*/
|
||||||
public GameStartInfo(String boardName, List<Player> playerList, String name) {
|
public GameStartInfo(String boardName, List<Player> playerList, String playerName) {
|
||||||
this.playerName = name;
|
this.playerName = playerName;
|
||||||
this.boardName = boardName;
|
this.boardName = boardName;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
}
|
}
|
||||||
|
@ -161,16 +161,16 @@ public class Board {
|
|||||||
* Sets the power down status of the robot
|
* Sets the power down status of the robot
|
||||||
*
|
*
|
||||||
* @param robotID The robot id of the robot
|
* @param robotID The robot id of the robot
|
||||||
* @param powerdown The status of the powerdown
|
* @param powerDown The status of the power down
|
||||||
*/
|
*/
|
||||||
public void setPowerDown(RobotID robotID, Boolean powerdown) {
|
public void setPowerDown(RobotID robotID, Boolean powerDown) {
|
||||||
robots.get(robotID).setPowerDown(powerdown);
|
robots.get(robotID).setPowerDown(powerDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the power down status of the robot
|
* Gets the power down status of the robot
|
||||||
*
|
|
||||||
* @param robotID The robot id of the robot
|
* @param robotID The robot id of the robot
|
||||||
|
* @return The power down status of the robot
|
||||||
*/
|
*/
|
||||||
public boolean getPowerDown(RobotID robotID) {
|
public boolean getPowerDown(RobotID robotID) {
|
||||||
return robots.get(robotID).isInPowerDown();
|
return robots.get(robotID).isInPowerDown();
|
||||||
@ -190,7 +190,7 @@ public class Board {
|
|||||||
/**
|
/**
|
||||||
* sets the damage taken of robots in powerdown to 0
|
* sets the damage taken of robots in powerdown to 0
|
||||||
*/
|
*/
|
||||||
public void executePowerdown() {
|
public void executePowerDown() {
|
||||||
for (Robot robot : robots.values()) {
|
for (Robot robot : robots.values()) {
|
||||||
if (robot.isInPowerDown()) {
|
if (robot.isInPowerDown()) {
|
||||||
robot.setDamageTaken(0);
|
robot.setDamageTaken(0);
|
||||||
@ -826,7 +826,7 @@ public class Board {
|
|||||||
* @return If the robot has touched a flag this turn
|
* @return If the robot has touched a flag this turn
|
||||||
*/
|
*/
|
||||||
public boolean isHasTouchedFlagThisTurnFromRobotID(RobotID robotID) {
|
public boolean isHasTouchedFlagThisTurnFromRobotID(RobotID robotID) {
|
||||||
return robots.get(robotID).isHasTouchedFlagThisTurn();
|
return robots.get(robotID).hasTouchedFlagThisTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -81,4 +81,11 @@ public interface InteractableGame {
|
|||||||
*/
|
*/
|
||||||
void setProgram(List<ProgrammingCard> program);
|
void setProgram(List<ProgrammingCard> program);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the name of the player that won the game
|
||||||
|
*
|
||||||
|
* @param winningPlayerName The player winning the game
|
||||||
|
*/
|
||||||
|
void setWinningPlayerName(String winningPlayerName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public class Phase {
|
|||||||
private List<BoardElementContainer<Tile>> conveyorBelts;
|
private List<BoardElementContainer<Tile>> conveyorBelts;
|
||||||
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
||||||
private List<BoardElementContainer<Tile>> flags;
|
private List<BoardElementContainer<Tile>> flags;
|
||||||
private RoboRallyGame game;
|
private InteractableGame game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new phase
|
* Instantiates a new phase
|
||||||
@ -35,7 +35,7 @@ public class Phase {
|
|||||||
* @param cycleDelay The amount of milliseconds to wait between moves
|
* @param cycleDelay The amount of milliseconds to wait between moves
|
||||||
* @param game The game which uses this object
|
* @param game The game which uses this object
|
||||||
*/
|
*/
|
||||||
public Phase(Board gameBoard, List<Player> playerList, int cycleDelay, RoboRallyGame game) {
|
public Phase(Board gameBoard, List<Player> playerList, int cycleDelay, InteractableGame game) {
|
||||||
this.gameBoard = gameBoard;
|
this.gameBoard = gameBoard;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
this.cycleDelay = cycleDelay;
|
this.cycleDelay = cycleDelay;
|
||||||
@ -80,6 +80,7 @@ public class Phase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires all lasers on the game board
|
* Fires all lasers on the game board
|
||||||
|
* @throws InterruptedException If it gets interrupted while trying to sleep
|
||||||
*/
|
*/
|
||||||
public void fireAllLasers() throws InterruptedException {
|
public void fireAllLasers() throws InterruptedException {
|
||||||
gameBoard.fireAllLasers();
|
gameBoard.fireAllLasers();
|
||||||
|
@ -44,15 +44,6 @@ public class Player {
|
|||||||
return robotID;
|
return robotID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the robot id of the robot
|
|
||||||
*
|
|
||||||
* @param robotID The new id of the robot
|
|
||||||
*/
|
|
||||||
public void setRobotID(RobotID robotID) {
|
|
||||||
this.robotID = robotID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives you the Name of the player
|
* Gives you the Name of the player
|
||||||
*
|
*
|
||||||
@ -85,7 +76,7 @@ public class Player {
|
|||||||
*
|
*
|
||||||
* @return a deck
|
* @return a deck
|
||||||
*/
|
*/
|
||||||
public ProgrammingCardDeck getPlayerDeck() {
|
public ProgrammingCardDeck getProgrammingCardDeck() {
|
||||||
return playerDeck;
|
return playerDeck;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +85,7 @@ public class Player {
|
|||||||
*
|
*
|
||||||
* @param playerDeck A deck of cards given to the player
|
* @param playerDeck A deck of cards given to the player
|
||||||
*/
|
*/
|
||||||
public void setPlayerDeck(ProgrammingCardDeck playerDeck) {
|
public void setProgrammingCardDeck(ProgrammingCardDeck playerDeck) {
|
||||||
this.playerDeck = playerDeck;
|
this.playerDeck = playerDeck;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,19 +94,10 @@ public class Player {
|
|||||||
*
|
*
|
||||||
* @return a deck with locked cards
|
* @return a deck with locked cards
|
||||||
*/
|
*/
|
||||||
public ProgrammingCardDeck getLockedPlayerDeck() {
|
public ProgrammingCardDeck getLockedProgrammingCardDeck() {
|
||||||
return lockedPlayerDeck;
|
return lockedPlayerDeck;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the players locked deck to the given deck
|
|
||||||
*
|
|
||||||
* @param lockedPlayerDeck A deck of locked cards kept by the player
|
|
||||||
*/
|
|
||||||
public void setLockedPlayerDeck(ProgrammingCardDeck lockedPlayerDeck) {
|
|
||||||
this.lockedPlayerDeck = lockedPlayerDeck;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives you the players power down status
|
* Gives you the players power down status
|
||||||
*
|
*
|
||||||
@ -139,9 +121,9 @@ public class Player {
|
|||||||
*
|
*
|
||||||
* @param cardList list the size of 5 with programing cards
|
* @param cardList list the size of 5 with programing cards
|
||||||
*/
|
*/
|
||||||
public void setInProgram(List<ProgrammingCard> cardList) {
|
public void setProgram(List<ProgrammingCard> cardList) {
|
||||||
if (cardList.size() != 5) {
|
if (cardList.size() != 5) {
|
||||||
throw new IllegalArgumentException("list must contain 5 programing cards");
|
throw new IllegalArgumentException("The program must contain exactly 5 cards.");
|
||||||
} else {
|
} else {
|
||||||
program = new ArrayList<>(cardList);
|
program = new ArrayList<>(cardList);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
String playerName;
|
String playerName;
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
playerName = player.getName();
|
playerName = player.getName();
|
||||||
player.setInProgram(programMap.get(playerName));
|
player.setProgram(programMap.get(playerName));
|
||||||
player.setPowerDownNextRound(powerDown.get(playerName));
|
player.setPowerDownNextRound(powerDown.get(playerName));
|
||||||
}
|
}
|
||||||
//Runs 5 phases
|
//Runs 5 phases
|
||||||
@ -185,21 +185,13 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
resetHasTouchedFlagThisTurnForAllRobots();
|
resetHasTouchedFlagThisTurnForAllRobots();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Gets the name of the player that won the game
|
|
||||||
*
|
|
||||||
* @return The name of the winning player
|
|
||||||
*/
|
|
||||||
public String getWinningPlayerName() {
|
public String getWinningPlayerName() {
|
||||||
return winningPlayerName;
|
return winningPlayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Sets the name of the player that won the game
|
public void setWinningPlayerName(String winningPlayerName) {
|
||||||
*
|
|
||||||
* @param winningPlayerName The player winning the game
|
|
||||||
*/
|
|
||||||
protected void setWinningPlayerName(String winningPlayerName) {
|
|
||||||
this.winningPlayerName = winningPlayerName;
|
this.winningPlayerName = winningPlayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,15 +267,15 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
// Resets players power down for next turn to false.
|
// Resets players power down for next turn to false.
|
||||||
updateRobotPowerDown();
|
updateRobotPowerDown();
|
||||||
// Set damage of robots in power down to 0
|
// Set damage of robots in power down to 0
|
||||||
gameBoard.executePowerdown();
|
gameBoard.executePowerDown();
|
||||||
if (host) {
|
if (host) {
|
||||||
//Distributes programming cards for all players, and sends a deck to each player
|
//Distributes programming cards for all players, and sends a deck to each player
|
||||||
distributeProgrammingCardsToPlayers();
|
distributeProgrammingCardsToPlayers();
|
||||||
for (Connection connection : server.getPlayerNames().keySet()) {
|
for (Connection connection : server.getPlayerNames().keySet()) {
|
||||||
String playerName = server.getPlayerNames().get(connection);
|
String playerName = server.getPlayerNames().get(connection);
|
||||||
Player player = getPlayerFromName(playerName);
|
Player player = getPlayerFromName(playerName);
|
||||||
if (player != null && player.getPlayerDeck() != null) {
|
if (player != null && player.getProgrammingCardDeck() != null) {
|
||||||
server.sendToClient(connection, player.getPlayerDeck());
|
server.sendToClient(connection, player.getProgrammingCardDeck());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,8 +306,8 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
private void updateLockedProgrammingCardsForAllPlayers() {
|
private void updateLockedProgrammingCardsForAllPlayers() {
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
List<ProgrammingCard> playerProgram = player.getProgram();
|
List<ProgrammingCard> playerProgram = player.getProgram();
|
||||||
ProgrammingCardDeck playerDeck = player.getPlayerDeck();
|
ProgrammingCardDeck playerDeck = player.getProgrammingCardDeck();
|
||||||
ProgrammingCardDeck lockedPlayerDeck = player.getLockedPlayerDeck();
|
ProgrammingCardDeck lockedPlayerDeck = player.getLockedProgrammingCardDeck();
|
||||||
int robotDamage;
|
int robotDamage;
|
||||||
if (!gameBoard.isRobotAlive(player.getRobotID())) {
|
if (!gameBoard.isRobotAlive(player.getRobotID())) {
|
||||||
robotDamage = 0;
|
robotDamage = 0;
|
||||||
@ -325,7 +317,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
|
|
||||||
//The player has no locked cards. All previously locked cards should go into the free deck
|
//The player has no locked cards. All previously locked cards should go into the free deck
|
||||||
if (robotDamage <= 4) {
|
if (robotDamage <= 4) {
|
||||||
lockedPlayerDeck.emptyInto(player.getPlayerDeck());
|
lockedPlayerDeck.emptyInto(player.getProgrammingCardDeck());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +356,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
*/
|
*/
|
||||||
private void removeNonLockedProgrammingCardsFromPlayers() {
|
private void removeNonLockedProgrammingCardsFromPlayers() {
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
player.getPlayerDeck().emptyInto(mainDeck);
|
player.getProgrammingCardDeck().emptyInto(mainDeck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +367,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
mainDeck.shuffle();
|
mainDeck.shuffle();
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
RobotID robot = player.getRobotID();
|
RobotID robot = player.getRobotID();
|
||||||
ProgrammingCardDeck playerDeck = player.getPlayerDeck();
|
ProgrammingCardDeck playerDeck = player.getProgrammingCardDeck();
|
||||||
int robotDamage = gameBoard.getRobotDamage(robot);
|
int robotDamage = gameBoard.getRobotDamage(robot);
|
||||||
//Powered down or heavily damaged robots don't get any cards
|
//Powered down or heavily damaged robots don't get any cards
|
||||||
if (gameBoard.getPowerDown(robot) || robotDamage >= 9) {
|
if (gameBoard.getPowerDown(robot) || robotDamage >= 9) {
|
||||||
|
@ -36,7 +36,7 @@ public class Robot {
|
|||||||
*
|
*
|
||||||
* @return a boolean
|
* @return a boolean
|
||||||
*/
|
*/
|
||||||
public boolean isHasTouchedFlagThisTurn() {
|
public boolean hasTouchedFlagThisTurn() {
|
||||||
return hasTouchedFlagThisTurn;
|
return hasTouchedFlagThisTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public class BoardTest {
|
|||||||
boardforpowerdown.setPowerDown(RobotID.ROBOT_2, true);
|
boardforpowerdown.setPowerDown(RobotID.ROBOT_2, true);
|
||||||
testrobot.setDamageTaken(4);
|
testrobot.setDamageTaken(4);
|
||||||
assertEquals(4, testrobot.getDamageTaken());
|
assertEquals(4, testrobot.getDamageTaken());
|
||||||
boardforpowerdown.executePowerdown();
|
boardforpowerdown.executePowerDown();
|
||||||
assertEquals(0, testrobot.getDamageTaken());
|
assertEquals(0, testrobot.getDamageTaken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class PlayerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInProgram() {
|
public void testSetInProgram() {
|
||||||
playerTest.setInProgram(cards);
|
playerTest.setProgram(cards);
|
||||||
assertEquals(Action.MOVE_1, playerTest.getProgram().get(0).getAction());
|
assertEquals(Action.MOVE_1, playerTest.getProgram().get(0).getAction());
|
||||||
assertEquals(Action.MOVE_2, playerTest.getProgram().get(1).getAction());
|
assertEquals(Action.MOVE_2, playerTest.getProgram().get(1).getAction());
|
||||||
assertEquals(Action.MOVE_3, playerTest.getProgram().get(2).getAction());
|
assertEquals(Action.MOVE_3, playerTest.getProgram().get(2).getAction());
|
||||||
@ -51,15 +51,15 @@ public class PlayerTest {
|
|||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testSetInProgramWithToManyCards() {
|
public void testSetInProgramWithToManyCards() {
|
||||||
cards.add(new ProgrammingCard(10, Action.ROTATE_LEFT));
|
cards.add(new ProgrammingCard(10, Action.ROTATE_LEFT));
|
||||||
playerTest.setInProgram(cards);
|
playerTest.setProgram(cards);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetInDeck() {
|
public void testSetInDeck() {
|
||||||
cards.add(new ProgrammingCard(10, Action.ROTATE_LEFT));
|
cards.add(new ProgrammingCard(10, Action.ROTATE_LEFT));
|
||||||
ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards);
|
ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards);
|
||||||
playerTest.setPlayerDeck(playerDeck);
|
playerTest.setProgrammingCardDeck(playerDeck);
|
||||||
assertEquals(playerDeck, playerTest.getPlayerDeck());
|
assertEquals(playerDeck, playerTest.getProgrammingCardDeck());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -74,7 +74,7 @@ public class PlayerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProgramFromPlayer() {
|
public void getProgramFromPlayer() {
|
||||||
playerTest.setInProgram(cards);
|
playerTest.setProgram(cards);
|
||||||
assertEquals(cards, playerTest.getProgram());
|
assertEquals(cards, playerTest.getProgram());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user