diff --git a/src/controllers/modelcontrollers/GameManager.java b/src/controllers/modelcontrollers/GameManager.java index ce5cff2..397f65c 100644 --- a/src/controllers/modelcontrollers/GameManager.java +++ b/src/controllers/modelcontrollers/GameManager.java @@ -45,6 +45,10 @@ public void initGame(ArrayList players) { game = new Game(players,regions,chanceCardNames); } + public void initGameScene(){ + infectRandomCity(); + } + public ArrayList getRegions(){ return this.game.getRegions(); } @@ -230,16 +234,17 @@ public void endTurn(){ diceRolled = false; this.game.nextPlayer(); - // check update functions + // check for each turn this.offerAgreement(); - this.game.checkVirus(); - - infectRandomCity(); turnCounter++; turnCounter = turnCounter % this.game.getPlayerNumber(); + if(turnCounter == 0) { + // check for each tour tourCounter++; + this.game.checkVirus(); + infectRandomCity(); } } @@ -281,6 +286,10 @@ public void setDiceRolled(boolean bool){ diceRolled = bool; } + public int getPlayerNumber(){ + return game.getPlayerNumber(); + } + // Private methods diff --git a/src/controllers/scenecontrollers/GameSceneController.java b/src/controllers/scenecontrollers/GameSceneController.java index 615d02c..de3cc91 100644 --- a/src/controllers/scenecontrollers/GameSceneController.java +++ b/src/controllers/scenecontrollers/GameSceneController.java @@ -42,11 +42,32 @@ public class GameSceneController implements Initializable { @FXML private Text playerName; @FXML - private Button rollDiceButton; - @FXML private VBox gameLog; @FXML + private Button rollDiceButton; + @FXML private Label rollDiceLabel; + @FXML + private Button endTurnButton; + @FXML + private Label endTurnLabel; + @FXML + private Button agreementButton; + @FXML + private Label agreementLabel; + @FXML + private Button mortgageButton; + @FXML + private Label mortgageLabel; + @FXML + private Button buyBuildingButton; + @FXML + private Label buyBuildingLabel; + @FXML + private Button sellBuildingButton; + @FXML + private Label sellBuildingLabel; + @Override @@ -55,6 +76,19 @@ public void initialize(URL url, ResourceBundle resourceBundle) { stackPane.getChildren().add(cameraScene); cameraScene.toBack(); GameManager.getInstance().setPlayerObservers(this, gameLog); + GameManager.getInstance().initGameScene(); + rollDiceButton.setVisible(true); + rollDiceLabel.setVisible(true); + sellBuildingButton.setVisible(true); + sellBuildingLabel.setVisible(true); + buyBuildingButton.setVisible(true); + buyBuildingLabel.setVisible(true); + mortgageButton.setVisible(true); + mortgageLabel.setVisible(true); + agreementButton.setVisible(true); + agreementLabel.setVisible(true); + endTurnButton.setVisible(false); + endTurnLabel.setVisible(false); //test purpose //double[] rents = {1,2,3,4,5,6}; @@ -180,10 +214,20 @@ public void handleRollDiceButton() throws IOException { ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.schedule(GameManager.getInstance()::runPerformRegionAction, dice[2] * 300, TimeUnit.MILLISECONDS); - // repeat turn + // turn is end if (dice[0] != dice[1]) { rollDiceButton.setVisible(false); rollDiceLabel.setVisible(false); + sellBuildingButton.setVisible(false); + sellBuildingLabel.setVisible(false); + buyBuildingButton.setVisible(false); + buyBuildingLabel.setVisible(false); + mortgageButton.setVisible(false); + mortgageLabel.setVisible(false); + agreementButton.setVisible(false); + agreementLabel.setVisible(false); + endTurnButton.setVisible(true); + endTurnLabel.setVisible(true); } } @@ -202,11 +246,21 @@ public void handleEndTurnButton() { rollDiceButton.setVisible(true); rollDiceLabel.setVisible(true); } - + sellBuildingButton.setVisible(true); + sellBuildingLabel.setVisible(true); + buyBuildingButton.setVisible(true); + buyBuildingLabel.setVisible(true); + mortgageButton.setVisible(true); + mortgageLabel.setVisible(true); + agreementButton.setVisible(true); + agreementLabel.setVisible(true); + endTurnButton.setVisible(false); + endTurnLabel.setVisible(false); } public void handleSaveGameButton() { - DataManager.getInstance().saveGame("testSave"); + DataManager.getInstance().saveGame("SaveGame1"); + } public static void handleChanceRegionPopup() { diff --git a/src/controllers/scenecontrollers/LoadGameSceneController.java b/src/controllers/scenecontrollers/LoadGameSceneController.java index b3bce61..515fcf3 100644 --- a/src/controllers/scenecontrollers/LoadGameSceneController.java +++ b/src/controllers/scenecontrollers/LoadGameSceneController.java @@ -32,7 +32,6 @@ public void getSavedGames() { buttonBox.setPrefWidth(500); buttonBox.setPrefHeight(700); buttonBox.setAlignment(Pos.TOP_CENTER); - buttonBox.setStyle("-fx-padding: 50 50 50 220;"); buttonBox.setSpacing(15.0); DataManager dataManager = DataManager.getInstance(); List savedNames = dataManager.getSavedNames(); diff --git a/src/models/Agreement.java b/src/models/Agreement.java index 4b8cbc9..4693712 100644 --- a/src/models/Agreement.java +++ b/src/models/Agreement.java @@ -42,7 +42,7 @@ private void performOneTimeOffer(){ // check offers if they are continuous public boolean performOffers(City city, Player player){ if(isAccepted){ - // if firstOffer instanceof ContiuousOffer + // if firstOffer instanceof ContinuousOffer if(firstOffer != null){ if(city.getId() == ((ContiuousOffer) firstOffer).getCity().getId()){ if(firstOffer instanceof TakePercentage) { @@ -61,7 +61,7 @@ public boolean performOffers(City city, Player player){ firstOffer.performOffer(firstPlayer, secondPlayer); } } - // if secondOffer instanceof ContiuousOffer + // if secondOffer instanceof ContinuousOffer if(secondOffer != null){ if(city.getId() == ((ContiuousOffer) secondOffer).getCity().getId()){ if(secondOffer instanceof TakePercentage) { diff --git a/src/models/City.java b/src/models/City.java index 28fe81f..da31f5a 100644 --- a/src/models/City.java +++ b/src/models/City.java @@ -11,8 +11,8 @@ public class City extends Region { private String name; private final double MORGAGE_PENALTY = 0.55; private final double MORGAGE_RATE = 0.5; - private int infectTurnCounter = 99999; - private final int MAX = 99999; + private int infectTourCounter; + private final int INFECTION_TIME = 2; public City(double price, double[] rents, String name, int id) { super(id); @@ -55,21 +55,20 @@ public boolean removeBuilding(int count) { public void infect(boolean bool) { if(bool){ if(!isInfected){ - infectTurnCounter = GameManager.getInstance().getTour(); + infectTourCounter = GameManager.getInstance().getTour(); } } - else{ - infectTurnCounter = MAX; - } isInfected = bool; this.notifyAllObservers(); } public boolean checkInfection(){ - if(Math.abs(GameManager.getInstance().getTurn() - infectTurnCounter) >= 1){ - infect(false); - infectTurnCounter = MAX; - return true; + if(isInfected){ + int tourToDisinfect = infectTourCounter + INFECTION_TIME; + if( tourToDisinfect == GameManager.getInstance().getTour()){ + infect(false); + return true; + } } return false; } diff --git a/src/models/PirateRegion.java b/src/models/PirateRegion.java index 002ff9b..9952c73 100644 --- a/src/models/PirateRegion.java +++ b/src/models/PirateRegion.java @@ -3,7 +3,7 @@ import controllers.modelcontrollers.GameManager; public class PirateRegion extends Region { - private final int PIRATE_FEE = 5000; + private final int PIRATE_FEE = 2000; public PirateRegion(int id){ super(id); } public void performRegionAction() { diff --git a/src/models/Player.java b/src/models/Player.java index 04c1fc4..a49ecc2 100644 --- a/src/models/Player.java +++ b/src/models/Player.java @@ -15,9 +15,10 @@ public class Player extends Observable implements Serializable { private boolean isBankrupted; private int location; private boolean isInfected; - private int quarantineTourCounter = 99999; - private int infectTourCounter = 99999; - private final int MAX = 99999; + private int quarantineTourCounter; + private int infectTourCounter; + private final int INFECTION_TIME = 2; + private final int QUARANTINE_TIME = 2; public Player(String name, String color, String pawn, int id) { @@ -46,18 +47,17 @@ public void quarantine(boolean bool) quarantineTourCounter = GameManager.getInstance().getTour(); } } - else{ - quarantineTourCounter = MAX; - } isInQuarantine = bool; this.notifyGameLogObserver("quarantine", bool ? 1 : 0); } public boolean checkQuarantine(){ - if(GameManager.getInstance().getTour() - quarantineTourCounter >= 2){ - quarantine(false); - quarantineTourCounter = MAX; - return true; + if(isInQuarantine) { + int tourToLeaveQuarantine = quarantineTourCounter + QUARANTINE_TIME; + if (tourToLeaveQuarantine == GameManager.getInstance().getTour()) { + quarantine(false); + return true; + } } return false; } @@ -69,19 +69,18 @@ public void infect(boolean bool) infectTourCounter = GameManager.getInstance().getTour(); } } - else{ - infectTourCounter = MAX; - } isInfected = bool; this.notifyAllObservers(); this.notifyGameLogObserver("infect", bool ? 1 : 0); } public boolean checkInfection(){ - if(GameManager.getInstance().getTour() - infectTourCounter >= 2){ - infect(false); - infectTourCounter = MAX; - return true; + if(isInfected){ + int tourToDisinfect = infectTourCounter + INFECTION_TIME; + if(tourToDisinfect == GameManager.getInstance().getTour()){ + infect(false); + return true; + } } return false; } diff --git a/src/storage/filemanager/DataManager.java b/src/storage/filemanager/DataManager.java index fd2470d..1683797 100644 --- a/src/storage/filemanager/DataManager.java +++ b/src/storage/filemanager/DataManager.java @@ -70,7 +70,11 @@ public ArrayList getSavedNames(){ savedNames.add(content); } for ( int i=0; i - -