diff --git a/src/controllers/modelcontrollers/GameManager.java b/src/controllers/modelcontrollers/GameManager.java index 3b9df94..32a6db5 100644 --- a/src/controllers/modelcontrollers/GameManager.java +++ b/src/controllers/modelcontrollers/GameManager.java @@ -60,6 +60,7 @@ public void infectRandomCity() { random = (int) (this.game.getRegionNumber() * Math.random()); } ((City) this.game.getRegion(random)).infect(true); + this.game.infectPlayersAt(this.game.getRegion(random).getId()); } // moves current player count number of steps diff --git a/src/controllers/popupControllers/AgreementPopupController.java b/src/controllers/popupControllers/AgreementPopupController.java index bf1153a..a933964 100644 --- a/src/controllers/popupControllers/AgreementPopupController.java +++ b/src/controllers/popupControllers/AgreementPopupController.java @@ -211,8 +211,8 @@ void submitButtonClicked(ActionEvent event) { String offerType = chooseOppositeOfferBox.getSelectionModel().getSelectedItem(); String agreementName = agreementNameField.getText(); - Offer offer = getOffer(offerType, city1, moneyField1, percentageField1); - Offer oppositeOffer = getOffer(oppositeOfferType, city2, moneyField2, percentageField2); + Offer offer = getOffer(offerType, city1, moneyField1, percentageField1, currentPlayer); + Offer oppositeOffer = getOffer(oppositeOfferType, city2, moneyField2, percentageField2, player2); // create agreement GameManager.getInstance().newAgreement(offer, oppositeOffer, currentPlayer, player2, agreementName); @@ -220,10 +220,10 @@ void submitButtonClicked(ActionEvent event) { closeStage(event); } - private Offer getOffer(String oppositeOfferType, City city, TextField moneyField, TextField percentageField) { + private Offer getOffer(String oppositeOfferType, City city, TextField moneyField, TextField percentageField, Player giver) { Offer offer = switch (oppositeOfferType) { case "Sell Region" -> new SellRegion(city); - case "Give Money" -> new GiveMoney(Integer.parseInt(moneyField.getText())); + case "Give Money" -> new GiveMoney(Integer.parseInt(moneyField.getText()),giver); case "Pay Rent or Not" -> new PayRentOrNot(city); case "Take Percentage" -> new TakePercentage(city, Integer.parseInt(percentageField.getText())); default -> throw new IllegalStateException("Unexpected value: " + oppositeOfferType); diff --git a/src/controllers/scenecontrollers/GameSceneController.java b/src/controllers/scenecontrollers/GameSceneController.java index 5764c96..8f0001c 100644 --- a/src/controllers/scenecontrollers/GameSceneController.java +++ b/src/controllers/scenecontrollers/GameSceneController.java @@ -14,8 +14,6 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -import javafx.scene.text.Font; -import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Modality; import javafx.stage.Stage; @@ -262,9 +260,7 @@ public void handleEndTurnButton() { public void handleSaveGameButton() { DataManager.saveGame("SaveGame1"); - Text text = new Text("Game saved as SaveGame1!"); - text.setFont(Font.font("Arial", FontWeight.BOLD, 20)); - gameLog.getChildren().add(text); + } public static void handleChanceRegionPopup() { diff --git a/src/models/Game.java b/src/models/Game.java index b2eadef..4bbbe11 100644 --- a/src/models/Game.java +++ b/src/models/Game.java @@ -132,4 +132,12 @@ public Agreement offerAgreement(){ return null; } + public void infectPlayersAt(int location){ + for(Player player: players){ + if(player.getLocation() == location){ + player.infect(true); + } + } + } + } diff --git a/src/models/GiveMoney.java b/src/models/GiveMoney.java index fde6648..b29bda7 100644 --- a/src/models/GiveMoney.java +++ b/src/models/GiveMoney.java @@ -2,17 +2,28 @@ public class GiveMoney extends OneTimeOffer { private double money; + private Player giver; - public GiveMoney(double money){ + public GiveMoney(double money, Player giver){ + this.giver = giver; this.money = money; } @Override public void performOffer(Player firstPlayer, Player secondPlayer) { - //first player gives specified amount of money to second player - firstPlayer.removeMoney(money); - //second player takes specified amount of money from the first player - secondPlayer.addMoney(money); + if(giver.getId() == firstPlayer.getId()){ + //first player gives specified amount of money to second player + firstPlayer.removeMoney(money); + //second player takes specified amount of money from the first player + secondPlayer.addMoney(money); + } + else{ + //secondPlayer gives specified amount of money to second player + secondPlayer.removeMoney(money); + //firstPlayer takes specified amount of money from the first player + firstPlayer.addMoney(money); + } + } @Override diff --git a/src/models/PirateRegion.java b/src/models/PirateRegion.java index 9952c73..002ff9b 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 = 2000; + private final int PIRATE_FEE = 5000; public PirateRegion(int id){ super(id); } public void performRegionAction() { diff --git a/src/models/Player.java b/src/models/Player.java index a49ecc2..aae5ee3 100644 --- a/src/models/Player.java +++ b/src/models/Player.java @@ -17,7 +17,7 @@ public class Player extends Observable implements Serializable { private boolean isInfected; private int quarantineTourCounter; private int infectTourCounter; - private final int INFECTION_TIME = 2; + private final int INFECTION_TIME = 1; private final int QUARANTINE_TIME = 2; public Player(String name, String color, String pawn, int id) diff --git a/src/models/SellRegion.java b/src/models/SellRegion.java index dcde0ca..2e0abdd 100644 --- a/src/models/SellRegion.java +++ b/src/models/SellRegion.java @@ -11,14 +11,25 @@ public SellRegion(City city){ @Override public void performOffer(Player firstPlayer, Player secondPlayer) { - // remove city from second player (if possible) - if(secondPlayer.removeCity(city)){ - // add city to first player (if possible) - firstPlayer.addCity(city); - city.setOwner(firstPlayer); - return; + if(city.getOwner().getId() == firstPlayer.getId()){ + // remove city from second player (if possible) + if(firstPlayer.removeCity(city)){ + // add city to first player (if possible) + secondPlayer.addCity(city); + city.setOwner(secondPlayer); + return; + } + System.out.println("First player does not own city: " + city.getName()); + }else{ + // remove city from second player (if possible) + if(secondPlayer.removeCity(city)){ + // add city to first player (if possible) + firstPlayer.addCity(city); + city.setOwner(firstPlayer); + return; + } + System.out.println("Second player does not own city: " + city.getName()); } - System.out.println("Second player does not own city: " + city.getName()); } @Override diff --git a/src/views/popupViews/AgreementPopup.fxml b/src/views/popupViews/AgreementPopup.fxml index 7d4f594..afe6237 100644 --- a/src/views/popupViews/AgreementPopup.fxml +++ b/src/views/popupViews/AgreementPopup.fxml @@ -31,7 +31,7 @@ - +