Skip to content

Commit

Permalink
Simple Bugfixes in several cases. No additional feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
aybarsaltinisik committed Dec 22, 2020
1 parent e7acf47 commit 90d32f8
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/controllers/modelcontrollers/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,19 @@ 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);

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);
Expand Down
6 changes: 1 addition & 5 deletions src/controllers/scenecontrollers/GameSceneController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions src/models/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

}
21 changes: 16 additions & 5 deletions src/models/GiveMoney.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 = 2000;
private final int PIRATE_FEE = 5000;

public PirateRegion(int id){ super(id); }
public void performRegionAction() {
Expand Down
2 changes: 1 addition & 1 deletion src/models/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 18 additions & 7 deletions src/models/SellRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/views/popupViews/AgreementPopup.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ComboBox>
<VBox fx:id="chooseOfferVBox" prefHeight="200.0" prefWidth="100.0">
<children>
<ComboBox fx:id="chooseOfferBox" prefWidth="300.0" promptText="Choose Your Offer">
<ComboBox fx:id="chooseOfferBox" prefWidth="300.0" promptText="Choose Opposite Offer">
<VBox.margin>
<Insets />
</VBox.margin>
Expand Down

0 comments on commit 90d32f8

Please sign in to comment.