Added stuff to randomEvents logic

This commit is contained in:
2019-04-10 23:16:20 -06:00
parent a2e3879cae
commit ea5faaca36
4 changed files with 341 additions and 1484 deletions

1740
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,8 +8,7 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import logic.Player; import logic.Player;
import logic.RandomEventLogic;
import java.util.Random;
/** /**
* 2019-03-19 * 2019-03-19
@@ -132,33 +131,20 @@ public class RandomEventGUI extends Player {
* 2: Paying Liu Yuen * 2: Paying Liu Yuen
* 3: Repairing the Ship * 3: Repairing the Ship
*/ */
Random rand = new Random(); RandomEventLogic randomEventLogic = new RandomEventLogic(getPlayer());
int randGenNum = rand.nextInt(3) + 1; int[] randEvent = randomEventLogic.randEvent();
while(true){ eventNumber = randEvent[0];
//Buy Guns itemPrice = randEvent[1];
if (randGenNum == 1) {
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10); if(eventNumber == 1){
sellingItemLabel.setText("A vender is selling a gun for $" + itemPrice + " for a gun?"); sellingItemLabel.setText("A vender is selling a gun for $" + itemPrice + " for a gun?");
break; }
} if(eventNumber == 2){
//Liu Yuen sellingItemLabel.setText("Liu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
if (randGenNum == 2) { }
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10); if(eventNumber == 3){
sellingItemLabel.setText("Liu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess"); sellingItemLabel.setText("Mc Henry from the Hong Kong shipyard has arrived,\n would be willing to repair your ship for $" + itemPrice);
setAttackingShips(true);
break;
}
//Ship Repair
if (randGenNum == 3 && getHP() < 100) {
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
sellingItemLabel.setText("Mc Henry from the Hong Kong shipyard has arrived,\n would be willing to repair your ship for $" + itemPrice);
break;
}
else {
randGenNum = 2;
}
} }
eventNumber = randGenNum;
if((eventNumber == 1 && getCargoSpace() < 10)){ if((eventNumber == 1 && getCargoSpace() < 10)){
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer()); TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
@@ -229,4 +215,6 @@ public class RandomEventGUI extends Player {
stage.setScene(root); stage.setScene(root);
return stage; return stage;
} }
} }

View File

@@ -1,4 +1,45 @@
package logic; package logic;
import java.util.Random;
public class RandomEventLogic extends Player{ public class RandomEventLogic extends Player{
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
*
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public RandomEventLogic(Player player) {
Player playerDummy = new Player(player);
setPlayer(playerDummy);
}
public int[] randEvent() {
Random rand = new Random();
int itemPrice;
int randGenNum = rand.nextInt(3) + 1;
while(true){
//Buy Guns
if (randGenNum == 1) {
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
break;
}
//Liu Yuen
if (randGenNum == 2) {
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
setAttackingShips(true);
break;
}
//Ship Repair
if (randGenNum == 3 && getHP() < 100) {
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
break;
}
else {
randGenNum = 2;
}
}
return new int[]{randGenNum,itemPrice};
}
} }

Binary file not shown.