Skip to content

Commit

Permalink
Agreement offer popup modificiation in game scene controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bulutg committed Dec 20, 2020
1 parent 6b6eda7 commit 473550f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import javafx.fxml.FXML;
import models.Agreement;

public class AgreementOfferPopupController extends PopupController{
public class AgreementOfferPopupController extends PopupController {
private Agreement agreement;

@FXML
void closeButtonClicked(ActionEvent event) {
closeStage(event);
}

public void setAgreement(Agreement agreement){
public void setAgreement(Agreement agreement) {
this.agreement = agreement;
}
}
73 changes: 31 additions & 42 deletions src/controllers/scenecontrollers/GameSceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import controllers.modelcontrollers.GameManager;
import controllers.popupControllers.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
Expand All @@ -15,18 +14,14 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import models.Agreement;
import models.City;
import models.Game;
import models.Player;
import storage.filemanager.DataManager;
import utils.Sleeper;

import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -74,18 +69,17 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
}

//Update the game scene according to the current player
public void renderPlayer(Player player){
public void renderPlayer(Player player) {
playerName.setText(player.getName());
money.setText(player.getMoney() + "$");
cardsBar.setStyle("-fx-spacing: 10;");
cardsBar.getChildren().clear();
for(int i = 0; i < player.getCities().size(); i++){
for (int i = 0; i < player.getCities().size(); i++) {
int finalI = i;
Button button = new Button(player.getCities().get(i).getName());
if(player.getCities().get(finalI).isMortgaged()){
if (player.getCities().get(finalI).isMortgaged()) {
button.setStyle("-fx-text-fill: white; -fx-pref-height: 80; -fx-pref-width: 150 ;-fx-border-color: black; -fx-background-color: grey; -fx-border-width: 3 3 0 3");
}
else{
} else {
String color1 = player.getColor();
button.setStyle("-fx-background-color:" + color1 + ";" + "-fx-text-fill: white; -fx-pref-height: 80; -fx-pref-width: 150 ;-fx-border-color: black; -fx-border-width: 3 3 0 3");

Expand Down Expand Up @@ -127,7 +121,7 @@ public void handleCityPopup(City city) {
}

public void handleAgreementPopup() throws IOException {
if(!GameManager.getInstance().isDiceRolled()) {
if (!GameManager.getInstance().isDiceRolled()) {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../../views/popupViews/AgreementPopup.fxml"));
Parent parent = fxmlLoader.load();

Expand All @@ -136,44 +130,44 @@ public void handleAgreementPopup() throws IOException {
}
}

public void handleBuyBuildingPopup() throws IOException{
if(!GameManager.getInstance().isDiceRolled()) {
public void handleBuyBuildingPopup() throws IOException {
if (!GameManager.getInstance().isDiceRolled()) {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../../views/popupViews/BuyBuildingPopup.fxml"));
Parent parent = fxmlLoader.load();
BuyBuildingPopupController buyBuildingController = fxmlLoader.getController();
handlePopup(parent);
}
}

public void handleSellBuildingPopup() throws IOException{
if(!GameManager.getInstance().isDiceRolled()){
public void handleSellBuildingPopup() throws IOException {
if (!GameManager.getInstance().isDiceRolled()) {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../../views/popupViews/SellBuildingPopup.fxml"));
Parent parent = fxmlLoader.load();
SellBuildingPopupController sbpc = fxmlLoader.getController();
handlePopup(parent);
}
}

public void handleMortgageCityPopup() throws IOException{
if(!GameManager.getInstance().isDiceRolled()) {
public void handleMortgageCityPopup() throws IOException {
if (!GameManager.getInstance().isDiceRolled()) {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../../views/popupViews/MortgageCityPopup.fxml"));
Parent parent = fxmlLoader.load();
MortgageCityPopupController mcpc = fxmlLoader.getController();
handlePopup(parent);
}
}

public void handleRollDiceButton() throws IOException{
public void handleRollDiceButton() throws IOException {
int[] dice = GameManager.getInstance().rollDice();
if(dice == null) {
if (dice == null) {
System.out.println("Your turn is end");
return;
}
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../../views/popupViews/RollDicePopup.fxml"));
Parent parent = fxmlLoader.load();
RollDicePopupController rdpc = fxmlLoader.getController();
rdpc.setDice(dice[0],dice[1]);
rdpc.setDice(dice[0], dice[1]);

handlePopup(parent);

Expand All @@ -187,81 +181,76 @@ public void handleRollDiceButton() throws IOException{
executorService.schedule(GameManager.getInstance()::runPerformRegionAction, dice[2] * 300, TimeUnit.MILLISECONDS);

// repeat turn
if(dice[0] != dice[1]){
if (dice[0] != dice[1]) {
rollDiceButton.setVisible(false);
rollDiceLabel.setVisible(false);
}
}

public void handleEndTurnButton(){
if(GameManager.getInstance().isDiceRolled()){
public void handleEndTurnButton() {
if (GameManager.getInstance().isDiceRolled()) {
GameManager.getInstance().endTurn();
cameraScene.rotateTable();
}
else{
} else {
System.out.println("Cannot end turn without rolling a dice.");
}
// if new player bankrupted, disable roll dice
if(GameManager.getInstance().getCurrentPlayer().isBankrupted()){
if (GameManager.getInstance().getCurrentPlayer().isBankrupted()) {
// set isDiceRolled true
GameManager.getInstance().setDiceRolled(true);
}
else{
} else {
rollDiceButton.setVisible(true);
rollDiceLabel.setVisible(true);
}

}

public void handleSaveGameButton(){
public void handleSaveGameButton() {
DataManager.getInstance().saveGame("testSave");
}

public static void handleChanceRegionPopup(){
public static void handleChanceRegionPopup() {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
GameSceneController.class.getResource("../../views/popupViews/ChanceRegionPopup.fxml"));
Parent parent = fxmlLoader.load();
handlePopup(parent);
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}

public static void handleBuyCityPopup(){
public static void handleBuyCityPopup() {
try {
FXMLLoader fxmlLoader = new FXMLLoader(
GameSceneController.class.getResource("../../views/popupViews/BuyCityPopup.fxml"));
Parent parent = fxmlLoader.load();
handlePopup(parent);
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}

public static void handleAgreementOfferPopup(Agreement agreement){
public static void handleAgreementOfferPopup(Agreement agreement) {
try {
if (!GameManager.getInstance().isDiceRolled()) {
FXMLLoader fxmlLoader = new FXMLLoader(GameSceneController.class.getResource("../../views/popupViews/AgreementOfferPopup.fxml"));
Parent parent = fxmlLoader.load();
AgreementOfferPopupController agreementOfferPopupController = fxmlLoader.getController();
agreementOfferPopupController.setAgreement(agreement);
handlePopup(parent);
}
}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}

public static void handlePirateRegionPopup(){
try{
public static void handlePirateRegionPopup() {
try {
FXMLLoader fxmlLoader = new FXMLLoader(GameSceneController.class.getResource("../../views/popupViews/PirateRegionPopup.fxml"));
Parent parent = fxmlLoader.load();
handlePopup(parent);
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
Expand Down

0 comments on commit 473550f

Please sign in to comment.