Skip to content

Commit

Permalink
Simple bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
aybarsaltinisik committed Dec 23, 2020
1 parent 90d32f8 commit 2efde29
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ void submitButtonClicked(ActionEvent event) {
closeStage(event);
}

private Offer getOffer(String oppositeOfferType, City city, TextField moneyField, TextField percentageField, Player giver) {
private Offer getOffer(String oppositeOfferType, City city, TextField moneyField, TextField percentageField, Player owner) {
Offer offer = switch (oppositeOfferType) {
case "Sell Region" -> new SellRegion(city);
case "Give Money" -> new GiveMoney(Integer.parseInt(moneyField.getText()),giver);
case "Sell Region" -> new SellRegion(city, owner);
case "Give Money" -> new GiveMoney(Integer.parseInt(moneyField.getText()), owner);
case "Pay Rent or Not" -> new PayRentOrNot(city);
case "Take Percentage" -> new TakePercentage(city, Integer.parseInt(percentageField.getText()));
case "Take Percentage" -> new TakePercentage(city, Integer.parseInt(percentageField.getText()), owner);
default -> throw new IllegalStateException("Unexpected value: " + oppositeOfferType);
};
return offer;
Expand Down
6 changes: 4 additions & 2 deletions src/models/SellRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
public class SellRegion extends OneTimeOffer {
// properties
private City city;
private Player owner;

// constructor
public SellRegion(City city){
public SellRegion(City city, Player owner){
this.city = city;
this.owner = owner;
}

@Override
public void performOffer(Player firstPlayer, Player secondPlayer) {
if(city.getOwner().getId() == firstPlayer.getId()){
if(owner.getId() == firstPlayer.getId()){
// remove city from second player (if possible)
if(firstPlayer.removeCity(city)){
// add city to first player (if possible)
Expand Down
14 changes: 11 additions & 3 deletions src/models/TakePercentage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ public class TakePercentage extends ContiuousOffer {
// properties
private City city;
private int percentage;
private Player owner;

// constructor
public TakePercentage(City city, int percentage){
public TakePercentage(City city, int percentage, Player owner){
this.city = city;
this.percentage = percentage;
this.owner = owner;
}

@Override
public void performOffer(Player firstPlayer, Player secondPlayer) {
// get percentage of rent from secondPlayers city
double rate = ((double)percentage)/100;
firstPlayer.addMoney(city.getRent() * rate);
secondPlayer.addMoney(city.getRent() * (1 - rate));
if(owner.getId() == firstPlayer.getId()){
secondPlayer.addMoney(city.getRent() * rate);
firstPlayer.addMoney(city.getRent() * (1 - rate));
}
else {
firstPlayer.addMoney(city.getRent() * rate);
secondPlayer.addMoney(city.getRent() * (1 - rate));
}
}

@Override
Expand Down

0 comments on commit 2efde29

Please sign in to comment.