diff --git a/src/controllers/modelcontrollers/GameManager.java b/src/controllers/modelcontrollers/GameManager.java index d3e598e..ce5cff2 100644 --- a/src/controllers/modelcontrollers/GameManager.java +++ b/src/controllers/modelcontrollers/GameManager.java @@ -24,7 +24,6 @@ public class GameManager { private static int NUMBER_OF_REGIONS = 40; private boolean diceRolled = false; private Card currentChanceCard = null; - private City currentInfectedCity = null; public static GameManager getInstance(){ @@ -52,15 +51,11 @@ public ArrayList getRegions(){ // infects a random city in a game public void infectRandomCity() { - if(currentInfectedCity != null){ - currentInfectedCity.infect(false); - } int random = (int) (this.game.getRegionNumber() * Math.random()); while( !(this.game.getRegion(random) instanceof City) ){ random = (int) (this.game.getRegionNumber() * Math.random()); } ((City) this.game.getRegion(random)).infect(true); - currentInfectedCity = ((City) this.game.getRegion(random)); } // moves current player count number of steps @@ -180,6 +175,9 @@ private boolean performRegionAction(){ if(((City) currentRegion).isInfected()){ currentPlayer.infect(true); } + else if(currentPlayer.isInfected()) { + ((City) currentRegion).infect(true); + } performed = checkAgreements(); if(!performed){ GameSceneController.handleBuyCityPopup(); @@ -236,10 +234,8 @@ public void endTurn(){ this.offerAgreement(); this.game.checkVirus(); - if(tourCounter == 0) { - // TODO remove infected cities infection - infectRandomCity(); - } + infectRandomCity(); + turnCounter++; turnCounter = turnCounter % this.game.getPlayerNumber(); if(turnCounter == 0) { @@ -275,8 +271,17 @@ public int getTour(){ return tourCounter; } + public int getTurn(){ + return turnCounter; + } + public Game getGame() { return this.game; } + public void setDiceRolled(boolean bool){ + diceRolled = bool; + } + + // Private methods private boolean checkPandemic(){ diff --git a/src/controllers/scenecontrollers/GameSceneController.java b/src/controllers/scenecontrollers/GameSceneController.java index 22b1450..3ee2f09 100644 --- a/src/controllers/scenecontrollers/GameSceneController.java +++ b/src/controllers/scenecontrollers/GameSceneController.java @@ -182,11 +182,15 @@ public void handleRollDiceButton() throws IOException{ } //GameManager.getInstance().getCurrentPlayer().quarantine(true); // DEBUG GameManager.getInstance().moveForward(dice[2]); -// GameManager.getInstance().moveForward(1); // DEBUG + //GameManager.getInstance().moveForward(14); // DEBUG ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.schedule(GameManager.getInstance()::runPerformRegionAction, dice[2] * 300, TimeUnit.MILLISECONDS); - rollDiceButton.setVisible(false); - rollDiceLabel.setVisible(false); + + // repeat turn + if(dice[0] != dice[1]){ + rollDiceButton.setVisible(false); + rollDiceLabel.setVisible(false); + } } public void handleEndTurnButton(){ @@ -197,8 +201,16 @@ public void handleEndTurnButton(){ else{ System.out.println("Cannot end turn without rolling a dice."); } - rollDiceButton.setVisible(true); - rollDiceLabel.setVisible(true); + // if new player bankrupted, disable roll dice + if(GameManager.getInstance().getCurrentPlayer().isBankrupted()){ + // set isDiceRolled true + GameManager.getInstance().setDiceRolled(true); + } + else{ + rollDiceButton.setVisible(true); + rollDiceLabel.setVisible(true); + } + } public void handleSaveGameButton(){ diff --git a/src/models/City.java b/src/models/City.java index b10f48c..28fe81f 100644 --- a/src/models/City.java +++ b/src/models/City.java @@ -11,6 +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; public City(double price, double[] rents, String name, int id) { super(id); @@ -51,10 +53,27 @@ public boolean removeBuilding(int count) { } public void infect(boolean bool) { + if(bool){ + if(!isInfected){ + infectTurnCounter = 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; + } + return false; + } + public boolean isInfected() { return isInfected; } diff --git a/src/models/Game.java b/src/models/Game.java index 9cf81a9..151d614 100644 --- a/src/models/Game.java +++ b/src/models/Game.java @@ -108,6 +108,11 @@ public void checkVirus() { player.checkInfection(); } } + for( Region region : regions){ + if(region instanceof City){ + ((City) region).checkInfection(); + } + } } public ArrayList getAgreements(){ diff --git a/src/models/Player.java b/src/models/Player.java index ac0c853..04c1fc4 100644 --- a/src/models/Player.java +++ b/src/models/Player.java @@ -15,8 +15,9 @@ public class Player extends Observable implements Serializable { private boolean isBankrupted; private int location; private boolean isInfected; - private int quarantineTourCounter = -1; - private int infectTourCounter = -1; + private int quarantineTourCounter = 99999; + private int infectTourCounter = 99999; + private final int MAX = 99999; public Player(String name, String color, String pawn, int id) { @@ -46,7 +47,7 @@ public void quarantine(boolean bool) } } else{ - quarantineTourCounter = -1; + quarantineTourCounter = MAX; } isInQuarantine = bool; this.notifyGameLogObserver("quarantine", bool ? 1 : 0); @@ -54,33 +55,13 @@ public void quarantine(boolean bool) public boolean checkQuarantine(){ if(GameManager.getInstance().getTour() - quarantineTourCounter >= 2){ - isInQuarantine = false; - quarantineTourCounter = -1; + quarantine(false); + quarantineTourCounter = MAX; return true; } return false; } - public void addMoney(double money) - { - this.money = this.money + money; - if(isBankrupted && money > 0){ - isBankrupted = false; - } - this.notifyAllObservers(); - this.notifyGameLogObserver("money", money); - } - - public void removeMoney(double money) - { - this.money = this.money - money; - if(this.money < 0){ - isBankrupted = true; - } - this.notifyAllObservers(); - this.notifyGameLogObserver("money", -money); - } - public void infect(boolean bool) { if(bool){ @@ -89,7 +70,7 @@ public void infect(boolean bool) } } else{ - infectTourCounter = -1; + infectTourCounter = MAX; } isInfected = bool; this.notifyAllObservers(); @@ -97,14 +78,34 @@ public void infect(boolean bool) } public boolean checkInfection(){ - if(GameManager.getInstance().getTour() - infectTourCounter >= 3){ - isInfected = false; - infectTourCounter = -1; + if(GameManager.getInstance().getTour() - infectTourCounter >= 2){ + infect(false); + infectTourCounter = MAX; return true; } return false; } + public void addMoney(double money) + { + this.money = this.money + money; + if(isBankrupted && money > 0){ + isBankrupted = false; + } + this.notifyAllObservers(); + this.notifyGameLogObserver("money", money); + } + + public void removeMoney(double money) + { + this.money = this.money - money; + if(this.money < 0){ + isBankrupted = true; + } + this.notifyAllObservers(); + this.notifyGameLogObserver("money", -money); + } + public boolean removeCity(City city){ if (cities.remove(city)){ this.notifyAllObservers();