Skip to content

Commit

Permalink
Bug fix, city infection, buttons, labels and game logic changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
aybarsaltinisik committed Dec 20, 2020
1 parent 4df4578 commit 6e6fdc6
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 51 deletions.
17 changes: 13 additions & 4 deletions src/controllers/modelcontrollers/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public void initGame(ArrayList<Player> players) {
game = new Game(players,regions,chanceCardNames);
}

public void initGameScene(){
infectRandomCity();
}

public ArrayList<Region> getRegions(){
return this.game.getRegions();
}
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -281,6 +286,10 @@ public void setDiceRolled(boolean bool){
diceRolled = bool;
}

public int getPlayerNumber(){
return game.getPlayerNumber();
}


// Private methods

Expand Down
64 changes: 59 additions & 5 deletions src/controllers/scenecontrollers/GameSceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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};
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> savedNames = dataManager.getSavedNames();
Expand Down
4 changes: 2 additions & 2 deletions src/models/Agreement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
19 changes: 9 additions & 10 deletions src/models/City.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/PirateRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
33 changes: 16 additions & 17 deletions src/models/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/storage/filemanager/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public ArrayList<String> getSavedNames(){
savedNames.add(content);
}
for ( int i=0; i<savedNames.size(); i++ ) {
savedNames.set(i, savedNames.get(i).substring(0, savedNames.get(i).lastIndexOf(".")));
try{
savedNames.set(i, savedNames.get(i).substring(0, savedNames.get(i).lastIndexOf(".")));
} catch (Exception e) {
e.printStackTrace();
}
}
return savedNames;
}
Expand Down
20 changes: 10 additions & 10 deletions src/views/sceneviews/GameScene.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<left>
<VBox style="-fx-spacing: 30; -fx-padding: 30">
<children>
<Button mnemonicParsing="false" onAction="#handleBuyBuildingPopup" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<Button fx:id="buyBuildingButton" mnemonicParsing="false" onAction="#handleBuyBuildingPopup" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<graphic>
<ImageView fitHeight="70.0" fitWidth="70.0" pickOnBounds="true" preserveRatio="true">
<image>
Expand All @@ -56,15 +56,15 @@
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Label text="Buy Building" textFill="white">
<Label fx:id="buyBuildingLabel" text="Buy Building" textFill="white">
<font>
<Font size="18.0" />
</font>
<VBox.margin>
<Insets />
</VBox.margin>
</Label>
<Button mnemonicParsing="false" onAction="#handleSellBuildingPopup" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<Button fx:id="sellBuildingButton" mnemonicParsing="false" onAction="#handleSellBuildingPopup" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<graphic>
<ImageView fitHeight="70.0" fitWidth="70.0" pickOnBounds="true" preserveRatio="true">
<image>
Expand All @@ -79,12 +79,12 @@
<Insets top="25.0" />
</VBox.margin>
</Button>
<Label text="Sell Building" textFill="white">
<Label fx:id="sellBuildingLabel" text="Sell Building" textFill="white">
<font>
<Font size="18.0" />
</font>
</Label>
<Button mnemonicParsing="false" onAction="#handleMortgageCityPopup" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<Button fx:id="mortgageButton" mnemonicParsing="false" onAction="#handleMortgageCityPopup" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<graphic>
<ImageView fitHeight="70.0" fitWidth="70.0" pickOnBounds="true" preserveRatio="true">
<image>
Expand All @@ -99,12 +99,12 @@
<Insets top="25.0" />
</VBox.margin>
</Button>
<Label text="Mortgage" textFill="white">
<Label fx:id="mortgageLabel" text="Mortgage" textFill="white">
<font>
<Font size="18.0" />
</font>
</Label>
<Button mnemonicParsing="false" onAction="#handleAgreementPopup" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<Button fx:id="agreementButton" mnemonicParsing="false" onAction="#handleAgreementPopup" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<graphic>
<ImageView fitHeight="70.0" fitWidth="70.0" pickOnBounds="true" preserveRatio="true">
<image>
Expand All @@ -119,7 +119,7 @@
<Insets top="25.0" />
</VBox.margin>
</Button>
<Label text="Agreement" textFill="white">
<Label fx:id="agreementLabel" text="Agreement" textFill="white">
<font>
<Font size="18.0" />
</font>
Expand Down Expand Up @@ -167,7 +167,7 @@
<Font size="18.0" />
</font>
</Label>
<Button mnemonicParsing="false" onAction="#handleEndTurnButton" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<Button fx:id="endTurnButton" mnemonicParsing="false" onAction="#handleEndTurnButton" prefHeight="70.0" prefWidth="70.0" style="-fx-background-color: transparent;">
<graphic>
<ImageView fitHeight="70.0" fitWidth="70.0" pickOnBounds="true" preserveRatio="true">
<image>
Expand All @@ -182,7 +182,7 @@
<Insets top="25.0" />
</VBox.margin>
</Button>
<Label text="End Turn" textFill="white">
<Label fx:id="endTurnLabel" text="End Turn" textFill="white">
<font>
<Font size="18.0" />
</font>
Expand Down

0 comments on commit 6e6fdc6

Please sign in to comment.