mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Fikser en feil i oppdatering av låste kort
Fikser noen formateringsfeil Fikser noen variabelnavn Erstatter runGameLoop med runTurn Endrer navn på metode for å oppdatere låste programmeringskort Fjerner unødvendinge linjer som ikke gjør noe
This commit is contained in:
parent
4a885f9fc0
commit
b3fee7494f
@ -24,15 +24,16 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
private List<BoardElementContainer<Tile>> cogwheels;
|
private List<BoardElementContainer<Tile>> cogwheels;
|
||||||
private List<BoardElementContainer<Tile>> conveyorBelts;
|
private List<BoardElementContainer<Tile>> conveyorBelts;
|
||||||
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
||||||
private List<Player> playerList;
|
private final List<Player> playerList;
|
||||||
private final boolean host;
|
private final boolean host;
|
||||||
private Deck<ProgrammingCard> mainDeck;
|
private Deck<ProgrammingCard> mainDeck;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new robo rally game
|
* Instantiates a new robo rally game
|
||||||
* @param debug Whether to start the game in debugging mode
|
* @param debug Whether to start the game in debugging mode
|
||||||
*/
|
*/
|
||||||
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, boolean debug) {
|
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, boolean debug) {
|
||||||
this.host=host;
|
this.host = host;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
initializeDebugMode();
|
initializeDebugMode();
|
||||||
@ -45,7 +46,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
* Instantiates a new robo rally game
|
* Instantiates a new robo rally game
|
||||||
*/
|
*/
|
||||||
public RoboRallyGame(List<Player> playerList, String boardName,boolean host) {
|
public RoboRallyGame(List<Player> playerList, String boardName,boolean host) {
|
||||||
this.host=host;
|
this.host = host;
|
||||||
this.playerList = playerList;
|
this.playerList = playerList;
|
||||||
initializeGame(boardName);
|
initializeGame(boardName);
|
||||||
}
|
}
|
||||||
@ -88,6 +89,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
long cycleDelay = 600;
|
long cycleDelay = 600;
|
||||||
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the game with a debugging board
|
* Initializes the game with a debugging board
|
||||||
*/
|
*/
|
||||||
@ -114,14 +116,15 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
private void initializeGame(String boardName) {
|
private void initializeGame(String boardName) {
|
||||||
try {
|
try {
|
||||||
List<Robot> robots = new ArrayList<>();
|
List<Robot> robots = new ArrayList<>();
|
||||||
int noe = 1;
|
//TODO: Find correct robot spawn positions
|
||||||
for (Player player:playerList) {
|
int posX = 1;
|
||||||
Position spawn = new Position(noe,1);
|
for (Player player : playerList) {
|
||||||
robots.add(new Robot(player.getRobotID(),spawn));
|
Position spawn = new Position(posX,1);
|
||||||
noe++;
|
robots.add(new Robot(player.getRobotID(), spawn));
|
||||||
|
posX++;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameBoard = BoardLoaderUtil.loadBoard("boards/"+boardName, robots);
|
gameBoard = BoardLoaderUtil.loadBoard("boards/" + boardName, robots);
|
||||||
generateTileLists();
|
generateTileLists();
|
||||||
|
|
||||||
if (host) {
|
if (host) {
|
||||||
@ -130,7 +133,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
runGameLoop();
|
runTurn();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
@ -160,20 +163,6 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
|
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Does whatever the game wants to do
|
|
||||||
* @throws InterruptedException If interrupted while trying to sleep
|
|
||||||
*/
|
|
||||||
private void runGameLoop() throws InterruptedException {
|
|
||||||
TimeUnit.SECONDS.sleep(3);
|
|
||||||
runPhase(1);
|
|
||||||
runPhase(2);
|
|
||||||
runPhase(3);
|
|
||||||
runPhase(4);
|
|
||||||
runPhase(5);
|
|
||||||
respawnRobots();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs all the steps of one turn in the game
|
* Runs all the steps of one turn in the game
|
||||||
* @throws InterruptedException If interrupted while trying to sleep
|
* @throws InterruptedException If interrupted while trying to sleep
|
||||||
@ -218,7 +207,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
// Repair robots on repair tiles
|
// Repair robots on repair tiles
|
||||||
repairAllRobotsOnRepairTiles();
|
repairAllRobotsOnRepairTiles();
|
||||||
if (host) {
|
if (host) {
|
||||||
updatePlayerLockedProgrammingCards();
|
updateLockedProgrammingCardsForAllPlayers();
|
||||||
removeNonLockedProgrammingCardsFromPlayers();
|
removeNonLockedProgrammingCardsFromPlayers();
|
||||||
}
|
}
|
||||||
// TODO: If this player is in power down, ask if it shall continue
|
// TODO: If this player is in power down, ask if it shall continue
|
||||||
@ -229,33 +218,48 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
/**
|
/**
|
||||||
* Locks the players programming cards in relation to the robots damage
|
* Locks the players programming cards in relation to the robots damage
|
||||||
*/
|
*/
|
||||||
private void updatePlayerLockedProgrammingCards() {
|
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.getPlayerDeck();
|
||||||
ProgrammingCardDeck lockedPlayerDeck = player.getLockedPlayerDeck();
|
ProgrammingCardDeck lockedPlayerDeck = player.getLockedPlayerDeck();
|
||||||
int robotDamage = gameBoard.getRobotDamage(player.getRobotID());
|
int robotDamage = gameBoard.getRobotDamage(player.getRobotID());
|
||||||
|
|
||||||
|
//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.getPlayerDeck());
|
||||||
player.setLockedPlayerDeck(lockedPlayerDeck);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i <= (robotDamage-4); i++) {
|
//Goes through locked cards and moves them to the locked player deck
|
||||||
ProgrammingCard card = playerProgram.get(playerProgram.size()-i);
|
for (int i = 1; i <= (robotDamage - 4); i++) {
|
||||||
|
ProgrammingCard card = playerProgram.get(playerProgram.size() - i);
|
||||||
if (card.compareTo(playerDeck.peekTop()) == 0) {
|
moveProgrammingCardToLockedDeck(card, playerDeck, lockedPlayerDeck);
|
||||||
lockedPlayerDeck.draw(playerDeck);
|
|
||||||
} else {
|
|
||||||
playerDeck.draw(playerDeck);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
player.setPlayerDeck(playerDeck);
|
|
||||||
player.setLockedPlayerDeck(lockedPlayerDeck);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves a card from the player's deck to the player's locked deck if found
|
||||||
|
* @param card The card to move to the locked deck
|
||||||
|
* @param playerDeck The deck containing the player's cards
|
||||||
|
* @param lockedPlayerDeck The deck containing the player's locked cards
|
||||||
|
*/
|
||||||
|
private void moveProgrammingCardToLockedDeck(ProgrammingCard card, ProgrammingCardDeck playerDeck,
|
||||||
|
ProgrammingCardDeck lockedPlayerDeck) {
|
||||||
|
for (int i = 0; i < playerDeck.size(); i++) {
|
||||||
|
if (card.equals(playerDeck.peekTop())) {
|
||||||
|
//Found the card. Add to the locked deck
|
||||||
|
lockedPlayerDeck.draw(playerDeck);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
//Move the card to the bottom of the deck
|
||||||
|
playerDeck.draw(playerDeck);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves non-locked player programming cards from their hand back to the main deck
|
* Moves non-locked player programming cards from their hand back to the main deck
|
||||||
*/
|
*/
|
||||||
@ -270,7 +274,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
/**
|
/**
|
||||||
* Deals correct amount of cards to active players, based on their robots damage
|
* Deals correct amount of cards to active players, based on their robots damage
|
||||||
*/
|
*/
|
||||||
public void distributeProgrammingCardsToPlayers() {
|
private void distributeProgrammingCardsToPlayers() {
|
||||||
int robotDamage;
|
int robotDamage;
|
||||||
ProgrammingCardDeck playerDeck;
|
ProgrammingCardDeck playerDeck;
|
||||||
mainDeck.shuffle();
|
mainDeck.shuffle();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user