Compare commits
108 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c0914d8e5e | |||
| 11b16b4e40 | |||
| 076ba12ef1 | |||
| 59de84a47d | |||
| e1671d8d21 | |||
| e6a67ce1e4 | |||
|
|
1ac82edf1e | ||
|
|
1df0cbec36 | ||
|
|
0af20d9f67 | ||
|
|
5b8682a900 | ||
| a58d0fa184 | |||
|
|
4d09891665 | ||
| 91bb72351e | |||
|
|
ba16ea1809 | ||
|
|
9b9af573a8 | ||
|
|
c6df980f8e | ||
|
|
666e409e74 | ||
|
|
89f9e47921 | ||
| 414a9634b5 | |||
| f4fbc474e7 | |||
|
|
4c8b99d4bb | ||
|
|
ffb77b14a0 | ||
|
|
0c5317cf6f | ||
|
|
461171ff46 | ||
|
|
13f30b681a | ||
|
|
1d5e5aa706 | ||
|
|
01ee9b2600 | ||
| 3aa6ad619d | |||
| 0b8b8ed50c | |||
|
|
df372522e4 | ||
|
|
4fd40af606 | ||
|
|
664d194d7b | ||
|
|
2198fffbd5 | ||
| d395d91730 | |||
| 31e93f6997 | |||
| 0f2e8848ad | |||
| c3f7cc16d2 | |||
| 9a15f6bc63 | |||
|
|
680225550f | ||
|
|
6778aa5737 | ||
|
|
46624389f5 | ||
| a0e0ab517d | |||
|
|
5e33374e3c | ||
| 325c4127dd | |||
|
|
fde76a5bfb | ||
|
|
888d8a1c92 | ||
|
|
42c4534f52 | ||
|
|
a07d633ff9 | ||
|
|
b4e0e18d20 | ||
|
|
d558e7cf0c | ||
|
|
36aa789590 | ||
|
|
e5807a46af | ||
|
|
5f6abbc817 | ||
| b376ad5284 | |||
| b945cafe98 | |||
| 75673d40e1 | |||
|
|
9feac6e90e | ||
|
|
1bb00d0d01 | ||
|
|
80102eabee | ||
|
|
f5845cb8df | ||
|
|
5a7d1e7c34 | ||
|
|
370b3ee041 | ||
|
|
7314bc174f | ||
|
|
5c78f561d8 | ||
|
|
271a37877b | ||
|
|
89188152e6 | ||
| 6b9e3dcc06 | |||
| 14e5eb2d30 | |||
| bf2d1c3fb0 | |||
|
|
b62274cda3 | ||
|
|
72708e53f2 | ||
|
|
540605f0f1 | ||
|
|
f6fa9dc646 | ||
| 93f16751f1 | |||
| 507fe4debd | |||
| 2d1864bb87 | |||
|
|
de3c686db7 | ||
|
|
2abef09de8 | ||
|
|
b1421e19d4 | ||
|
|
55e1ae2d5f | ||
|
|
697c221323 | ||
|
|
4aaff2809a | ||
|
|
581bee7bfe | ||
|
|
1295d625fb | ||
|
|
52ec4c2422 | ||
|
|
27ac100618 | ||
|
|
94762234af | ||
|
|
207d258e05 | ||
|
|
f236650611 | ||
|
|
757d258e3d | ||
|
|
e7a0ddf085 | ||
|
|
70b698c22e | ||
|
|
4cc9ac5d26 | ||
|
|
c66e3d5d70 | ||
|
|
40ba6b0c9b | ||
|
|
2ae60073c0 | ||
|
|
c4c4a41776 | ||
|
|
6b379bae3a | ||
|
|
67ddc34c65 | ||
|
|
b6b5c14c56 | ||
|
|
d1c3fe0f7e | ||
|
|
fcb0b50468 | ||
|
|
237ce1da27 | ||
|
|
3b068d869b | ||
|
|
70d9a36af5 | ||
|
|
8d35d073e4 | ||
|
|
672707f5b6 | ||
|
|
83057e863f |
6
.idea/misc.xml
generated
6
.idea/misc.xml
generated
@@ -1,5 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="JavadocGenerationManager">
|
||||||
|
<option name="OUTPUT_DIRECTORY" value="$USER_HOME$/Desktop/Javadocs TaipanClone" />
|
||||||
|
<option name="OPTION_HIERARCHY" value="false" />
|
||||||
|
<option name="OPTION_NAVIGATOR" value="false" />
|
||||||
|
<option name="OPTION_INDEX" value="false" />
|
||||||
|
</component>
|
||||||
<component name="ProjectKey">
|
<component name="ProjectKey">
|
||||||
<option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" />
|
<option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
766
.idea/workspace.xml
generated
766
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -2,12 +2,10 @@
|
|||||||
Computer Science 233 project, Winter 2019
|
Computer Science 233 project, Winter 2019
|
||||||
|
|
||||||
How to run:
|
How to run:
|
||||||
If you are using intellij, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder in intellij. Also set up the SDK. Then, run main.java.
|
If you are using intellij, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder in intellij. Also set up the SDK. Then, run MainGUI.java.
|
||||||
|
|
||||||
If you are using the command line, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder. Open your terminal and change its directory to the "src" folder within "TaipanClone-master" folder. Then, type in "javac *.java", this compiles all the necessary files. Now, run main.java using "java main".
|
If you are using the command line, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder. Open your terminal and change its directory to the "src" folder within "TaipanClone-master" folder. Then, type in "javac *.java", this compiles all the necessary files. Now, run main.java using "java main".
|
||||||
|
|
||||||
Additional information:
|
Additional information:
|
||||||
For input, the program usually takes the first letter of whichever option you need to select. Example:
|
|
||||||
What would you like to buy? Valid inputs are "O" (for Opium), "S" (for Silk), "A" (for Arms), "G" (for General cargo).
|
|
||||||
|
|
||||||
You lose if your HP reaches 0. You can win if you "retire" in Hong Kong while having a net worth of over $1 million.
|
You lose if your HP reaches 0. You can win if you "retire" in Hong Kong while having a net worth of over $1 million.
|
||||||
|
|||||||
@@ -9,4 +9,3 @@
|
|||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -1,70 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Bank{
|
|
||||||
|
|
||||||
private Player player;
|
|
||||||
public void setPlayer(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer(){
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
return playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bank(Player player){
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void bank(){
|
|
||||||
Scanner input = new Scanner(System.in);
|
|
||||||
boolean notDone = true;
|
|
||||||
int check = 0;
|
|
||||||
while(notDone){
|
|
||||||
System.out.println("Would you like to Withdraw or Deposit?");
|
|
||||||
String response = input.nextLine();
|
|
||||||
if(response.equalsIgnoreCase("W")){
|
|
||||||
boolean notDone2 = true;
|
|
||||||
while(notDone2){
|
|
||||||
System.out.println("How much do you wish to Withdraw?");
|
|
||||||
int withdraw = input.nextInt();
|
|
||||||
if(withdraw <= player.getBank()){
|
|
||||||
player.setMoney(withdraw + player.getMoney());
|
|
||||||
player.setBank(player.getBank()-withdraw);
|
|
||||||
notDone2 = false;
|
|
||||||
check = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else if(response.equalsIgnoreCase("D")){
|
|
||||||
boolean notDone2 = true;
|
|
||||||
while(notDone2){
|
|
||||||
System.out.println("How much do you wish to Deposit?");
|
|
||||||
int deposit = input.nextInt();
|
|
||||||
if(deposit <= player.getMoney()){
|
|
||||||
player.setBank(deposit + player.getBank());
|
|
||||||
player.setMoney(player.getMoney()-deposit);
|
|
||||||
notDone2 = false;
|
|
||||||
check = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(check == 1){
|
|
||||||
boolean notDone3 = true;
|
|
||||||
while(notDone3){
|
|
||||||
System.out.println("Would you like to continue? Y/N");
|
|
||||||
response = input.nextLine();
|
|
||||||
response = input.nextLine();
|
|
||||||
if(response.equalsIgnoreCase("Y")){
|
|
||||||
notDone3 = false;
|
|
||||||
}else if(response.equalsIgnoreCase("N")){
|
|
||||||
notDone = false;
|
|
||||||
notDone3 = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
183
src/BankGUI.java
Normal file
183
src/BankGUI.java
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class BankGUI {
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method that takes in a Player object as an argument.
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public void setPlayer(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for obtaining a player object.
|
||||||
|
*
|
||||||
|
* @return returns player object
|
||||||
|
*/
|
||||||
|
public Player getPlayer() {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
return playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
* <p>
|
||||||
|
* //* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public BankGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the GUI for the Bank in our game.
|
||||||
|
*
|
||||||
|
* @param primaryStage
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Stage initializeBank(Stage primaryStage) {
|
||||||
|
primaryStage.setTitle("Bank");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creating all the layouts, labels, buttons, and a textfield.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BorderPane brdr1 = new BorderPane();
|
||||||
|
HBox hbx1 = new HBox(30);
|
||||||
|
HBox hbx2 = new HBox(30);
|
||||||
|
VBox vbx1 = new VBox(30);
|
||||||
|
|
||||||
|
Label l1 = new Label("Player: " + player.getName());
|
||||||
|
Label l2 = new Label("Current Balance: " + player.getBank());
|
||||||
|
Label l3 = new Label("Enter Amount: ");
|
||||||
|
Label l4 = new Label("Current cash: " + player.getMoney());
|
||||||
|
Label l5 = new Label(" ");
|
||||||
|
|
||||||
|
Button b1 = new Button("Withdraw");
|
||||||
|
Button b2 = new Button("Deposit");
|
||||||
|
Button b3 = new Button("Go back");
|
||||||
|
|
||||||
|
TextField txtField1 = new TextField();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the buttons so that they are at the bottom of the screen.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
hbx1.setAlignment(Pos.CENTER);
|
||||||
|
hbx1.getChildren().add(b1);
|
||||||
|
hbx1.getChildren().add(b2);
|
||||||
|
hbx1.getChildren().add(b3);
|
||||||
|
|
||||||
|
brdr1.setBottom(hbx1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the text field to the center of the screen.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
hbx2.setAlignment(Pos.CENTER);
|
||||||
|
hbx2.getChildren().add(l3);
|
||||||
|
hbx2.getChildren().add(txtField1);
|
||||||
|
brdr1.setCenter(hbx2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the labels to the top of the screen.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
vbx1.setAlignment(Pos.CENTER);
|
||||||
|
vbx1.getChildren().add(l1);
|
||||||
|
vbx1.getChildren().add(l2);
|
||||||
|
vbx1.getChildren().add(l4);
|
||||||
|
vbx1.getChildren().add(l5);
|
||||||
|
brdr1.setTop(vbx1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds function to button 1 which, when clicked, withdraws money from your bank to your person but, will not let you overdraw.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
b1.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
int withdraw = Integer.parseInt(txtField1.getText());
|
||||||
|
if (withdraw <= player.getBank()) {
|
||||||
|
player.setMoney(withdraw + player.getMoney());
|
||||||
|
player.setBank(player.getBank() - withdraw);
|
||||||
|
} else {
|
||||||
|
l5.setText("Sorry you cannot withdraw that much");
|
||||||
|
}
|
||||||
|
l2.setText("Current Balance: " + player.getBank());
|
||||||
|
l4.setText("Current cash: " + player.getMoney());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds function to button 2 which, when clicked, deposits money into your bank but, will not let you overdraw.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// Set the event handler when the withdraw button is clicked
|
||||||
|
b2.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
int deposit = Integer.parseInt(txtField1.getText());
|
||||||
|
if (deposit <= player.getMoney()) {
|
||||||
|
player.setBank(deposit + player.getBank());
|
||||||
|
player.setMoney(player.getMoney() - deposit);
|
||||||
|
} else {
|
||||||
|
l5.setText("Sorry you cannot deposit that much");
|
||||||
|
}
|
||||||
|
l2.setText("Current Balance: " + player.getBank());
|
||||||
|
l4.setText("Current cash: " + player.getMoney());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds function to button 3 which, when clicked, brings you back to the Shop GUI.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
b3.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
TaipanShopGUI shopGUI = new TaipanShopGUI(player);
|
||||||
|
shopGUI.initializeShop(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the window size to a width of 600 and height of 480 and displays the screen.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Scene scene = new Scene(brdr1, 600, 480);
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
return primaryStage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets scene and runs stage
|
||||||
|
*
|
||||||
|
* @param primaryStage the stage in which the scene may be run and switched to
|
||||||
|
*/
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
BankGUI bank = new BankGUI(player);
|
||||||
|
bank.initializeBank(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
114
src/GameEndGUI.java
Normal file
114
src/GameEndGUI.java
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class GameEndGUI {
|
||||||
|
|
||||||
|
private Label title;
|
||||||
|
private VBox vBox;
|
||||||
|
private Label firmName;
|
||||||
|
private Label gunsHeld;
|
||||||
|
private Label netWorth;
|
||||||
|
private BorderPane borderPane;
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
public GameEndGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the graphical part of GameEndGUI and includes all logic for the class
|
||||||
|
*
|
||||||
|
* @param stage sets the stage to which we will execute the scene of the GameEndGUI class
|
||||||
|
* @return stage so that another class can switch to the stage
|
||||||
|
*/
|
||||||
|
public Stage initializeGameEndGUI(Stage stage) {
|
||||||
|
|
||||||
|
//Creating all the nodes
|
||||||
|
title = new Label();
|
||||||
|
vBox = new VBox();
|
||||||
|
firmName = new Label();
|
||||||
|
gunsHeld = new Label();
|
||||||
|
netWorth = new Label();
|
||||||
|
borderPane = new BorderPane();
|
||||||
|
int netWorthInt = 0;
|
||||||
|
|
||||||
|
borderPane.setPrefHeight(480.0);
|
||||||
|
borderPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
//Setting positions and names of all the nodes
|
||||||
|
BorderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
|
||||||
|
title.setText("Game Over!");
|
||||||
|
title.setFont(new Font(43.0));
|
||||||
|
BorderPane.setMargin(title, new Insets(0.0));
|
||||||
|
title.setPadding(new Insets(50.0, 0.0, 0.0, 0.0));
|
||||||
|
borderPane.setTop(title);
|
||||||
|
|
||||||
|
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
|
||||||
|
vBox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
vBox.setPrefHeight(200.0);
|
||||||
|
vBox.setPrefWidth(100.0);
|
||||||
|
|
||||||
|
firmName.setText("Name:");
|
||||||
|
firmName.setFont(new Font(22.0));
|
||||||
|
|
||||||
|
gunsHeld.setText("Guns Held:");
|
||||||
|
gunsHeld.setFont(new Font(22.0));
|
||||||
|
|
||||||
|
netWorth.setText("Net Worth:");
|
||||||
|
netWorth.setFont(new Font(22.0));
|
||||||
|
borderPane.setCenter(vBox);
|
||||||
|
|
||||||
|
|
||||||
|
//Adding the labels to the character's stats to the VBox which will show up on the screen
|
||||||
|
vBox.getChildren().add(firmName);
|
||||||
|
vBox.getChildren().add(gunsHeld);
|
||||||
|
vBox.getChildren().add(netWorth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If health is below or equal to 0 then the game will either show the gameOver screen or the win screen
|
||||||
|
* */
|
||||||
|
if (player.getHP() <= 0) {
|
||||||
|
title.setText("Game Over!");
|
||||||
|
} else {
|
||||||
|
title.setText("Congratulations!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the networth of the player by the end of the game
|
||||||
|
* */
|
||||||
|
netWorthInt = player.getMoney() + (player.getOpiumHeld() * 16000) + (player.getSilkHeld() * 160) + (player.getArmsHeld() * 160) + (player.getGeneralHeld() * 8);
|
||||||
|
netWorthInt += (player.getwOpium() * 16000) + (player.getwSilk() * 160) + (player.getwArms() * 160) + (player.getwGeneral() * 8);
|
||||||
|
netWorthInt -= player.getDebt();
|
||||||
|
|
||||||
|
|
||||||
|
//Updating the endgame stats of the player
|
||||||
|
firmName.setText("Firm Name: " + player.getName());
|
||||||
|
gunsHeld.setText("Guns Held: " + player.getGuns());
|
||||||
|
netWorth.setText("Net Worth: " + netWorthInt);
|
||||||
|
|
||||||
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
|
|
||||||
|
stage.setTitle("End Game Stats");
|
||||||
|
stage.setResizable(false);
|
||||||
|
stage.setScene(root);
|
||||||
|
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets scene and runs stage
|
||||||
|
*
|
||||||
|
* @param primaryStage the stage in which the scene may be run and switched to
|
||||||
|
*/
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
GameEndGUI gameEndGUI = new GameEndGUI(player);
|
||||||
|
gameEndGUI.initializeGameEndGUI(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
170
src/LoanSharkGUI.java
Normal file
170
src/LoanSharkGUI.java
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class LoanSharkGUI {
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method that takes in a Player object as an argument.
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public void setPlayer(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for obtaining a player object.
|
||||||
|
*
|
||||||
|
* @return returns player object
|
||||||
|
*/
|
||||||
|
public Player getPlayer() {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
return playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
* <p>
|
||||||
|
* //* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public LoanSharkGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stage initializeLoanShark(Stage primaryStage) {
|
||||||
|
primaryStage.setTitle("Loan Shark");
|
||||||
|
|
||||||
|
//Declaring each Layout
|
||||||
|
BorderPane brdr1 = new BorderPane();
|
||||||
|
HBox hbx1 = new HBox(10);
|
||||||
|
HBox hbx2 = new HBox(10);
|
||||||
|
VBox vbx1 = new VBox(10);
|
||||||
|
|
||||||
|
//Declaring all Variables
|
||||||
|
Label l1 = new Label("Player: " + player.getName());
|
||||||
|
Label l2 = new Label("Current Debt " + player.getDebt());
|
||||||
|
Label l4 = new Label("Current cash: " + player.getMoney());
|
||||||
|
Label l3 = new Label("Enter Amount: ");
|
||||||
|
Label l5 = new Label(" ");
|
||||||
|
|
||||||
|
//Declaring All Buttons
|
||||||
|
Button b1 = new Button("Borrow");
|
||||||
|
Button b2 = new Button("Repay");
|
||||||
|
Button b3 = new Button("Go back");
|
||||||
|
|
||||||
|
//Declaring All TextFields
|
||||||
|
TextField txtField1 = new TextField();
|
||||||
|
|
||||||
|
//Creating the buttons at the bottom of the screen
|
||||||
|
hbx1.setAlignment(Pos.CENTER);
|
||||||
|
hbx1.getChildren().add(b1);
|
||||||
|
hbx1.getChildren().add(b2);
|
||||||
|
hbx1.getChildren().add(b3);
|
||||||
|
|
||||||
|
brdr1.setBottom(hbx1);
|
||||||
|
|
||||||
|
//Creating the TextField at the center of the screen
|
||||||
|
hbx2.setAlignment(Pos.CENTER);
|
||||||
|
hbx2.getChildren().add(l3);
|
||||||
|
hbx2.getChildren().add(txtField1);
|
||||||
|
brdr1.setCenter(hbx2);
|
||||||
|
|
||||||
|
//Creating the Labels at the top of the Screen
|
||||||
|
vbx1.setAlignment(Pos.CENTER);
|
||||||
|
vbx1.getChildren().add(l1);
|
||||||
|
vbx1.getChildren().add(l2);
|
||||||
|
vbx1.getChildren().add(l4);
|
||||||
|
vbx1.getChildren().add(l5);
|
||||||
|
brdr1.setTop(vbx1);
|
||||||
|
|
||||||
|
// Set the event handler when the deposit button is clicked
|
||||||
|
boolean keepGoing = true;
|
||||||
|
b1.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
int loanAsk = Integer.parseInt(txtField1.getText());
|
||||||
|
if (loanAsk <= 2 * (player.getMoney() - player.getDebt()) && loanAsk >= 0) {
|
||||||
|
player.setDebt(player.getDebt() + loanAsk);
|
||||||
|
player.setMoney(player.getMoney() + loanAsk);
|
||||||
|
l4.setText("Current cash: " + player.getMoney());
|
||||||
|
} else {
|
||||||
|
l5.setText("Sorry you cannot be loaned that much");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
l2.setText("Debt: " + player.getDebt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set the event handler when the withdraw button is clicked
|
||||||
|
b2.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
int returnAsk = Integer.parseInt(txtField1.getText());
|
||||||
|
if (returnAsk <= player.getDebt() && returnAsk >= 0) {
|
||||||
|
player.setDebt(player.getDebt() - returnAsk);
|
||||||
|
player.setMoney(player.getMoney() - returnAsk);
|
||||||
|
l4.setText("Current cash: " + player.getMoney());
|
||||||
|
} else if (returnAsk > player.getDebt()) {
|
||||||
|
l5.setText("Sorry you cannot be loaned that much");
|
||||||
|
} else {
|
||||||
|
l5.setText("Sorry you cannot return a negative amount");
|
||||||
|
}
|
||||||
|
l2.setText("Debt: " + player.getDebt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
b3.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
TaipanShopGUI shopGUI = new TaipanShopGUI(player);
|
||||||
|
shopGUI.initializeShop(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//Setting the Scene and displaying it
|
||||||
|
Scene scene = new Scene(brdr1, 600, 480);
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
//primaryStage.show();
|
||||||
|
return primaryStage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
LoanSharkGUI loan = new LoanSharkGUI(player);
|
||||||
|
loan.initializeLoanShark(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This methods purpose is to loan the player the funds it wants
|
||||||
|
* or pay its outstanding debts. The method prompts the user if they
|
||||||
|
* would like to borrow money or repay. depending on what the player chooses
|
||||||
|
* the corresponding loop is evoked. The player can only be loaned 2 times the
|
||||||
|
* money they have minus the debt id their debt exceeds the cash balance, the loan
|
||||||
|
* cannot be given.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
45
src/MainGUI.java
Normal file
45
src/MainGUI.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class MainGUI extends Application {
|
||||||
|
private Player player = new Player();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the Player object player.
|
||||||
|
*
|
||||||
|
* @return returns a copy of the object player
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
Player copy = new Player(player);
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the Taipan shop with the players stats after the player finishes shopping, it updates the player object and returns it.
|
||||||
|
*
|
||||||
|
* @param shop player object from the main class used to update the shop class
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void shop(TaipanShopGUI shop) {
|
||||||
|
shop.setPlayer(player);
|
||||||
|
shop.shop();
|
||||||
|
player = shop.getPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates main class with player data and starts the game.
|
||||||
|
* The game will only run as long as the player has not retired or has been destroyed.
|
||||||
|
*
|
||||||
|
* @param args Just the console for the player to look at.
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
StartGUI start = new StartGUI(player);
|
||||||
|
start.initializeStart(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
288
src/Player.java
288
src/Player.java
@@ -8,7 +8,7 @@ public class Player {
|
|||||||
private int generalHeld = 0;
|
private int generalHeld = 0;
|
||||||
private int armsHeld = 0;
|
private int armsHeld = 0;
|
||||||
private int location = 1;
|
private int location = 1;
|
||||||
private int guns = 0;
|
private int guns = 5;
|
||||||
private int HP = 100;
|
private int HP = 100;
|
||||||
private int debt = 0;
|
private int debt = 0;
|
||||||
private int wOpium = 0;
|
private int wOpium = 0;
|
||||||
@@ -16,12 +16,35 @@ public class Player {
|
|||||||
private int wGeneral = 0;
|
private int wGeneral = 0;
|
||||||
private int wArms = 0;
|
private int wArms = 0;
|
||||||
private boolean retire = false;
|
private boolean retire = false;
|
||||||
|
private int cargoSpace = 60;
|
||||||
|
|
||||||
public Player(){
|
public Player() {
|
||||||
|
this.name = "Taipan";
|
||||||
|
this.bank = 0;
|
||||||
|
this.money = 0;
|
||||||
|
this.opiumHeld = 0;
|
||||||
|
this.silkHeld = 0;
|
||||||
|
this.generalHeld = 0;
|
||||||
|
this.armsHeld = 0;
|
||||||
|
this.location = 1;
|
||||||
|
this.guns = 0;
|
||||||
|
this.HP = 100;
|
||||||
|
this.debt = 0;
|
||||||
|
this.wOpium = 0;
|
||||||
|
this.wSilk = 0;
|
||||||
|
this.wGeneral = 0;
|
||||||
|
this.wArms = 0;
|
||||||
|
this.retire = false;
|
||||||
|
this.cargoSpace = 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player(Player player){
|
/**
|
||||||
|
* Copy constructor
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public Player(Player player) {
|
||||||
|
this.name = player.name;
|
||||||
this.bank = player.bank;
|
this.bank = player.bank;
|
||||||
this.money = player.money;
|
this.money = player.money;
|
||||||
this.opiumHeld = player.opiumHeld;
|
this.opiumHeld = player.opiumHeld;
|
||||||
@@ -36,162 +59,389 @@ public class Player {
|
|||||||
this.wSilk = player.wSilk;
|
this.wSilk = player.wSilk;
|
||||||
this.wGeneral = player.wGeneral;
|
this.wGeneral = player.wGeneral;
|
||||||
this.wArms = player.wArms;
|
this.wArms = player.wArms;
|
||||||
|
this.cargoSpace = player.cargoSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getRetire(){
|
/**
|
||||||
|
* getter method for the instance variable cargoSpace.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable cargoSpace
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getCargoSpace() {
|
||||||
|
return cargoSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable cargoSpace.
|
||||||
|
*
|
||||||
|
* @param cargoSpace takes an int that is greater than 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void setCargoSpace(int cargoSpace) {
|
||||||
|
if (cargoSpace > 0) {
|
||||||
|
this.cargoSpace = cargoSpace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable retire.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable retire
|
||||||
|
*/
|
||||||
|
|
||||||
|
public boolean getRetire() {
|
||||||
return retire;
|
return retire;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRetire(boolean retire){
|
/**
|
||||||
if(retire){
|
* setter method for the instance variable retire.
|
||||||
|
*
|
||||||
|
* @param retire takes a boolean as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void setRetire(boolean retire) {
|
||||||
|
if (retire) {
|
||||||
this.retire = retire;
|
this.retire = retire;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable name.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable name
|
||||||
|
*/
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable name.
|
||||||
|
*
|
||||||
|
* @param name takes a string as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable HP.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable HP
|
||||||
|
*/
|
||||||
|
|
||||||
public int getHP() {
|
public int getHP() {
|
||||||
return HP;
|
return HP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable HP.
|
||||||
|
*
|
||||||
|
* @param HP takes an int as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setHP(int HP) {
|
public void setHP(int HP) {
|
||||||
|
|
||||||
this.HP = HP;
|
this.HP = HP;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable bank.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable bank
|
||||||
|
*/
|
||||||
|
|
||||||
public int getBank() {
|
public int getBank() {
|
||||||
return bank;
|
return bank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable bank.
|
||||||
|
*
|
||||||
|
* @param bank takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setBank(int bank) {
|
public void setBank(int bank) {
|
||||||
if (bank >= 0) {
|
if (bank >= 0) {
|
||||||
this.bank = bank;
|
this.bank = bank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable money.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable money
|
||||||
|
*/
|
||||||
|
|
||||||
public int getMoney() {
|
public int getMoney() {
|
||||||
return money;
|
return money;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable money.
|
||||||
|
*
|
||||||
|
* @param money takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setMoney(int money) {
|
public void setMoney(int money) {
|
||||||
if (money >= 0) {
|
if (money >= 0) {
|
||||||
this.money = money;
|
this.money = money;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable opiumHeld.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable opiumHeld
|
||||||
|
*/
|
||||||
|
|
||||||
public int getOpiumHeld() {
|
public int getOpiumHeld() {
|
||||||
return opiumHeld;
|
return opiumHeld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable opiumHeld.
|
||||||
|
*
|
||||||
|
* @param opiumHeld takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setOpiumHeld(int opiumHeld) {
|
public void setOpiumHeld(int opiumHeld) {
|
||||||
if (opiumHeld >= 0) {
|
if (opiumHeld >= 0) {
|
||||||
this.opiumHeld = opiumHeld;
|
this.opiumHeld = opiumHeld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable silkHeld.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable silkHeld
|
||||||
|
*/
|
||||||
|
|
||||||
public int getSilkHeld() {
|
public int getSilkHeld() {
|
||||||
return silkHeld;
|
return silkHeld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable silkHeld.
|
||||||
|
*
|
||||||
|
* @param silkHeld takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setSilkHeld(int silkHeld) {
|
public void setSilkHeld(int silkHeld) {
|
||||||
if (silkHeld >= 0) {
|
if (silkHeld >= 0) {
|
||||||
this.silkHeld = silkHeld;
|
this.silkHeld = silkHeld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable generalHeld.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable generalHeld
|
||||||
|
*/
|
||||||
|
|
||||||
public int getGeneralHeld() {
|
public int getGeneralHeld() {
|
||||||
return generalHeld;
|
return generalHeld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable generalHeld.
|
||||||
|
*
|
||||||
|
* @param generalHeld takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setGeneralHeld(int generalHeld) {
|
public void setGeneralHeld(int generalHeld) {
|
||||||
if (generalHeld >= 0) {
|
if (generalHeld >= 0) {
|
||||||
this.generalHeld = generalHeld;
|
this.generalHeld = generalHeld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable armsHeld.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable armsHeld
|
||||||
|
*/
|
||||||
|
|
||||||
public int getArmsHeld() {
|
public int getArmsHeld() {
|
||||||
return armsHeld;
|
return armsHeld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable armsHeld.
|
||||||
|
*
|
||||||
|
* @param armsHeld takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setArmsHeld(int armsHeld) {
|
public void setArmsHeld(int armsHeld) {
|
||||||
if (armsHeld >= 0) {
|
if (armsHeld >= 0) {
|
||||||
this.armsHeld = armsHeld;
|
this.armsHeld = armsHeld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable location.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable location
|
||||||
|
*/
|
||||||
|
|
||||||
public int getLocation() {
|
public int getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable location.
|
||||||
|
*
|
||||||
|
* @param location takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setLocation(int location) {
|
public void setLocation(int location) {
|
||||||
if (location >= 0) {
|
if (location >= 0) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable guns.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable guns
|
||||||
|
*/
|
||||||
|
|
||||||
public int getGuns() {
|
public int getGuns() {
|
||||||
return guns;
|
return guns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable guns.
|
||||||
|
*
|
||||||
|
* @param guns takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setGuns(int guns) {
|
public void setGuns(int guns) {
|
||||||
if (guns >= 0) {
|
if (guns >= 0) {
|
||||||
this.guns = guns;
|
this.guns = guns;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for the instance variable debt.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable debt
|
||||||
|
*/
|
||||||
|
|
||||||
public int getDebt() {
|
public int getDebt() {
|
||||||
return debt;
|
return debt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable debt.
|
||||||
|
*
|
||||||
|
* @param debt takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setDebt(int debt) {
|
public void setDebt(int debt) {
|
||||||
if (debt >= 0) {
|
if (debt >= 0) {
|
||||||
this.debt = debt;
|
this.debt = debt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getwOpium(){ return wOpium; }
|
/**
|
||||||
|
* getter method for the instance variable wOpium.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable wOpium
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getwOpium() {
|
||||||
|
return wOpium;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable wOpium.
|
||||||
|
*
|
||||||
|
* @param wOpium takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setwOpium(int wOpium) {
|
public void setwOpium(int wOpium) {
|
||||||
if (wOpium >= 0){
|
if (wOpium >= 0) {
|
||||||
this.wOpium = wOpium;
|
this.wOpium = wOpium;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getwSilk(){return wSilk;}
|
/**
|
||||||
|
* getter method for the instance variable wSilk.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable wSilk
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getwSilk() {
|
||||||
|
return wSilk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable wSilk.
|
||||||
|
*
|
||||||
|
* @param wSilk takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setwSilk(int wSilk) {
|
public void setwSilk(int wSilk) {
|
||||||
if (wSilk >= 0){
|
if (wSilk >= 0) {
|
||||||
this.wSilk = wSilk;
|
this.wSilk = wSilk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getwGeneral(){return wGeneral;}
|
/**
|
||||||
|
* getter method for the instance variable wGeneral.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable wGeneral
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getwGeneral() {
|
||||||
|
return wGeneral;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable wGeneral.
|
||||||
|
*
|
||||||
|
* @param wGeneral takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setwGeneral(int wGeneral) {
|
public void setwGeneral(int wGeneral) {
|
||||||
if (wGeneral >= 0){
|
if (wGeneral >= 0) {
|
||||||
this.wGeneral = wGeneral;
|
this.wGeneral = wGeneral;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getwArms(){return wArms;}
|
/**
|
||||||
|
* getter method for the instance variable wArms.
|
||||||
|
*
|
||||||
|
* @return returns the instance variable wArms
|
||||||
|
*/
|
||||||
|
|
||||||
|
public int getwArms() {
|
||||||
|
return wArms;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for the instance variable wArms.
|
||||||
|
*
|
||||||
|
* @param wArms takes an int that is greater than or equal to 0 as an argument
|
||||||
|
*/
|
||||||
|
|
||||||
public void setwArms(int wArms) {
|
public void setwArms(int wArms) {
|
||||||
if (wArms >= 0){
|
if (wArms >= 0) {
|
||||||
this.wArms = wArms;
|
this.wArms = wArms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameOver(){
|
/**
|
||||||
|
* Method to indicate that you have lost the game. If the player has lost, console will be cleared and will only
|
||||||
|
* show the statement "Game Over". After showing the message the game closes.
|
||||||
|
**/
|
||||||
|
|
||||||
|
public void gameOver() {
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
System.out.println("Game over");
|
System.out.println("Game over");
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,386 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class ShipWarfare {
|
|
||||||
|
|
||||||
private int numOfPeasantShips = 0;
|
|
||||||
private int numOfLittyShips = 0;
|
|
||||||
private boolean userAttacks = true;
|
|
||||||
private int startingPeasantShips = 0;
|
|
||||||
private int startingLittyShips =0;
|
|
||||||
private int howMuchRun = 0;
|
|
||||||
private String pirateName = "Liu Yen";
|
|
||||||
private Player player;
|
|
||||||
|
|
||||||
public ShipWarfare(Player player){
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayer(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer(){
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
return playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
//This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
|
|
||||||
public void peasantFleetAttack() throws Exception {
|
|
||||||
Scanner userResponse = new Scanner(System.in);
|
|
||||||
setNumOfPeasantShips(numOfShips());
|
|
||||||
|
|
||||||
System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfPeasantShips, player.getHP());
|
|
||||||
|
|
||||||
fightOrRunMessage();
|
|
||||||
while (true) {
|
|
||||||
String response = userResponse.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("f")) {
|
|
||||||
userAttacks = true;
|
|
||||||
System.out.println("Ohh, fight ehh?");
|
|
||||||
boolean winOrLose = destroyPeasantShipsOrEscape();
|
|
||||||
if (winOrLose == true) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("r")) {
|
|
||||||
if (runFromShips() == false) {
|
|
||||||
System.out.println("Couldn't run away!");
|
|
||||||
if (destroyPeasantShipsOrEscape())
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
System.out.println("Phew! Got away safely");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
//This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
|
|
||||||
public void littyFleetAttack() throws Exception {
|
|
||||||
Scanner userResponse = new Scanner(System.in);
|
|
||||||
setNumOfLittyShips(numOfShips());
|
|
||||||
System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfLittyShips, pirateName, player.getHP());
|
|
||||||
fightOrRunMessage();
|
|
||||||
while (true) {
|
|
||||||
String response = userResponse.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("f")) {
|
|
||||||
userAttacks = true;
|
|
||||||
System.out.println("Ohh, fight ehh?");
|
|
||||||
boolean winOrLose = destroyLittyShipsOrEscape();
|
|
||||||
if (winOrLose == true) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("r")) {
|
|
||||||
if (runFromShips() == false) {
|
|
||||||
System.out.println("Couldn't run away!");
|
|
||||||
if (destroyLittyShipsOrEscape())
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
System.out.println("Phew! Got away safely");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void fightOrRunMessage() {
|
|
||||||
System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)", player.getGuns());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int numOfPeasantShips() {
|
|
||||||
return numOfPeasantShips;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNumOfLittyShips(int numOfLittyShips) {
|
|
||||||
this.numOfLittyShips = numOfLittyShips;
|
|
||||||
startingLittyShips = numOfLittyShips;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNumOfPeasantShips(int numOfPeasantShips) {
|
|
||||||
this.numOfPeasantShips = numOfPeasantShips;
|
|
||||||
startingPeasantShips = numOfPeasantShips;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delayForASecond() throws Exception {
|
|
||||||
TimeUnit.SECONDS.sleep(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//The number of ships which attack is based on the amount of money one has on hand
|
|
||||||
public int numOfShips() {
|
|
||||||
|
|
||||||
int numOfShipsAttacking = 0;
|
|
||||||
Random randomValue = new Random();
|
|
||||||
|
|
||||||
if (player.getMoney() <= 100000) {
|
|
||||||
//Minimum one ship will attack, maximum 20
|
|
||||||
numOfShipsAttacking = randomValue.nextInt(20) + 1;
|
|
||||||
} else if (player.getMoney() <= 200000) {
|
|
||||||
//Minimum 30 Ships will attack, maximum 70
|
|
||||||
numOfShipsAttacking = randomValue.nextInt(40) + 30;
|
|
||||||
} else if (player.getMoney() <= 500000) {
|
|
||||||
//Minimum 50 ships will attack, maximum 140
|
|
||||||
numOfShipsAttacking = randomValue.nextInt(90) + 50;
|
|
||||||
} else if (player.getMoney() > 1000000) {
|
|
||||||
//Minimum 100 ships will attack, maximum 300 ships
|
|
||||||
numOfShipsAttacking = randomValue.nextInt(3) + 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
return numOfShipsAttacking;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//One in two chance of running away
|
|
||||||
public boolean runFromShips() {
|
|
||||||
userAttacks = false;
|
|
||||||
Random randomValue = new Random();
|
|
||||||
int runSuccessChance = randomValue.nextInt(2) + 1;
|
|
||||||
if (runSuccessChance == 2) {
|
|
||||||
return true;
|
|
||||||
} else if (runSuccessChance == 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//The loot for defeating a litty fleet is much higher than that of a peasant one
|
|
||||||
public boolean destroyLittyShipsOrEscape() throws Exception {
|
|
||||||
int calculateLoot = 0;
|
|
||||||
int chanceOfEnemyRun = 0;
|
|
||||||
|
|
||||||
|
|
||||||
Scanner userInput = new Scanner(System.in);
|
|
||||||
Random randomValue = new Random();
|
|
||||||
int exitValue = 0;
|
|
||||||
|
|
||||||
//Player volley
|
|
||||||
while (exitValue == 0) {
|
|
||||||
for (int j = 0; j < player.getGuns(); j++) {
|
|
||||||
if (userAttacks == true) {
|
|
||||||
int hitOrMiss = randomValue.nextInt(3) + 1;
|
|
||||||
if (hitOrMiss == 1) {
|
|
||||||
numOfLittyShips--;
|
|
||||||
if (numOfLittyShips <= 0) {
|
|
||||||
exitValue = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.println("Got eem");
|
|
||||||
delayForASecond();
|
|
||||||
} else if (hitOrMiss == 2) {
|
|
||||||
System.out.printf("ARRG! We missed %s\n", player.getName());
|
|
||||||
delayForASecond();
|
|
||||||
} else {
|
|
||||||
System.out.println("Darn! Their fleet tanked our attack");
|
|
||||||
delayForASecond();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (numOfLittyShips <= 0) {
|
|
||||||
exitValue = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
|
||||||
if (chanceOfEnemyRun == 2) {
|
|
||||||
howMuchRun = randomValue.nextInt(10) + 1;
|
|
||||||
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
|
|
||||||
|
|
||||||
|
|
||||||
setNumOfLittyShips(numOfLittyShips - howMuchRun);
|
|
||||||
if (userAttacks == true) {
|
|
||||||
System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, player.getName());
|
|
||||||
} else {
|
|
||||||
System.out.printf("Escaped %d of them!\n", howMuchRun);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.printf("%d ships remaining\n", numOfLittyShips);
|
|
||||||
System.out.println("Oh no, they are taking the offensive!");
|
|
||||||
delayForASecond();
|
|
||||||
//Computer volley
|
|
||||||
int takeGunChance = randomValue.nextInt(4) + 1;
|
|
||||||
if (takeGunChance == 1 && player.getGuns() > 0) {
|
|
||||||
player.setGuns(player.getGuns() - 1);
|
|
||||||
System.out.println("Dang it! They destroyed one of our guns");
|
|
||||||
} else {
|
|
||||||
player.setHP(player.getHP() - (1 + randomValue.nextInt(15)));
|
|
||||||
}
|
|
||||||
if (player.getHP() <= 0) {
|
|
||||||
exitValue = 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
|
|
||||||
delayForASecond();
|
|
||||||
if (userAttacks == false) {
|
|
||||||
userAttacks = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns());
|
|
||||||
|
|
||||||
String response = userInput.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("r")) {
|
|
||||||
if (runFromShips() == false) {
|
|
||||||
System.out.println("Couldn't run away");
|
|
||||||
} else {
|
|
||||||
exitValue = 3;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (exitValue == 1) {
|
|
||||||
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
|
|
||||||
calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300;
|
|
||||||
player.setMoney(player.getMoney() + calculateLoot);
|
|
||||||
System.out.printf("We got $%,d!\n", calculateLoot);
|
|
||||||
return true;
|
|
||||||
} else if (exitValue == 2) {
|
|
||||||
player.gameOver();
|
|
||||||
return true;
|
|
||||||
} else if (exitValue == 3) {
|
|
||||||
System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean destroyPeasantShipsOrEscape() throws Exception {
|
|
||||||
int calculateLoot = 0;
|
|
||||||
int chanceOfEnemyRun = 0;
|
|
||||||
|
|
||||||
|
|
||||||
Scanner userInput = new Scanner(System.in);
|
|
||||||
Random randomValue = new Random();
|
|
||||||
int exitValue = 0;
|
|
||||||
|
|
||||||
//Player volley
|
|
||||||
while (exitValue == 0) {
|
|
||||||
for (int j = 0; j < player.getGuns(); j++) {
|
|
||||||
if (userAttacks == true) {
|
|
||||||
int hitOrMiss = randomValue.nextInt(2) + 1;
|
|
||||||
if (hitOrMiss == 2) {
|
|
||||||
numOfPeasantShips--;
|
|
||||||
if (numOfPeasantShips <= 0) {
|
|
||||||
exitValue = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.println("Got eem");
|
|
||||||
delayForASecond();
|
|
||||||
} else {
|
|
||||||
System.out.printf("ARRG! We missed %s\n", player.getName());
|
|
||||||
delayForASecond();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (numOfPeasantShips <= 0) {
|
|
||||||
exitValue = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
|
||||||
if (chanceOfEnemyRun == 2) {
|
|
||||||
howMuchRun = randomValue.nextInt(15) + 1;
|
|
||||||
if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) {
|
|
||||||
|
|
||||||
|
|
||||||
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
|
|
||||||
if (userAttacks == true) {
|
|
||||||
System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, player.getName());
|
|
||||||
} else {
|
|
||||||
System.out.printf("Escaped %d of them!\n", howMuchRun);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.printf("%d ships remaining\n", numOfPeasantShips);
|
|
||||||
System.out.println("Oh no, they are taking the offensive!");
|
|
||||||
delayForASecond();
|
|
||||||
//Computer volley
|
|
||||||
int takeGunChance = randomValue.nextInt(4) + 1;
|
|
||||||
if (takeGunChance == 1 && player.getGuns() > 0) {
|
|
||||||
player.setGuns(player.getGuns() - 1);
|
|
||||||
System.out.println("Dang it! They destroyed one of our guns");
|
|
||||||
} else {
|
|
||||||
player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
|
|
||||||
}
|
|
||||||
if (player.getHP() <= 0) {
|
|
||||||
exitValue = 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
|
|
||||||
delayForASecond();
|
|
||||||
if (userAttacks == false) {
|
|
||||||
userAttacks = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns());
|
|
||||||
|
|
||||||
String response = userInput.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("r")) {
|
|
||||||
if (runFromShips() == false) {
|
|
||||||
System.out.println("Couldn't run away");
|
|
||||||
} else {
|
|
||||||
exitValue = 3;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (exitValue == 1) {
|
|
||||||
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
|
|
||||||
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
|
|
||||||
player.setMoney(player.getMoney() + calculateLoot);
|
|
||||||
System.out.printf("We got $%,d!", calculateLoot);
|
|
||||||
return true;
|
|
||||||
} else if (exitValue == 2) {
|
|
||||||
player.gameOver();
|
|
||||||
return true;
|
|
||||||
} else if (exitValue == 3) {
|
|
||||||
System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
498
src/ShipWarfareGUI.java
Normal file
498
src/ShipWarfareGUI.java
Normal file
@@ -0,0 +1,498 @@
|
|||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class ShipWarfareGUI {
|
||||||
|
|
||||||
|
|
||||||
|
private Player player = new Player();
|
||||||
|
private HBox hBox;
|
||||||
|
private Button fightButton;
|
||||||
|
private Button runButton;
|
||||||
|
private VBox vBox;
|
||||||
|
private Label title;
|
||||||
|
private Label chooseFightOrRun;
|
||||||
|
private Label report;
|
||||||
|
private Label runAwayOrLeft;
|
||||||
|
private Label shipsRemaining;
|
||||||
|
private Label HPLeft;
|
||||||
|
private Label gunsLeftOrTaken;
|
||||||
|
private Label continueToFight;
|
||||||
|
private int counter1;
|
||||||
|
private Button continueButton;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ShipWarfareGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int numOfPeasantShips = 0;
|
||||||
|
private int numOfLittyShips = 0;
|
||||||
|
private boolean userAttacks = true;
|
||||||
|
private int startingPeasantShips = 0;
|
||||||
|
private int startingLittyShips = 0;
|
||||||
|
private int howMuchRun = 0;
|
||||||
|
private int counter = 0;
|
||||||
|
private String pirateName = "Liu Yen";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method for player
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public void setPlayer(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter method for obtaining a player object.
|
||||||
|
*
|
||||||
|
* @return returns player object
|
||||||
|
*/
|
||||||
|
public Player getPlayer() {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
return playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method that takes in an integer as an argument
|
||||||
|
*
|
||||||
|
* @param numOfPeasantShips the number of ships to be used in the peasant fleet attack
|
||||||
|
*/
|
||||||
|
public void setNumOfPeasantShips(int numOfPeasantShips) {
|
||||||
|
counter1++;
|
||||||
|
this.numOfPeasantShips = numOfPeasantShips;
|
||||||
|
if (counter1 == 1) {
|
||||||
|
startingPeasantShips = numOfPeasantShips;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of ships that attack is based on the amount of money one has on hand
|
||||||
|
*
|
||||||
|
* @return the number of ships which will attack
|
||||||
|
*/
|
||||||
|
public int numOfShips() {
|
||||||
|
|
||||||
|
int numOfShipsAttacking = 0;
|
||||||
|
Random randomValue = new Random();
|
||||||
|
|
||||||
|
if (player.getMoney() <= 100000) {
|
||||||
|
//Minimum one ship will attack, maximum 20
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(20) + 1;
|
||||||
|
} else if (player.getMoney() <= 200000) {
|
||||||
|
//Minimum 30 Ships will attack, maximum 70
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(40) + 31;
|
||||||
|
} else if (player.getMoney() <= 500000) {
|
||||||
|
//Minimum 50 ships will attack, maximum 140
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(90) + 51;
|
||||||
|
} else if (player.getMoney() >= 1000000) {
|
||||||
|
//Minimum 100 ships will attack, maximum 300 ships
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(200) + 101;
|
||||||
|
}
|
||||||
|
|
||||||
|
return numOfShipsAttacking;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One in two chance of running away
|
||||||
|
*
|
||||||
|
* @return true if the user is allowed to run, false if not, the "default" is false
|
||||||
|
*/
|
||||||
|
public boolean runFromShips() {
|
||||||
|
userAttacks = false;
|
||||||
|
Random randomValue = new Random();
|
||||||
|
int runSuccessChance = randomValue.nextInt(10) + 1;
|
||||||
|
if (runSuccessChance == 2) {
|
||||||
|
return true;
|
||||||
|
} else if (runSuccessChance == 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets most of the labels invisible except for the "fight or run" label
|
||||||
|
*/
|
||||||
|
public void wipe() {
|
||||||
|
title.setVisible(false);
|
||||||
|
runAwayOrLeft.setVisible(false);
|
||||||
|
shipsRemaining.setVisible(false);
|
||||||
|
HPLeft.setVisible(false);
|
||||||
|
gunsLeftOrTaken.setVisible(false);
|
||||||
|
continueToFight.setVisible(false);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets most of the labels invisible including the fight or run label
|
||||||
|
*/
|
||||||
|
public void completeWipe() {
|
||||||
|
title.setVisible(false);
|
||||||
|
chooseFightOrRun.setVisible(false);
|
||||||
|
runAwayOrLeft.setVisible(false);
|
||||||
|
shipsRemaining.setVisible(false);
|
||||||
|
HPLeft.setVisible(false);
|
||||||
|
gunsLeftOrTaken.setVisible(false);
|
||||||
|
continueToFight.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user faces off against the peasant ships and either prevails, dies, or runs away
|
||||||
|
*
|
||||||
|
* @return true if the user wins, loses, or flees, it returns false otherwise
|
||||||
|
* @throws Exception in case of errors due to the delay
|
||||||
|
*/
|
||||||
|
public boolean destroyPeasantShipsOrEscape(Stage stage) throws Exception {
|
||||||
|
int calculateLoot = 0;
|
||||||
|
int chanceOfEnemyRun = 0;
|
||||||
|
int hitCounter = 0;
|
||||||
|
int missCounter = 0;
|
||||||
|
boolean gunFrustration = false;
|
||||||
|
|
||||||
|
title.setVisible(true);
|
||||||
|
chooseFightOrRun.setVisible(true);
|
||||||
|
report.setVisible(true);
|
||||||
|
runAwayOrLeft.setVisible(true);
|
||||||
|
shipsRemaining.setVisible(true);
|
||||||
|
HPLeft.setVisible(true);
|
||||||
|
gunsLeftOrTaken.setVisible(true);
|
||||||
|
continueToFight.setVisible(true);
|
||||||
|
continueButton.setVisible(false);
|
||||||
|
|
||||||
|
|
||||||
|
runAwayOrLeft.setText("No ships ran away");
|
||||||
|
|
||||||
|
Random randomValue = new Random();
|
||||||
|
int exitValue = 0;
|
||||||
|
|
||||||
|
//Player volley
|
||||||
|
//while (exitValue == 0) {
|
||||||
|
if (player.getGuns() > 0) {
|
||||||
|
|
||||||
|
for (int j = 0; j < player.getGuns(); j++) {
|
||||||
|
if (userAttacks == true) {
|
||||||
|
int hitOrMiss = randomValue.nextInt(2) + 1;
|
||||||
|
if (hitOrMiss == 2) {
|
||||||
|
numOfPeasantShips--;
|
||||||
|
if (numOfPeasantShips <= 0) {
|
||||||
|
exitValue = 1;
|
||||||
|
//break;
|
||||||
|
}
|
||||||
|
hitCounter++;
|
||||||
|
} else {
|
||||||
|
missCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (userAttacks == true) {
|
||||||
|
report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
report.setText("We don't have any guns!!!");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (numOfPeasantShips <= 0) {
|
||||||
|
exitValue = 1;
|
||||||
|
//break;
|
||||||
|
}
|
||||||
|
if (player.getGuns() > 0) {
|
||||||
|
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
||||||
|
if (chanceOfEnemyRun == 2) {
|
||||||
|
howMuchRun = randomValue.nextInt(15) + 1;
|
||||||
|
if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) {
|
||||||
|
|
||||||
|
|
||||||
|
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
|
||||||
|
if (userAttacks == true) {
|
||||||
|
if (howMuchRun > 0) {
|
||||||
|
runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, player.getName()));
|
||||||
|
//runAwayOrLeft.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
report.setText((String.format("Escaped %d of them %s!", howMuchRun, player.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shipsRemaining.setText(String.format("%d ships remaining and they look angry!", numOfPeasantShips));
|
||||||
|
//Computer volley
|
||||||
|
int takeGunChance = randomValue.nextInt(4) + 1;
|
||||||
|
if (takeGunChance == 1 && player.getGuns() > 0) {
|
||||||
|
player.setGuns(player.getGuns() - 1);
|
||||||
|
gunFrustration = true;
|
||||||
|
} else {
|
||||||
|
if (numOfPeasantShips > 0) {
|
||||||
|
player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (player.getHP() <= 0) {
|
||||||
|
exitValue = 2;
|
||||||
|
//break;
|
||||||
|
}
|
||||||
|
if (gunFrustration == true) {
|
||||||
|
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", player.getGuns()));
|
||||||
|
} else {
|
||||||
|
gunsLeftOrTaken.setText(String.format("We still have %d guns left", player.getGuns()));
|
||||||
|
}
|
||||||
|
|
||||||
|
HPLeft.setText(String.format("EEK, our current ship status is %d%% ", player.getHP()));
|
||||||
|
if (userAttacks == false) {
|
||||||
|
userAttacks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
continueToFight.setText(String.format("Captain, what are your orders? (Click the fight button or the run button)", player.getGuns()));
|
||||||
|
|
||||||
|
if (exitValue == 1) {
|
||||||
|
wipe();
|
||||||
|
chooseFightOrRun.setText(String.format("Ayy! We won and survived at %d%% ship status!", player.getHP()));
|
||||||
|
calculateLoot = (startingPeasantShips * 100) + randomValue.nextInt(startingPeasantShips) * 200;
|
||||||
|
player.setMoney(player.getMoney() + calculateLoot);
|
||||||
|
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
|
||||||
|
continueButton.setVisible(true);
|
||||||
|
return true;
|
||||||
|
} else if (exitValue == 2) {
|
||||||
|
GameEndGUI gameEndGUI = new GameEndGUI(player);
|
||||||
|
gameEndGUI.initializeGameEndGUI(stage);
|
||||||
|
stage.show();
|
||||||
|
return true;
|
||||||
|
} else if (exitValue == 3) {
|
||||||
|
System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
|
||||||
|
continueButton.setVisible(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the graphical part of ShipWarfare and includes all logic for the class
|
||||||
|
*
|
||||||
|
* @param stage sets the stage to which we will execute the scene of the ShipWarfare class
|
||||||
|
* @return stage so that another class can switch to the stage
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Stage initializeShip(Stage stage) {
|
||||||
|
setNumOfPeasantShips(numOfShips());
|
||||||
|
|
||||||
|
BorderPane BorderPane = new BorderPane();
|
||||||
|
|
||||||
|
GridPane gridPane = new GridPane();
|
||||||
|
gridPane.setPadding(new Insets(10.0, 10.0, 10.0, 10.0));
|
||||||
|
gridPane.setVgap(5.0);
|
||||||
|
|
||||||
|
hBox = new HBox();
|
||||||
|
fightButton = new Button();
|
||||||
|
runButton = new Button();
|
||||||
|
vBox = new VBox();
|
||||||
|
title = new Label();
|
||||||
|
chooseFightOrRun = new Label();
|
||||||
|
report = new Label();
|
||||||
|
runAwayOrLeft = new Label();
|
||||||
|
shipsRemaining = new Label();
|
||||||
|
HPLeft = new Label();
|
||||||
|
gunsLeftOrTaken = new Label();
|
||||||
|
continueToFight = new Label();
|
||||||
|
continueButton = new Button();
|
||||||
|
|
||||||
|
continueButton.setVisible(false);
|
||||||
|
|
||||||
|
|
||||||
|
BorderPane.setPrefHeight(400.0);
|
||||||
|
BorderPane.setPrefWidth(600.0);
|
||||||
|
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setPrefHeight(100.0);
|
||||||
|
hBox.setPrefWidth(200.0);
|
||||||
|
hBox.setSpacing(10.0);
|
||||||
|
|
||||||
|
title.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
||||||
|
title.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
title.setId("Label1");
|
||||||
|
title.setText(String.format("%d ships attacking. Would you like to Fight or Run?", numOfPeasantShips));
|
||||||
|
title.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
|
||||||
|
|
||||||
|
continueButton.setMnemonicParsing(false);
|
||||||
|
continueButton.setText("Continue?");
|
||||||
|
|
||||||
|
fightButton.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
fightButton.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
fightButton.setId("Button1");
|
||||||
|
fightButton.setMnemonicParsing(false);
|
||||||
|
fightButton.setText("Fight");
|
||||||
|
|
||||||
|
runButton.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
runButton.setId("Button2");
|
||||||
|
runButton.setMnemonicParsing(false);
|
||||||
|
|
||||||
|
BorderPane.setBottom(hBox);
|
||||||
|
runButton.setText("Run");
|
||||||
|
|
||||||
|
javafx.scene.layout.BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
|
||||||
|
vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
||||||
|
vBox.setPrefHeight(200.0);
|
||||||
|
vBox.setPrefWidth(100.0);
|
||||||
|
vBox.setSpacing(20.0);
|
||||||
|
|
||||||
|
report.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
||||||
|
report.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
report.setId("Label1");
|
||||||
|
report.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
|
||||||
|
vBox.setPadding(new Insets(0.0, 0.0, 10.0, 0.0));
|
||||||
|
BorderPane.setTop(vBox);
|
||||||
|
BorderPane.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
|
||||||
|
|
||||||
|
hBox.getChildren().add(fightButton);
|
||||||
|
hBox.getChildren().add(runButton);
|
||||||
|
vBox.getChildren().add(title);
|
||||||
|
vBox.getChildren().add(chooseFightOrRun);
|
||||||
|
vBox.getChildren().add(report);
|
||||||
|
vBox.getChildren().add(runAwayOrLeft);
|
||||||
|
vBox.getChildren().add(shipsRemaining);
|
||||||
|
vBox.getChildren().add(HPLeft);
|
||||||
|
vBox.getChildren().add(gunsLeftOrTaken);
|
||||||
|
vBox.getChildren().add(continueToFight);
|
||||||
|
vBox.getChildren().add(continueButton);
|
||||||
|
|
||||||
|
|
||||||
|
//Fight
|
||||||
|
fightButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
/**
|
||||||
|
* Fight Button, engages in fight logic and graphical interface
|
||||||
|
* @param event, once button is clicked, executes graphical information
|
||||||
|
*/
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
counter++;
|
||||||
|
chooseFightOrRun.setText("Ohh, Fight ehh?");
|
||||||
|
try {
|
||||||
|
if (destroyPeasantShipsOrEscape(stage)) {
|
||||||
|
completeWipe();
|
||||||
|
continueButton.setVisible(true);
|
||||||
|
fightButton.setVisible(false);
|
||||||
|
runButton.setVisible(false);
|
||||||
|
continueButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
/**
|
||||||
|
* Switches to Taipan Shop scene
|
||||||
|
* @param event, once button is clicked, executes graphical information
|
||||||
|
*/
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||||
|
shop.initializeShop(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter >= 2) {
|
||||||
|
title.setVisible(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Flee
|
||||||
|
runButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
/**
|
||||||
|
* Run Button, engages in run logic and graphical interface
|
||||||
|
* @param event, once button is clicked, executes graphical information
|
||||||
|
*/
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
chooseFightOrRun.setText("Ayy captain we will try to run!");
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
if (runFromShips() == false) {
|
||||||
|
title.setVisible(false);
|
||||||
|
chooseFightOrRun.setVisible(false);
|
||||||
|
report.setText(("Couldn't run away"));
|
||||||
|
try {
|
||||||
|
if (destroyPeasantShipsOrEscape(stage) == true) {
|
||||||
|
completeWipe();
|
||||||
|
continueButton.setVisible(true);
|
||||||
|
fightButton.setVisible(false);
|
||||||
|
runButton.setVisible(false);
|
||||||
|
continueButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
/**
|
||||||
|
* Switches to Taipan Shop scene
|
||||||
|
* @param event, once button is clicked, executes graphical information
|
||||||
|
*/
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||||
|
shop.initializeShop(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
completeWipe();
|
||||||
|
report.setText("Phew! Got away safely");
|
||||||
|
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||||
|
shop.initializeShop(stage);
|
||||||
|
stage.show();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (counter >= 2) {
|
||||||
|
title.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Scene root = new Scene(BorderPane, 600, 480);
|
||||||
|
|
||||||
|
stage.setTitle("Ship");
|
||||||
|
stage.setResizable(false);
|
||||||
|
stage.setScene(root);
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets scene and runs stage
|
||||||
|
*
|
||||||
|
* @param primaryStage the stage in which the scene may be run and switched to
|
||||||
|
*/
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
primaryStage = initializeShip(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
public class Start
|
|
||||||
{
|
|
||||||
private Player player;
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
Player playerTemp = new Player(player);
|
|
||||||
return playerTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayer(Player player) {
|
|
||||||
Player playerTemp = new Player(player);
|
|
||||||
this.player = playerTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirm (String name) {
|
|
||||||
if (name.length() <= 22) {
|
|
||||||
player.setName(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void intialize()
|
|
||||||
{
|
|
||||||
Scanner userInput = new Scanner(System.in);
|
|
||||||
System.out.println("Taipan, \nWhat will you name your firm:");
|
|
||||||
setFirm(userInput.nextLine());
|
|
||||||
System.out.println("Do you want to start . . .\n\t1) With cash (and a debt)\n\t\t\t>> or <<\n\t" +
|
|
||||||
"2) With five guns and no cash (But no debt!)?\n ");
|
|
||||||
int input = userInput.nextInt();
|
|
||||||
if (input == 1)
|
|
||||||
{
|
|
||||||
player.setMoney(400);
|
|
||||||
player.setDebt(5000);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (input == 2)
|
|
||||||
{
|
|
||||||
player.setGuns(5);
|
|
||||||
}
|
|
||||||
// purely for testing purposes.
|
|
||||||
if(player.getName().equalsIgnoreCase("Vikram")){
|
|
||||||
player.setMoney(999999999);
|
|
||||||
player.setBank(999999999);
|
|
||||||
player.setGuns(999);
|
|
||||||
player.setHP(99999999);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Start(Player player)
|
|
||||||
{
|
|
||||||
Player playerTemp = new Player(player);
|
|
||||||
this.player = playerTemp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
227
src/StartGUI.java
Normal file
227
src/StartGUI.java
Normal file
@@ -0,0 +1,227 @@
|
|||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class StartGUI {
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
private BorderPane borderPane = new BorderPane();
|
||||||
|
private HBox hBox = new HBox();
|
||||||
|
private TextField nameField = new TextField();
|
||||||
|
private Button startButton = new Button();
|
||||||
|
private VBox vBox = new VBox();
|
||||||
|
private Label choiceLabel = new Label();
|
||||||
|
private RadioButton gunChoice = new RadioButton();
|
||||||
|
private ToggleGroup Start = new ToggleGroup();
|
||||||
|
private RadioButton cashChoice = new RadioButton();
|
||||||
|
private VBox vBox0 = new VBox();
|
||||||
|
private Label title = new Label();
|
||||||
|
private Label authors = new Label();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
|
||||||
|
*
|
||||||
|
* @return playerDummy -- playerDummy is a copy of the player instance variable.
|
||||||
|
*/
|
||||||
|
public Player getPlayer() {
|
||||||
|
Player playerTemp = new Player(player);
|
||||||
|
return playerTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will replace the current instance of the player instance variable.
|
||||||
|
*/
|
||||||
|
public void setPlayer(Player player) {
|
||||||
|
Player playerTemp = new Player(player);
|
||||||
|
this.player = playerTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks the user to input the name that they would like to be called in the game
|
||||||
|
*
|
||||||
|
* @param name the name that you would like to be called in the game
|
||||||
|
*/
|
||||||
|
public void setFirm(String name) {
|
||||||
|
if (name.length() <= 22) {
|
||||||
|
player.setName(name);
|
||||||
|
} else {
|
||||||
|
player.setName("Taipan");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**
|
||||||
|
* Copy constructor.
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public StartGUI(Player player) {
|
||||||
|
Player playerTemp = new Player(player);
|
||||||
|
this.player = playerTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the Start GUI the game.
|
||||||
|
*
|
||||||
|
* @param stage object of type Stage
|
||||||
|
* @return returns the stage of GUI
|
||||||
|
*/
|
||||||
|
public Stage initializeStart(Stage stage) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an HBox at the center of the borderpane with a width of 200, height of 100 and spacing of 10.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setPrefHeight(100.0);
|
||||||
|
hBox.setPrefWidth(200.0);
|
||||||
|
hBox.setSpacing(10.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a borderpane window of width 600 and height 480.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
borderPane.setPrefHeight(480.0);
|
||||||
|
borderPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a prompt text field that asks for your firm name and has a default text set to "Taipan".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
nameField.setPromptText("Enter Firm Name.");
|
||||||
|
nameField.setText("Taipan");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a button with text "Start"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
startButton.setMnemonicParsing(false);
|
||||||
|
startButton.setText("Start");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a VBox at the left of center of the borderpane.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
vBox.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Do you want to start with..." to indicate the user has to choose between 2 given scenarios.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
choiceLabel.setText("Do you want to start with...");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label for scenario one which is you start with five guns and no cash or debt.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gunChoice.setMnemonicParsing(false);
|
||||||
|
gunChoice.setSelected(true);
|
||||||
|
gunChoice.setText("Five guns and no cash (But no debt!)?");
|
||||||
|
|
||||||
|
gunChoice.setToggleGroup(Start);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label for scenario 2 which is you start with cash but also a debt.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
cashChoice.setAlignment(javafx.geometry.Pos.TOP_LEFT);
|
||||||
|
cashChoice.setMnemonicParsing(false);
|
||||||
|
cashChoice.setText("Cash (and a debt)");
|
||||||
|
cashChoice.setToggleGroup(Start);
|
||||||
|
borderPane.setBottom(hBox);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a VBox at the center of the borderpane with a width of 100 and height of 200.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BorderPane.setAlignment(vBox0, javafx.geometry.Pos.CENTER);
|
||||||
|
vBox0.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
vBox0.setPrefHeight(200.0);
|
||||||
|
vBox0.setPrefWidth(100.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Taipan" in size 66 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
title.setText("Taipan");
|
||||||
|
title.setFont(new Font(66.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with our names as text
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
authors.setPrefHeight(80.0);
|
||||||
|
authors.setPrefWidth(499.0);
|
||||||
|
authors.setText("By Vikram Bawa, Haris Muhammad, Siddhant Dewani, Nathan Lum and Harkamal Randhawa");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts Vbox0 in the center of the borderpane.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
authors.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
borderPane.setCenter(vBox0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds all the buttons and labels to their respective boxes.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
hBox.getChildren().add(nameField);
|
||||||
|
hBox.getChildren().add(startButton);
|
||||||
|
vBox.getChildren().add(choiceLabel);
|
||||||
|
vBox.getChildren().add(gunChoice);
|
||||||
|
vBox.getChildren().add(cashChoice);
|
||||||
|
hBox.getChildren().add(vBox);
|
||||||
|
vBox0.getChildren().add(title);
|
||||||
|
vBox0.getChildren().add(authors);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds function to the "Start" button, scenario 1 gives the player $400 and a $5000 debt at the start of the game;
|
||||||
|
* scenario 2 gives the player 5 guns.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
startButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
if (Start.getSelectedToggle() == cashChoice) {
|
||||||
|
player.setMoney(400);
|
||||||
|
player.setDebt(5000);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (Start.getSelectedToggle() == gunChoice) {
|
||||||
|
player.setGuns(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
String response = nameField.getText();
|
||||||
|
// purely for testing purposes.
|
||||||
|
if (response.equalsIgnoreCase("Vikram")) {
|
||||||
|
player.setMoney(999999999);
|
||||||
|
player.setBank(999999999);
|
||||||
|
player.setGuns(0);
|
||||||
|
player.setHP(99999999);
|
||||||
|
player.setCargoSpace(Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
setFirm(response);
|
||||||
|
|
||||||
|
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||||
|
shop.initializeShop(stage);
|
||||||
|
stage.show();
|
||||||
|
//title.setText("SHOP PLACEHOLDER");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
|
|
||||||
|
stage.setTitle("Start");
|
||||||
|
stage.setResizable(false);
|
||||||
|
stage.setScene(root);
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,619 +0,0 @@
|
|||||||
import java.util.Random;
|
|
||||||
import java.util.Scanner;
|
|
||||||
public class TaipanShop {
|
|
||||||
|
|
||||||
private Player player;
|
|
||||||
private int cargoSpace = 60;
|
|
||||||
private int currentCargo = 0;
|
|
||||||
private int opiumPrice = 16000;
|
|
||||||
private int silkPrice = 1600;
|
|
||||||
private int armsPrice = 160;
|
|
||||||
private int generalPrice = 8;
|
|
||||||
|
|
||||||
public void retire(){
|
|
||||||
player.setRetire(true);
|
|
||||||
System.out.println("You win!");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayer(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer(){
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
return playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TaipanShop(Player player){
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCargoSpace() {
|
|
||||||
return cargoSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCargoSpace(int cargoSpace) {
|
|
||||||
if(cargoSpace > 0){
|
|
||||||
this.cargoSpace = cargoSpace;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOpiumPrice() {
|
|
||||||
return opiumPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOpiumPrice(int opiumPrice) {
|
|
||||||
if(opiumPrice > 0){
|
|
||||||
this.opiumPrice = opiumPrice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSilkPrice() {
|
|
||||||
return silkPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSilkPrice(int silkPrice) {
|
|
||||||
if(silkPrice > 0){
|
|
||||||
this.silkPrice = silkPrice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getArmsPrice() {
|
|
||||||
return armsPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArmsPrice(int armsPrice) {
|
|
||||||
if(armsPrice > 0){
|
|
||||||
this.armsPrice = armsPrice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getGeneralPrice() {
|
|
||||||
return generalPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGeneralPrice(int generalPrice) {
|
|
||||||
if(generalPrice > 0){
|
|
||||||
this.generalPrice = generalPrice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void travel(){
|
|
||||||
Travel travel = new Travel(player);
|
|
||||||
travel.travelTo();
|
|
||||||
player = travel.getPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void warehouse(){
|
|
||||||
Warehouse warehouse = new Warehouse(player);
|
|
||||||
warehouse.changeWarehouse();
|
|
||||||
player = warehouse.getPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void bank(){
|
|
||||||
Bank bank = new Bank(player);
|
|
||||||
bank.bank();
|
|
||||||
player = bank.getPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loan(){
|
|
||||||
loanShark loan = new loanShark(player);
|
|
||||||
loan.loanMoney();
|
|
||||||
player = loan.getPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updatePrices(){
|
|
||||||
String s = "\n" + player.getName() + ", the price of ";
|
|
||||||
double value = 80*Math.random();
|
|
||||||
Random rand = new Random();
|
|
||||||
opiumPrice = (rand.nextInt(201) + 60)*100;
|
|
||||||
silkPrice = (rand.nextInt(201) + 60)*10;
|
|
||||||
armsPrice = (rand.nextInt(21) + 6)*10;
|
|
||||||
generalPrice = rand.nextInt(17) + 4;
|
|
||||||
if(value < 8){
|
|
||||||
if(value < 2){
|
|
||||||
if(value < 1){
|
|
||||||
opiumPrice /= 5;
|
|
||||||
System.out.println(s + "Opium has dropped to " + opiumPrice +"!!!\n");
|
|
||||||
}else{
|
|
||||||
opiumPrice *= 5;
|
|
||||||
System.out.println(s + "Opium has risen to " + opiumPrice +"!!!\n");
|
|
||||||
}
|
|
||||||
}else if(value < 4){
|
|
||||||
if(value < 3){
|
|
||||||
silkPrice /= 5;
|
|
||||||
System.out.println(s + "Silk has dropped to " + silkPrice +"!!!\n");
|
|
||||||
}else{
|
|
||||||
silkPrice *= 5;
|
|
||||||
System.out.println(s + "Silk has risen to " + silkPrice +"!!!\n");
|
|
||||||
}
|
|
||||||
}else if(value < 6){
|
|
||||||
if(value < 3){
|
|
||||||
armsPrice /= 5;
|
|
||||||
System.out.println(s + "Arms has dropped to " + armsPrice +"!!!\n");
|
|
||||||
}else{
|
|
||||||
armsPrice *= 5;
|
|
||||||
System.out.println(s + "Arms has risen to " + armsPrice +"!!!\n");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(value < 7){
|
|
||||||
generalPrice = 1;
|
|
||||||
System.out.println(s + "General Cargo has dropped to 1!!!\n");
|
|
||||||
}else{
|
|
||||||
generalPrice *= 5;
|
|
||||||
System.out.println(s + "General Cargo has risen to " + generalPrice + "!!!\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printShop(){
|
|
||||||
currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld();
|
|
||||||
if(cargoSpace - currentCargo < 0){
|
|
||||||
System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%");
|
|
||||||
}else{
|
|
||||||
System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%");
|
|
||||||
}
|
|
||||||
System.out.println("-------------------------------------------------------------");
|
|
||||||
System.out.println(" Opium: " + player.getOpiumHeld() + " Silk: " + player.getSilkHeld());
|
|
||||||
System.out.println(" Arms: " + player.getArmsHeld() + " General: " + player.getGeneralHeld());
|
|
||||||
System.out.println("-------------------------------------------------------------");
|
|
||||||
System.out.println("Cash: " + player.getMoney() + " Bank: " + player.getBank()+ " Debt: " + player.getDebt()+"\n");
|
|
||||||
System.out.println(player.getName() + ", present prices per unit here are:");
|
|
||||||
System.out.println(" Opium: " + opiumPrice + " Silk: " + silkPrice);
|
|
||||||
System.out.println(" Arms: " + armsPrice + " General: " + generalPrice);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void atLocationOne(boolean notDone, Scanner input){
|
|
||||||
while(notDone){
|
|
||||||
printShop();
|
|
||||||
System.out.println("\nShall I Buy, Sell, Visit Bank, Get Loans, Transfer Cargo, or Quit Trading?");
|
|
||||||
String response = input.next();
|
|
||||||
if (response.equalsIgnoreCase("B")) {
|
|
||||||
boolean notDone2 = true;
|
|
||||||
System.out.println("What do you wish me to buy, " + player.getName() + "?");
|
|
||||||
while (notDone2) {
|
|
||||||
response = input.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("O")) {
|
|
||||||
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / opiumPrice && num >= 0) {
|
|
||||||
player.setOpiumHeld(player.getOpiumHeld()+num);
|
|
||||||
player.setMoney(player.getMoney()-num * opiumPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / silkPrice && num >= 0) {
|
|
||||||
player.setSilkHeld(player.getSilkHeld()+num);
|
|
||||||
player.setMoney(player.getMoney()-num * silkPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("A")) {
|
|
||||||
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / armsPrice && num >= 0) {
|
|
||||||
player.setArmsHeld(player.getArmsHeld()+num);
|
|
||||||
player.setMoney(player.getMoney() - num*armsPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("G")) {
|
|
||||||
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / generalPrice && num >= 0) {
|
|
||||||
player.setGeneralHeld(player.getGeneralHeld()+num);
|
|
||||||
player.setMoney(player.getMoney() - num*generalPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
boolean notDone2 = true;
|
|
||||||
System.out.println("What do you wish me to sell, " + player.getName() + "?");
|
|
||||||
while (notDone2) {
|
|
||||||
response = input.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("O")) {
|
|
||||||
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getOpiumHeld() && num >= 0) {
|
|
||||||
player.setOpiumHeld(player.getOpiumHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*opiumPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getSilkHeld() && num >= 0) {
|
|
||||||
player.setSilkHeld(player.getSilkHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*silkPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("A")) {
|
|
||||||
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getArmsHeld() && num >= 0) {
|
|
||||||
player.setArmsHeld(player.getArmsHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*armsPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("G")) {
|
|
||||||
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getGeneralHeld() && num >= 0) {
|
|
||||||
player.setGeneralHeld(player.getGeneralHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*generalPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("V")) {
|
|
||||||
bank();
|
|
||||||
} else if (response.equalsIgnoreCase("T")) {
|
|
||||||
warehouse();
|
|
||||||
}else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) {
|
|
||||||
loan();
|
|
||||||
}else if (response.equalsIgnoreCase("Q")) {
|
|
||||||
travel();
|
|
||||||
notDone = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notAtLocationOne(boolean notDone, Scanner input){
|
|
||||||
while(notDone){
|
|
||||||
printShop();
|
|
||||||
System.out.println("\nShall I Buy, Sell, or Quit Trading?");
|
|
||||||
String response = input.next();
|
|
||||||
if (response.equalsIgnoreCase("B")) {
|
|
||||||
boolean notDone2 = true;
|
|
||||||
System.out.println("What do you wish me to buy, " + player.getName() + "?");
|
|
||||||
while (notDone2) {
|
|
||||||
response = input.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("O")) {
|
|
||||||
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / opiumPrice && num >= 0) {
|
|
||||||
player.setOpiumHeld(player.getOpiumHeld()+num);
|
|
||||||
player.setMoney(player.getMoney() - num*opiumPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / silkPrice && num >= 0) {
|
|
||||||
player.setSilkHeld(player.getSilkHeld()+num);
|
|
||||||
player.setMoney(player.getMoney() - num*silkPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("A")) {
|
|
||||||
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / armsPrice && num >= 0) {
|
|
||||||
player.setArmsHeld(player.getArmsHeld()+num);
|
|
||||||
player.setMoney(player.getMoney() - num*armsPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("G")) {
|
|
||||||
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / generalPrice && num >= 0) {
|
|
||||||
player.setGeneralHeld(player.getGeneralHeld()+num);
|
|
||||||
player.setMoney(player.getMoney() - num*generalPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
boolean notDone2 = true;
|
|
||||||
System.out.println("What do you wish me to sell, " + player.getName() + "?");
|
|
||||||
while (notDone2) {
|
|
||||||
response = input.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("O")) {
|
|
||||||
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getOpiumHeld() && num >= 0) {
|
|
||||||
player.setOpiumHeld(player.getOpiumHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*opiumPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getSilkHeld() && num >= 0) {
|
|
||||||
player.setSilkHeld(player.getSilkHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*silkPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("A")) {
|
|
||||||
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getArmsHeld() && num >= 0) {
|
|
||||||
player.setArmsHeld(player.getArmsHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*armsPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("G")) {
|
|
||||||
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getGeneralHeld() && num >= 0) {
|
|
||||||
player.setGeneralHeld(player.getGeneralHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*generalPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("Q")) {
|
|
||||||
travel();
|
|
||||||
notDone = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void retireAndLocationOne(boolean notDone, Scanner input){
|
|
||||||
while(notDone){
|
|
||||||
printShop();
|
|
||||||
System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, Get Loans, Retire, or Quit Trading?");
|
|
||||||
String response = input.next();
|
|
||||||
if (response.equalsIgnoreCase("B")) {
|
|
||||||
boolean notDone2 = true;
|
|
||||||
System.out.println("What do you wish me to buy, " + player.getName() + "?");
|
|
||||||
while (notDone2) {
|
|
||||||
response = input.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("O")) {
|
|
||||||
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / opiumPrice && num >= 0) {
|
|
||||||
player.setOpiumHeld(player.getOpiumHeld()+num);
|
|
||||||
player.setMoney(player.getMoney()-num * opiumPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / silkPrice && num >= 0) {
|
|
||||||
player.setSilkHeld(player.getSilkHeld()+num);
|
|
||||||
player.setMoney(player.getMoney()-num * silkPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("A")) {
|
|
||||||
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / armsPrice && num >= 0) {
|
|
||||||
player.setArmsHeld(player.getArmsHeld()+num);
|
|
||||||
player.setMoney(player.getMoney() - num*armsPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("G")) {
|
|
||||||
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getMoney() / generalPrice && num >= 0) {
|
|
||||||
player.setGeneralHeld(player.getGeneralHeld()+num);
|
|
||||||
player.setMoney(player.getMoney() - num*generalPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you can't afford that!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
boolean notDone2 = true;
|
|
||||||
System.out.println("What do you wish me to sell, " + player.getName() + "?");
|
|
||||||
while (notDone2) {
|
|
||||||
response = input.nextLine();
|
|
||||||
if (response.equalsIgnoreCase("O")) {
|
|
||||||
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getOpiumHeld() && num >= 0) {
|
|
||||||
player.setOpiumHeld(player.getOpiumHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*opiumPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("S")) {
|
|
||||||
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getSilkHeld() && num >= 0) {
|
|
||||||
player.setSilkHeld(player.getSilkHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*silkPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("A")) {
|
|
||||||
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getArmsHeld() && num >= 0) {
|
|
||||||
player.setArmsHeld(player.getArmsHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*armsPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (response.equalsIgnoreCase("G")) {
|
|
||||||
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
|
|
||||||
while (notDone2) {
|
|
||||||
int num = input.nextInt();
|
|
||||||
if (num <= player.getGeneralHeld() && num >= 0) {
|
|
||||||
player.setGeneralHeld(player.getGeneralHeld()-num);
|
|
||||||
player.setMoney(player.getMoney() + num*generalPrice);
|
|
||||||
notDone2 = false;
|
|
||||||
} else if (num >= 0) {
|
|
||||||
System.out.println(player.getName() + ", you don't have that many to sell!");
|
|
||||||
} else {
|
|
||||||
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (response.equalsIgnoreCase("V")) {
|
|
||||||
bank();
|
|
||||||
} else if (response.equalsIgnoreCase("T")) {
|
|
||||||
warehouse();
|
|
||||||
}else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) {
|
|
||||||
loan();
|
|
||||||
}else if (response.equalsIgnoreCase("Q")) {
|
|
||||||
travel();
|
|
||||||
notDone = false;
|
|
||||||
} else if (response.equalsIgnoreCase("R")) {
|
|
||||||
retire();
|
|
||||||
notDone = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shop() {
|
|
||||||
updatePrices();
|
|
||||||
Scanner input = new Scanner(System.in);
|
|
||||||
boolean notDone = true;
|
|
||||||
if (player.getLocation() == 1 && player.getBank()+player.getMoney()-player.getDebt() < 1000000) {
|
|
||||||
atLocationOne(notDone, input);
|
|
||||||
}else if(player.getLocation() != 1) {
|
|
||||||
notAtLocationOne(notDone, input);
|
|
||||||
}else{
|
|
||||||
retireAndLocationOne(notDone, input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
898
src/TaipanShopGUI.java
Normal file
898
src/TaipanShopGUI.java
Normal file
@@ -0,0 +1,898 @@
|
|||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class TaipanShopGUI {
|
||||||
|
private Player player;
|
||||||
|
private Label firm = new Label();
|
||||||
|
private Label wItemsText = new Label();
|
||||||
|
private Label wItemSpaceText = new Label();
|
||||||
|
private Label locationText = new Label();
|
||||||
|
private Label inventoryText = new Label();
|
||||||
|
private Label inventoryHeldText = new Label();
|
||||||
|
private Label gunsText = new Label();
|
||||||
|
private Label shipStatusText = new Label();
|
||||||
|
private Label cashText = new Label();
|
||||||
|
private Label bankText = new Label();
|
||||||
|
private Label textOut = new Label();
|
||||||
|
private Button quitButton = new Button();
|
||||||
|
private Button retireButton = new Button();
|
||||||
|
private Button bankButton = new Button();
|
||||||
|
private Button sellButton = new Button();
|
||||||
|
private Button buyButton = new Button();
|
||||||
|
private Button loanButton = new Button();
|
||||||
|
private Button cargoButton = new Button();
|
||||||
|
private Button opiumButton = new Button();
|
||||||
|
private Button silkButton = new Button();
|
||||||
|
private Button armsButton = new Button();
|
||||||
|
private Button generalButton = new Button();
|
||||||
|
private TextField numberInput = new TextField();
|
||||||
|
private int opiumPrice = 16000;
|
||||||
|
private int silkPrice = 1600;
|
||||||
|
private int armsPrice = 160;
|
||||||
|
private int generalPrice = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 TaipanShopGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is evoked if the user is eligible to win, and chooses to end the game (by winning).
|
||||||
|
*/
|
||||||
|
public void retire(Stage stage) {
|
||||||
|
player.setRetire(true);
|
||||||
|
GameEndGUI gameEndGUI = new GameEndGUI(player);
|
||||||
|
gameEndGUI.initializeGameEndGUI(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will replace the current instance of the player instance variable.
|
||||||
|
*/
|
||||||
|
public void setPlayer(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes.
|
||||||
|
*
|
||||||
|
* @return playerDummy -- playerDummy is a copy of the player instance variable.
|
||||||
|
*/
|
||||||
|
public Player getPlayer() {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
return playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter for opiumPrice instance variable.
|
||||||
|
*
|
||||||
|
* @return opiumPrice -- the price of opium in the shop
|
||||||
|
*/
|
||||||
|
public int getOpiumPrice() {
|
||||||
|
return opiumPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter for the opiumPrice instance variable. Runs as long as the parameter is greater than 0.
|
||||||
|
*
|
||||||
|
* @param opiumPrice -- what the instance variable opiumPrice should be changed to.
|
||||||
|
*/
|
||||||
|
public void setOpiumPrice(int opiumPrice) {
|
||||||
|
if (opiumPrice > 0) {
|
||||||
|
this.opiumPrice = opiumPrice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter for silkPrice instance variable.
|
||||||
|
*
|
||||||
|
* @return silkPrice -- the price of silk in the shop.
|
||||||
|
*/
|
||||||
|
public int getSilkPrice() {
|
||||||
|
return silkPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter for the silkPrice instance variable. Runs as long as the parameter is greater than 0.
|
||||||
|
*
|
||||||
|
* @param silkPrice -- what the instance variable silkPrice should be changed to.
|
||||||
|
*/
|
||||||
|
public void setSilkPrice(int silkPrice) {
|
||||||
|
if (silkPrice > 0) {
|
||||||
|
this.silkPrice = silkPrice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter for armsPrice instance variable.
|
||||||
|
*
|
||||||
|
* @return armsPrice -- the price of arms in the shop.
|
||||||
|
*/
|
||||||
|
public int getArmsPrice() {
|
||||||
|
return armsPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter for the armsPrice instance variable. Runs as long as the parameter is greater than 0.
|
||||||
|
*
|
||||||
|
* @param armsPrice -- what the instance variable armsPrice should be changed to.
|
||||||
|
*/
|
||||||
|
public void setArmsPrice(int armsPrice) {
|
||||||
|
if (armsPrice > 0) {
|
||||||
|
this.armsPrice = armsPrice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter for generalPrice instance variable.
|
||||||
|
*
|
||||||
|
* @return generalPrice -- the price of general cargo in the shop.
|
||||||
|
*/
|
||||||
|
public int getGeneralPrice() {
|
||||||
|
return generalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter for the generalPrice instance variable. Runs as long as the parameter is greater than 0.
|
||||||
|
*
|
||||||
|
* @param generalPrice -- what the instance variable generalPrice should be changed to.
|
||||||
|
*/
|
||||||
|
public void setGeneralPrice(int generalPrice) {
|
||||||
|
if (generalPrice > 0) {
|
||||||
|
this.generalPrice = generalPrice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method is when the shop is accessed, randomizing the prices of all the items.
|
||||||
|
*/
|
||||||
|
public void updatePrices() {
|
||||||
|
String s = "\t" + player.getName() + ", the price of ";
|
||||||
|
double value = 80 * Math.random();
|
||||||
|
Random rand = new Random();
|
||||||
|
opiumPrice = (rand.nextInt(201) + 60) * 100;
|
||||||
|
silkPrice = (rand.nextInt(201) + 60) * 10;
|
||||||
|
armsPrice = (rand.nextInt(21) + 6) * 10;
|
||||||
|
generalPrice = rand.nextInt(17) + 4;
|
||||||
|
|
||||||
|
// there is a 10% chance that the price of an item is increased/decreased beyond its regular range.
|
||||||
|
if (value < 8) {
|
||||||
|
if (value < 2) {
|
||||||
|
if (value < 1) {
|
||||||
|
opiumPrice /= 5;
|
||||||
|
textOut.setText(s + "Opium has dropped to " + opiumPrice + "!!!\n" + textOut.getText());
|
||||||
|
} else {
|
||||||
|
opiumPrice *= 5;
|
||||||
|
textOut.setText(s + "Opium has risen to " + opiumPrice + "!!!\n" + textOut.getText());
|
||||||
|
}
|
||||||
|
} else if (value < 4) {
|
||||||
|
if (value < 3) {
|
||||||
|
silkPrice /= 5;
|
||||||
|
textOut.setText(s + "Silk has dropped to " + silkPrice + "!!!\n" + textOut.getText());
|
||||||
|
} else {
|
||||||
|
silkPrice *= 5;
|
||||||
|
textOut.setText(s + "Silk has risen to " + silkPrice + "!!!\n" + textOut.getText());
|
||||||
|
}
|
||||||
|
} else if (value < 6) {
|
||||||
|
if (value < 3) {
|
||||||
|
armsPrice /= 5;
|
||||||
|
textOut.setText(s + "Arms has dropped to " + armsPrice + "!!!\n" + textOut.getText());
|
||||||
|
} else {
|
||||||
|
armsPrice *= 5;
|
||||||
|
textOut.setText(s + "Arms has risen to " + armsPrice + "!!!\n" + textOut.getText());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (value < 7) {
|
||||||
|
generalPrice = 1;
|
||||||
|
textOut.setText(s + "General Cargo has dropped to 1!!!\n" + textOut.getText());
|
||||||
|
} else {
|
||||||
|
generalPrice *= 5;
|
||||||
|
textOut.setText(s + "General Cargo has risen to " + generalPrice + "!!!\n" + textOut.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default dialogue of simply stating the prices of the items.
|
||||||
|
*/
|
||||||
|
public void defaultTextOut() {
|
||||||
|
textOut.setText(String.format("\t%s, present prices per unit here are:\n\n\t\tOpium: %d\t\t\tSilk: %d\n\t\tArms: %d\t\t\tGeneral: %d", player.getName(), getOpiumPrice(), getSilkPrice(), getArmsPrice(), getGeneralPrice()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up buttons according to which "state" is inputted. When used in "shop", only the item buttons are visible.
|
||||||
|
* When used in "reset", all the item buttons are invisible; if the user is at location one and is eligible to win,
|
||||||
|
* then all utilities and the retire button are visible. If the user is not at location one, then the user can only
|
||||||
|
* buy, sell, or exit. If the user is at location one and is not eligible to win, then all utilities are visible but
|
||||||
|
* the retire button is not. When used in "input" everything near the bottom is invisible except for the text area.
|
||||||
|
*
|
||||||
|
* @param state -- the state determines which buttons are visible and which are not.
|
||||||
|
*/
|
||||||
|
public void buttonSetup(String state) {
|
||||||
|
if (state.equals("shop")) {
|
||||||
|
buyButton.setVisible(false);
|
||||||
|
sellButton.setVisible(false);
|
||||||
|
bankButton.setVisible(false);
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
cargoButton.setVisible(false);
|
||||||
|
loanButton.setVisible(false);
|
||||||
|
armsButton.setVisible(true);
|
||||||
|
quitButton.setVisible(false);
|
||||||
|
opiumButton.setVisible(true);
|
||||||
|
silkButton.setVisible(true);
|
||||||
|
generalButton.setVisible(true);
|
||||||
|
retireButton.setVisible(false);
|
||||||
|
} else if (state.equals("reset")) {
|
||||||
|
buyButton.setText("Buy");
|
||||||
|
sellButton.setText("Sell");
|
||||||
|
opiumButton.setText("Opium");
|
||||||
|
silkButton.setText("Silk");
|
||||||
|
armsButton.setText("Arms");
|
||||||
|
generalButton.setText("General");
|
||||||
|
if (player.getLocation() != 1) {
|
||||||
|
buyButton.setVisible(true);
|
||||||
|
sellButton.setVisible(true);
|
||||||
|
bankButton.setVisible(false);
|
||||||
|
cargoButton.setVisible(false);
|
||||||
|
loanButton.setVisible(false);
|
||||||
|
armsButton.setVisible(false);
|
||||||
|
quitButton.setVisible(true);
|
||||||
|
opiumButton.setVisible(false);
|
||||||
|
silkButton.setVisible(false);
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
generalButton.setVisible(false);
|
||||||
|
retireButton.setVisible(false);
|
||||||
|
}
|
||||||
|
if (player.getBank() + player.getMoney() - player.getDebt() < 1000000 && player.getLocation() == 1) {
|
||||||
|
buyButton.setVisible(true);
|
||||||
|
sellButton.setVisible(true);
|
||||||
|
bankButton.setVisible(true);
|
||||||
|
cargoButton.setVisible(false);
|
||||||
|
loanButton.setVisible(true);
|
||||||
|
quitButton.setVisible(true);
|
||||||
|
opiumButton.setVisible(false);
|
||||||
|
silkButton.setVisible(false);
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
generalButton.setVisible(false);
|
||||||
|
armsButton.setVisible(false);
|
||||||
|
retireButton.setVisible(false);
|
||||||
|
} else if (player.getLocation() == 1) {
|
||||||
|
buyButton.setVisible(true);
|
||||||
|
sellButton.setVisible(true);
|
||||||
|
bankButton.setVisible(true);
|
||||||
|
cargoButton.setVisible(false);
|
||||||
|
loanButton.setVisible(true);
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
quitButton.setVisible(true);
|
||||||
|
opiumButton.setVisible(false);
|
||||||
|
silkButton.setVisible(false);
|
||||||
|
generalButton.setVisible(false);
|
||||||
|
armsButton.setVisible(false);
|
||||||
|
retireButton.setVisible(true);
|
||||||
|
}
|
||||||
|
} else if (state.equals("input")) {
|
||||||
|
buyButton.setVisible(false);
|
||||||
|
sellButton.setVisible(false);
|
||||||
|
bankButton.setVisible(false);
|
||||||
|
cargoButton.setVisible(false);
|
||||||
|
loanButton.setVisible(false);
|
||||||
|
numberInput.setVisible(true);
|
||||||
|
quitButton.setVisible(false);
|
||||||
|
opiumButton.setVisible(false);
|
||||||
|
silkButton.setVisible(false);
|
||||||
|
generalButton.setVisible(false);
|
||||||
|
armsButton.setVisible(false);
|
||||||
|
retireButton.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method is responsible for the actual purchasing/selling of items, and the text associated with the act.
|
||||||
|
*/
|
||||||
|
public void shop() {
|
||||||
|
String originalDialogue = textOut.getText();
|
||||||
|
int num = Integer.parseInt(numberInput.getText().replace(" ", ""));
|
||||||
|
if (buyButton.getText().contains(".")) {
|
||||||
|
if (opiumButton.getText().contains(".") && num <= player.getMoney() / opiumPrice && num >= 0) {
|
||||||
|
player.setMoney(player.getMoney() - num * opiumPrice);
|
||||||
|
player.setOpiumHeld(player.getOpiumHeld() + num);
|
||||||
|
} else if (num >= 0 && opiumButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
|
||||||
|
} else if (opiumButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
|
||||||
|
} else if (silkButton.getText().contains(".") && num <= player.getMoney() / silkPrice && num >= 0) {
|
||||||
|
player.setSilkHeld(player.getSilkHeld() + num);
|
||||||
|
player.setMoney(player.getMoney() - num * silkPrice);
|
||||||
|
} else if (num >= 0 && silkButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
|
||||||
|
} else if (silkButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
|
||||||
|
} else if (armsButton.getText().contains(".") && num <= player.getMoney() / armsPrice && num >= 0) {
|
||||||
|
player.setArmsHeld(player.getArmsHeld() + num);
|
||||||
|
player.setMoney(player.getMoney() - num * armsPrice);
|
||||||
|
} else if (num >= 0 && armsButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
|
||||||
|
} else if (armsButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
|
||||||
|
} else if (generalButton.getText().contains(".") && num <= player.getMoney() / generalPrice && num >= 0) {
|
||||||
|
player.setArmsHeld(player.getArmsHeld() + num);
|
||||||
|
player.setMoney(player.getMoney() - num * generalPrice);
|
||||||
|
} else if (num >= 0 && generalButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you can't afford that!");
|
||||||
|
} else if (generalButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
|
||||||
|
}
|
||||||
|
} else if (sellButton.getText().contains(".")) {
|
||||||
|
if (opiumButton.getText().contains(".") && num <= player.getOpiumHeld() && num >= 0) {
|
||||||
|
player.setOpiumHeld(player.getOpiumHeld() - num);
|
||||||
|
player.setMoney(player.getMoney() + num * opiumPrice);
|
||||||
|
} else if (num >= 0 && opiumButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you don't have that many to sell!");
|
||||||
|
} else if (opiumButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
|
||||||
|
} else if (silkButton.getText().contains(".") && num <= player.getSilkHeld() && num >= 0) {
|
||||||
|
player.setSilkHeld(player.getSilkHeld() - num);
|
||||||
|
player.setMoney(player.getMoney() + num * silkPrice);
|
||||||
|
} else if (num >= 0 && silkButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you don't have that many to sell!");
|
||||||
|
} else if (silkButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
|
||||||
|
} else if (armsButton.getText().contains(".") && num <= player.getArmsHeld() && num >= 0) {
|
||||||
|
player.setArmsHeld(player.getArmsHeld() - num);
|
||||||
|
player.setMoney(player.getMoney() + num * armsPrice);
|
||||||
|
} else if (num >= 0 && armsButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you don't have that many to sell!");
|
||||||
|
} else if (armsButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
|
||||||
|
} else if (generalButton.getText().contains(".") && num <= player.getGeneralHeld() && num >= 0) {
|
||||||
|
player.setGeneralHeld(player.getGeneralHeld() - num);
|
||||||
|
player.setMoney(player.getMoney() + num * generalPrice);
|
||||||
|
} else if (num >= 0 && generalButton.getText().contains(".")) {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", you don't have that many to sell!");
|
||||||
|
} else {
|
||||||
|
textOut.setText(originalDialogue + "\n\t" + player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the shop on the given stage as a parameter.
|
||||||
|
*
|
||||||
|
* @param stage
|
||||||
|
*/
|
||||||
|
public void initializeShop(Stage stage) {
|
||||||
|
Font size14 = new Font(14.0);
|
||||||
|
Rectangle dialogueRectangle = new Rectangle();
|
||||||
|
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
|
||||||
|
dialogueRectangle.setHeight(180.0);
|
||||||
|
dialogueRectangle.setLayoutX(8.0);
|
||||||
|
dialogueRectangle.setLayoutY(294.0);
|
||||||
|
dialogueRectangle.setStroke(javafx.scene.paint.Color.BLACK);
|
||||||
|
dialogueRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
|
||||||
|
dialogueRectangle.setWidth(582.0);
|
||||||
|
|
||||||
|
Rectangle inventoryRectangle = new Rectangle();
|
||||||
|
inventoryRectangle.setFill(javafx.scene.paint.Color.WHITE);
|
||||||
|
inventoryRectangle.setHeight(108.0);
|
||||||
|
inventoryRectangle.setLayoutX(8.0);
|
||||||
|
inventoryRectangle.setLayoutY(147.0);
|
||||||
|
inventoryRectangle.setStroke(javafx.scene.paint.Color.BLACK);
|
||||||
|
inventoryRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
|
||||||
|
inventoryRectangle.setWidth(405.0);
|
||||||
|
|
||||||
|
Rectangle warehouseRectangle = new Rectangle();
|
||||||
|
warehouseRectangle.setFill(javafx.scene.paint.Color.WHITE);
|
||||||
|
warehouseRectangle.setHeight(108.0);
|
||||||
|
warehouseRectangle.setLayoutY(33.0);
|
||||||
|
warehouseRectangle.setLayoutX(8.0);
|
||||||
|
warehouseRectangle.setStroke(javafx.scene.paint.Color.BLACK);
|
||||||
|
warehouseRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
|
||||||
|
warehouseRectangle.setWidth(405.0);
|
||||||
|
|
||||||
|
AnchorPane anchorPane = new AnchorPane();
|
||||||
|
anchorPane.setPrefHeight(480.0);
|
||||||
|
anchorPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
GridPane gridPane = new GridPane();
|
||||||
|
gridPane.setPrefHeight(480.0);
|
||||||
|
gridPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
ColumnConstraints columnConstraints = new ColumnConstraints();
|
||||||
|
columnConstraints.setMaxWidth(590.0);
|
||||||
|
columnConstraints.setMinWidth(0.0);
|
||||||
|
columnConstraints.setPrefWidth(590.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints = new RowConstraints();
|
||||||
|
rowConstraints.setMinHeight(20.0);
|
||||||
|
rowConstraints.setPrefHeight(20.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints0 = new RowConstraints();
|
||||||
|
rowConstraints0.setMaxHeight(122.0);
|
||||||
|
rowConstraints0.setMinHeight(10.0);
|
||||||
|
rowConstraints0.setPrefHeight(117.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints1 = new RowConstraints();
|
||||||
|
rowConstraints1.setMaxHeight(163.0);
|
||||||
|
rowConstraints1.setMinHeight(10.0);
|
||||||
|
rowConstraints1.setPrefHeight(112.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints2 = new RowConstraints();
|
||||||
|
rowConstraints2.setMaxHeight(126.0);
|
||||||
|
rowConstraints2.setMinHeight(0.0);
|
||||||
|
rowConstraints2.setPrefHeight(42.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints3 = new RowConstraints();
|
||||||
|
rowConstraints3.setMaxHeight(269.0);
|
||||||
|
rowConstraints3.setMinHeight(10.0);
|
||||||
|
rowConstraints3.setPrefHeight(118.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints4 = new RowConstraints();
|
||||||
|
rowConstraints4.setMaxHeight(179.0);
|
||||||
|
rowConstraints4.setMinHeight(10.0);
|
||||||
|
rowConstraints4.setPrefHeight(52.0);
|
||||||
|
|
||||||
|
gridPane.setPadding(new Insets(10.0, 10.0, 10.0, 0.0));
|
||||||
|
|
||||||
|
HBox hBox = new HBox();
|
||||||
|
GridPane.setRowIndex(hBox, 1);
|
||||||
|
hBox.setPrefHeight(100.0);
|
||||||
|
hBox.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
HBox hBox0 = new HBox();
|
||||||
|
GridPane.setRowIndex(hBox0, 2);
|
||||||
|
hBox0.setPrefHeight(100.0);
|
||||||
|
hBox0.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
FlowPane flowPane = new FlowPane();
|
||||||
|
GridPane.setRowIndex(flowPane, 5);
|
||||||
|
flowPane.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
flowPane.setHgap(5.0);
|
||||||
|
flowPane.setPrefHeight(200.0);
|
||||||
|
flowPane.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
buyButton.setMnemonicParsing(false);
|
||||||
|
buyButton.setPrefHeight(25.0);
|
||||||
|
buyButton.setPrefWidth(45.0);
|
||||||
|
buyButton.setText("Buy");
|
||||||
|
// if the buy button is clicked, the main utility buttons are set to be invisible and the buying process begins.
|
||||||
|
buyButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
buttonSetup("shop");
|
||||||
|
buyButton.setText("Buy.");
|
||||||
|
defaultTextOut();
|
||||||
|
textOut.setText(textOut.getText() + "\n\tWhich good would you like to purchase?");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sellButton.setPrefHeight(25.0);
|
||||||
|
sellButton.setText("Sell");
|
||||||
|
// if the sell button is clicked, the main utility buttons are set to be invisible and the selling process begins.
|
||||||
|
sellButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
buttonSetup("shop");
|
||||||
|
sellButton.setText("Sell.");
|
||||||
|
defaultTextOut();
|
||||||
|
textOut.setText(textOut.getText() + "\n\tWhich good would you like to sell?");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sellButton.setPrefWidth(45.0);
|
||||||
|
sellButton.setMnemonicParsing(false);
|
||||||
|
|
||||||
|
bankButton.setPrefHeight(25.0);
|
||||||
|
// opens the bank if the bank button is clicked.
|
||||||
|
bankButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
BankGUI bank = new BankGUI(getPlayer());
|
||||||
|
bank.initializeBank(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bankButton.setMnemonicParsing(false);
|
||||||
|
bankButton.setPrefWidth(74.0);
|
||||||
|
bankButton.setText("Visit Bank");
|
||||||
|
|
||||||
|
cargoButton.setPrefHeight(25.0);
|
||||||
|
cargoButton.setText("Transfer Cargo");
|
||||||
|
cargoButton.setMnemonicParsing(false);
|
||||||
|
cargoButton.setPrefWidth(94.0);
|
||||||
|
// warehouse is entered when the warehouse button is clicked.
|
||||||
|
cargoButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
WarehouseGUI warehouseGUI = new WarehouseGUI(player);
|
||||||
|
warehouseGUI.initializeWarehouse(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
loanButton.setMnemonicParsing(false);
|
||||||
|
loanButton.setPrefHeight(25.0);
|
||||||
|
loanButton.setPrefWidth(73.0);
|
||||||
|
// loan office is entered when the loan button is clicked.
|
||||||
|
loanButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
LoanSharkGUI loan = new LoanSharkGUI(getPlayer());
|
||||||
|
loan.initializeLoanShark(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
loanButton.setText("Get Loans");
|
||||||
|
|
||||||
|
quitButton.setPrefHeight(25.0);
|
||||||
|
quitButton.setMnemonicParsing(false);
|
||||||
|
quitButton.setPrefWidth(90.0);
|
||||||
|
quitButton.setText("Quit Trading");
|
||||||
|
// the user is free to travel once the quit button is clicked.
|
||||||
|
quitButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
TravelGUI travelGUI = new TravelGUI(player);
|
||||||
|
travelGUI.initializeTravel(stage);
|
||||||
|
stage.show();
|
||||||
|
//System.out.println("PLACEHOLDER FOR TRAVEL");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
retireButton.setPrefHeight(25.0);
|
||||||
|
retireButton.setPrefWidth(49.0);
|
||||||
|
retireButton.setText("Retire");
|
||||||
|
retireButton.setVisible(false);
|
||||||
|
// the user wins the game when the retire button is clicked.
|
||||||
|
retireButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
retire(stage);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
retireButton.setMnemonicParsing(false);
|
||||||
|
|
||||||
|
opiumButton.setMnemonicParsing(false);
|
||||||
|
opiumButton.setPrefWidth(86.0);
|
||||||
|
opiumButton.setPrefHeight(25.0);
|
||||||
|
opiumButton.setText("Opium");
|
||||||
|
opiumButton.setVisible(false);
|
||||||
|
// the opium buying/selling process starts as soon as the user clicks the opium button.
|
||||||
|
opiumButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
buttonSetup("input");
|
||||||
|
opiumButton.setText("Opium.");
|
||||||
|
defaultTextOut();
|
||||||
|
String extraText;
|
||||||
|
if (buyButton.getText().contains(".")) {
|
||||||
|
extraText = String.format(" (You can afford %d)", player.getMoney() / opiumPrice);
|
||||||
|
} else {
|
||||||
|
extraText = String.format(" (You have %d)", player.getOpiumHeld());
|
||||||
|
}
|
||||||
|
textOut.setText(textOut.getText() + "\n\tWhat quantity of Opium?" + extraText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
silkButton.setPrefHeight(25.0);
|
||||||
|
silkButton.setPrefWidth(86.0);
|
||||||
|
silkButton.setMnemonicParsing(false);
|
||||||
|
silkButton.setText("Silk");
|
||||||
|
silkButton.setVisible(false);
|
||||||
|
// the silk buying/selling process starts as soon as the user clicks the silk button.
|
||||||
|
silkButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
buttonSetup("input");
|
||||||
|
silkButton.setText("Silk.");
|
||||||
|
defaultTextOut();
|
||||||
|
String extraText;
|
||||||
|
if (buyButton.getText().contains(".")) {
|
||||||
|
extraText = String.format(" (You can afford %d)", player.getMoney() / silkPrice);
|
||||||
|
} else {
|
||||||
|
extraText = String.format(" (You have %d)", player.getSilkHeld());
|
||||||
|
}
|
||||||
|
textOut.setText(textOut.getText() + "\n\tWhat quantity of Silk?" + extraText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
armsButton.setPrefWidth(86.0);
|
||||||
|
armsButton.setMnemonicParsing(false);
|
||||||
|
armsButton.setVisible(false);
|
||||||
|
// the arms buying/selling process starts as soon as the user clicks the arms button.
|
||||||
|
armsButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
buttonSetup("input");
|
||||||
|
armsButton.setText("Arms.");
|
||||||
|
defaultTextOut();
|
||||||
|
String extraText;
|
||||||
|
if (buyButton.getText().contains(".")) {
|
||||||
|
extraText = String.format(" (You can afford %d)", player.getMoney() / armsPrice);
|
||||||
|
} else {
|
||||||
|
extraText = String.format(" (You have %d)", player.getArmsHeld());
|
||||||
|
}
|
||||||
|
textOut.setText(textOut.getText() + "\n\tWhat quantity of Arms?" + extraText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
armsButton.setText("Arms");
|
||||||
|
armsButton.setPrefHeight(25.0);
|
||||||
|
|
||||||
|
generalButton.setMnemonicParsing(false);
|
||||||
|
generalButton.setPrefHeight(25.0);
|
||||||
|
generalButton.setPrefWidth(86.0);
|
||||||
|
generalButton.setText("General");
|
||||||
|
generalButton.setVisible(false);
|
||||||
|
// the general cargo buying/selling process starts as soon as the user clicks the general cargo button.
|
||||||
|
generalButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
buttonSetup("input");
|
||||||
|
generalButton.setText("General.");
|
||||||
|
defaultTextOut();
|
||||||
|
String extraText;
|
||||||
|
if (buyButton.getText().contains(".")) {
|
||||||
|
extraText = String.format(" (You can afford %d)", player.getMoney() / generalPrice);
|
||||||
|
} else {
|
||||||
|
extraText = String.format(" (You have %d)", player.getGeneralHeld());
|
||||||
|
}
|
||||||
|
textOut.setText(textOut.getText() + "\n\tWhat quantity of General Cargo?" + extraText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT);
|
||||||
|
numberInput.setText("Enter amount here...");
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
// after the user inputs a valid input into the text field and presses Z or ENTER, the buying/selling ends and
|
||||||
|
// the user is returned to the regular shop dialogue.
|
||||||
|
numberInput.setOnKeyPressed(new EventHandler<KeyEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(KeyEvent event) {
|
||||||
|
boolean exit = true;
|
||||||
|
defaultTextOut();
|
||||||
|
if (event.getCode().equals(KeyCode.ENTER) || event.getCode().equals(KeyCode.Z)) {
|
||||||
|
while (true) {
|
||||||
|
if (!textOut.getText().contains("You entered an invalid input!") && !exit) {
|
||||||
|
textOut.setText(textOut.getText() + "\n\n\tYou entered an invalid input! Please try again.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
shop();
|
||||||
|
} catch (Exception e) {
|
||||||
|
exit = false;
|
||||||
|
}
|
||||||
|
if (exit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateStage();
|
||||||
|
|
||||||
|
buttonSetup("reset");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
firm.setAlignment(Pos.CENTER);
|
||||||
|
firm.setPrefHeight(27.0);
|
||||||
|
firm.setPrefWidth(632.0);
|
||||||
|
firm.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
Label warehouseText = new Label();
|
||||||
|
warehouseText.setAlignment(Pos.CENTER);
|
||||||
|
warehouseText.setPrefHeight(108.0);
|
||||||
|
warehouseText.setPrefWidth(100.0);
|
||||||
|
warehouseText.setText("Warehouse\n\tOpium\n\tSilk\n\tArms\n\tGeneral");
|
||||||
|
warehouseText.setFont(size14);
|
||||||
|
|
||||||
|
wItemsText.setAlignment(Pos.CENTER);
|
||||||
|
wItemsText.setPrefWidth(100.0);
|
||||||
|
wItemsText.setPrefHeight(108.0);
|
||||||
|
wItemsText.setFont(size14);
|
||||||
|
|
||||||
|
wItemSpaceText.setPrefHeight(108.0);
|
||||||
|
wItemSpaceText.setPrefWidth(215.0);
|
||||||
|
wItemSpaceText.setFont(size14);
|
||||||
|
|
||||||
|
locationText.setAlignment(Pos.BOTTOM_CENTER);
|
||||||
|
locationText.setPrefHeight(106.0);
|
||||||
|
locationText.setPrefWidth(175.0);
|
||||||
|
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
locationText.setFont(size14);
|
||||||
|
|
||||||
|
inventoryText.setAlignment(Pos.CENTER);
|
||||||
|
inventoryText.setFont(size14);
|
||||||
|
|
||||||
|
inventoryHeldText.setAlignment(Pos.CENTER);
|
||||||
|
inventoryHeldText.setPrefHeight(108.0);
|
||||||
|
inventoryHeldText.setPrefWidth(100.0);
|
||||||
|
inventoryHeldText.setFont(size14);
|
||||||
|
|
||||||
|
gunsText.setPrefHeight(108.0);
|
||||||
|
gunsText.setPrefWidth(212.0);
|
||||||
|
gunsText.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
gunsText.setFont(size14);
|
||||||
|
|
||||||
|
shipStatusText.setAlignment(Pos.TOP_CENTER);
|
||||||
|
shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
shipStatusText.setPrefHeight(110.0);
|
||||||
|
shipStatusText.setPrefWidth(180.0);
|
||||||
|
shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
shipStatusText.setFont(size14);
|
||||||
|
|
||||||
|
GridPane.setRowIndex(cashText, 3);
|
||||||
|
cashText.setPrefHeight(17.0);
|
||||||
|
cashText.setPrefWidth(209.0);
|
||||||
|
cashText.setFont(size14);
|
||||||
|
|
||||||
|
GridPane.setHalignment(bankText, javafx.geometry.HPos.CENTER);
|
||||||
|
GridPane.setRowIndex(bankText, 3);
|
||||||
|
bankText.setAlignment(Pos.CENTER);
|
||||||
|
bankText.setPrefHeight(20.0);
|
||||||
|
bankText.setPrefWidth(264.0);
|
||||||
|
bankText.setFont(size14);
|
||||||
|
|
||||||
|
GridPane.setRowIndex(textOut, 4);
|
||||||
|
textOut.setAlignment(Pos.TOP_LEFT);
|
||||||
|
textOut.setContentDisplay(javafx.scene.control.ContentDisplay.TOP);
|
||||||
|
textOut.setPrefHeight(163.0);
|
||||||
|
textOut.setPrefWidth(583.0);
|
||||||
|
defaultTextOut();
|
||||||
|
textOut.setFont(size14);
|
||||||
|
|
||||||
|
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);
|
||||||
|
|
||||||
|
hBox.getChildren().addAll(warehouseText, wItemsText, wItemSpaceText, locationText);
|
||||||
|
|
||||||
|
hBox0.getChildren().addAll(inventoryText, inventoryHeldText, gunsText, shipStatusText);
|
||||||
|
|
||||||
|
flowPane.getChildren().addAll(buyButton, sellButton, bankButton, cargoButton, loanButton, quitButton, retireButton, opiumButton, silkButton, armsButton, generalButton, numberInput);
|
||||||
|
|
||||||
|
gridPane.getColumnConstraints().add(columnConstraints);
|
||||||
|
gridPane.getRowConstraints().addAll(rowConstraints, rowConstraints0, rowConstraints1, rowConstraints2, rowConstraints3, rowConstraints4);
|
||||||
|
gridPane.getChildren().addAll(firm, hBox, hBox0, cashText, bankText, textOut, flowPane);
|
||||||
|
|
||||||
|
anchorPane.getChildren().add(gridPane);
|
||||||
|
|
||||||
|
Scene root = new Scene(anchorPane, 600, 480);
|
||||||
|
|
||||||
|
stage.setTitle("Shop");
|
||||||
|
stage.setResizable(false);
|
||||||
|
stage.setScene(root);
|
||||||
|
|
||||||
|
// general updates to the buttons, user stats/inventory, and text.
|
||||||
|
buttonSetup("reset");
|
||||||
|
updatePrices();
|
||||||
|
defaultTextOut();
|
||||||
|
updateStage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts the user's location (an integer) to a String, and returns it.
|
||||||
|
*
|
||||||
|
* @return location -- the user's location as a string; the actual name of the location.
|
||||||
|
*/
|
||||||
|
public String getStringLocation() {
|
||||||
|
String location;
|
||||||
|
switch (player.getLocation()) {
|
||||||
|
case 1:
|
||||||
|
location = "Hong Kong";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
location = "Shanghai";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
location = "Nagasaki";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
location = "Saigon";
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
location = "Manila";
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
location = "Singapore";
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
location = "Batavia";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
location = "Error";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the user's condition based upon their current HP.
|
||||||
|
*
|
||||||
|
* @return shipStatus -- a representation of their ship's health in words.
|
||||||
|
*/
|
||||||
|
public String shipStatusString() {
|
||||||
|
String shipStatus;
|
||||||
|
switch (player.getHP() / 10) {
|
||||||
|
case 10:
|
||||||
|
shipStatus = "Mint Condition";
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
shipStatus = "Near Perfect";
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
shipStatus = "Great";
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
shipStatus = "Good";
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
shipStatus = "Acceptable";
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
shipStatus = "Tolerable";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
shipStatus = "Needs Repair";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
shipStatus = "Damaged";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
shipStatus = "Indangered";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
shipStatus = "Near Sinking";
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
shipStatus = "Sinking";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
shipStatus = "Invincible";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return shipStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates the text associated with the user's inventory.
|
||||||
|
*/
|
||||||
|
public void updateStage() {
|
||||||
|
firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation()));
|
||||||
|
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", player.getwOpium(), player.getwSilk(), player.getwArms(), player.getwGeneral()));
|
||||||
|
int itemsInWarehouse = player.getwOpium() + player.getwGeneral() + player.getwArms() + player.getwSilk();
|
||||||
|
wItemSpaceText.setText(String.format("\n\t\tIn use:\n\t\t %d \n\t\tVacant:\n\t\t %d", itemsInWarehouse, (10000 - itemsInWarehouse)));
|
||||||
|
locationText.setText(String.format("Location\n%s", getStringLocation()));
|
||||||
|
int itemsInInventory = player.getCargoSpace() - player.getSilkHeld() - player.getOpiumHeld() - player.getGeneralHeld() - player.getArmsHeld() - 10 * player.getGuns();
|
||||||
|
if (itemsInInventory < 0) {
|
||||||
|
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
|
||||||
|
} else {
|
||||||
|
inventoryText.setText(String.format(" Hold %d\n\t Opium\n\t Silk\n\t Arms\n\t General", itemsInInventory));
|
||||||
|
}
|
||||||
|
gunsText.setText(String.format("Guns %d\n\n\n\n ", player.getGuns()));
|
||||||
|
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", player.getOpiumHeld(), player.getSilkHeld(), player.getArmsHeld(), player.getGeneralHeld()));
|
||||||
|
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", player.getDebt(), shipStatusString(), player.getHP()));
|
||||||
|
cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
|
||||||
|
bankText.setText(String.format("Bank: %d", player.getBank()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
120
src/Travel.java
120
src/Travel.java
@@ -1,120 +0,0 @@
|
|||||||
import java.util.Random;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Travel {
|
|
||||||
|
|
||||||
private Player player;
|
|
||||||
|
|
||||||
public void setPlayer(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
return playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Travel(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void seaAtlas(int locationOfTravel) {
|
|
||||||
switch (locationOfTravel) {
|
|
||||||
case 1:
|
|
||||||
System.out.println("\nArriving at Hong Kong");
|
|
||||||
player.setLocation(1);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
System.out.println("\nArriving at Shanghai");
|
|
||||||
player.setLocation(2);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
System.out.println("\nArriving at Nagasaki");
|
|
||||||
player.setLocation(3);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
System.out.println("\nArriving at Saigon");
|
|
||||||
player.setLocation(4);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
System.out.println("\nArriving at Manila");
|
|
||||||
player.setLocation(5);
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
System.out.println("\nArriving at Singapore");
|
|
||||||
player.setLocation(6);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
System.out.println("\nArriving at Batavia");
|
|
||||||
player.setLocation(7);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void randomEventSea(int locationOfTravel) throws Exception {
|
|
||||||
Random rand = new Random();
|
|
||||||
int randGenNum = rand.nextInt(3) + 1;
|
|
||||||
if (randGenNum == 1) {
|
|
||||||
peasantFleet();
|
|
||||||
} else if (randGenNum == 2) {
|
|
||||||
disaster(locationOfTravel);
|
|
||||||
}
|
|
||||||
System.out.println("We made it!");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void disaster(int locationOfTravel) {
|
|
||||||
System.out.print("Storm " + player.getName() + "! ");
|
|
||||||
Random rand = new Random();
|
|
||||||
int randGenNum = rand.nextInt(5) + 1;
|
|
||||||
|
|
||||||
if (randGenNum <= 2) {
|
|
||||||
System.out.println(" We made it through!");
|
|
||||||
} else {
|
|
||||||
while (randGenNum == locationOfTravel) {
|
|
||||||
randGenNum = rand.nextInt(7) + 1;
|
|
||||||
if (randGenNum != locationOfTravel) {
|
|
||||||
System.out.println("We've been blown off course!");
|
|
||||||
seaAtlas(randGenNum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void peasantFleet() throws Exception {
|
|
||||||
ShipWarfare attackShip = new ShipWarfare(player);
|
|
||||||
attackShip.peasantFleetAttack();
|
|
||||||
player = attackShip.getPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void travelTo() {
|
|
||||||
Scanner keyboard = new Scanner(System.in);
|
|
||||||
String response;
|
|
||||||
int tempInt;
|
|
||||||
boolean hasTraveled = false;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
System.out.println("\n" + player.getName() + ", do you wish to go to:\n");
|
|
||||||
System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?");
|
|
||||||
|
|
||||||
response = keyboard.nextLine();
|
|
||||||
try {
|
|
||||||
tempInt = Integer.parseInt(response);
|
|
||||||
System.out.println(tempInt + " " + player.getLocation());
|
|
||||||
if (tempInt != player.getLocation()) {
|
|
||||||
randomEventSea(tempInt);
|
|
||||||
seaAtlas(tempInt);
|
|
||||||
hasTraveled = true;
|
|
||||||
player.setBank((int)(player.getBank() * 1.01));
|
|
||||||
player.setDebt((int)(player.getDebt() * 1.01));
|
|
||||||
} else System.out.println("\nYou're already here " + player.getName() + ".");
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.print("\nSorry, " + player.getName() + " could you say that again?");
|
|
||||||
}
|
|
||||||
if (hasTraveled) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
473
src/TravelGUI.java
Normal file
473
src/TravelGUI.java
Normal file
@@ -0,0 +1,473 @@
|
|||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class TravelGUI{
|
||||||
|
private Player player;
|
||||||
|
private Label firm = new Label();
|
||||||
|
private Label wItemsText = new Label();
|
||||||
|
private Label wItemSpaceText = new Label();
|
||||||
|
private Label locationText = new Label();
|
||||||
|
private Label inventoryText = new Label();
|
||||||
|
private Label inventoryHeldText = new Label();
|
||||||
|
private Label gunsText = new Label();
|
||||||
|
private Label shipStatusText = new Label();
|
||||||
|
private Label cashText = new Label();
|
||||||
|
private Label bankText = new Label();
|
||||||
|
private Label textOut = new Label();
|
||||||
|
|
||||||
|
private Button quitButton = new Button();
|
||||||
|
private Button continueButton = new Button();
|
||||||
|
private TextField numberInput = new TextField();
|
||||||
|
|
||||||
|
private Boolean peasantShipScene = false;
|
||||||
|
private Boolean littyShipScene = false;
|
||||||
|
private Boolean shopScene = false;
|
||||||
|
private Boolean stormScene = false;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 TravelGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the graphical part of TravelGUI and includes all logic for the class
|
||||||
|
*
|
||||||
|
* @param stage sets the stage to which we will execute the scene of the TravelGUI class
|
||||||
|
* @return stage so that another class can switch to the stage
|
||||||
|
*/
|
||||||
|
public Stage initializeTravel(Stage stage){
|
||||||
|
//Updates the stage for the first-time you read it
|
||||||
|
updateStage();
|
||||||
|
|
||||||
|
Font size14 = new Font(14.0);
|
||||||
|
Rectangle dialogueRectangle = new Rectangle();
|
||||||
|
dialogueRectangle.setFill(javafx.scene.paint.Color.WHITE);
|
||||||
|
dialogueRectangle.setHeight(180.0);
|
||||||
|
dialogueRectangle.setLayoutX(8.0);
|
||||||
|
dialogueRectangle.setLayoutY(294.0);
|
||||||
|
dialogueRectangle.setStroke(javafx.scene.paint.Color.BLACK);
|
||||||
|
dialogueRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
|
||||||
|
dialogueRectangle.setWidth(582.0);
|
||||||
|
|
||||||
|
Rectangle inventoryRectangle = new Rectangle();
|
||||||
|
inventoryRectangle.setFill(javafx.scene.paint.Color.WHITE);
|
||||||
|
inventoryRectangle.setHeight(108.0);
|
||||||
|
inventoryRectangle.setLayoutX(8.0);
|
||||||
|
inventoryRectangle.setLayoutY(147.0);
|
||||||
|
inventoryRectangle.setStroke(javafx.scene.paint.Color.BLACK);
|
||||||
|
inventoryRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
|
||||||
|
inventoryRectangle.setWidth(405.0);
|
||||||
|
|
||||||
|
Rectangle warehouseRectangle = new Rectangle();
|
||||||
|
warehouseRectangle.setFill(javafx.scene.paint.Color.WHITE);
|
||||||
|
warehouseRectangle.setHeight(108.0);
|
||||||
|
warehouseRectangle.setLayoutY(33.0);
|
||||||
|
warehouseRectangle.setLayoutX(8.0);
|
||||||
|
warehouseRectangle.setStroke(javafx.scene.paint.Color.BLACK);
|
||||||
|
warehouseRectangle.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
|
||||||
|
warehouseRectangle.setWidth(405.0);
|
||||||
|
|
||||||
|
AnchorPane anchorPane = new AnchorPane();
|
||||||
|
anchorPane.setPrefHeight(480.0);
|
||||||
|
anchorPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
GridPane gridPane = new GridPane();
|
||||||
|
gridPane.setPrefHeight(480.0);
|
||||||
|
gridPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
ColumnConstraints columnConstraints = new ColumnConstraints();
|
||||||
|
columnConstraints.setMaxWidth(590.0);
|
||||||
|
columnConstraints.setMinWidth(0.0);
|
||||||
|
columnConstraints.setPrefWidth(590.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints = new RowConstraints();
|
||||||
|
rowConstraints.setMinHeight(20.0);
|
||||||
|
rowConstraints.setPrefHeight(20.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints0 = new RowConstraints();
|
||||||
|
rowConstraints0.setMaxHeight(122.0);
|
||||||
|
rowConstraints0.setMinHeight(10.0);
|
||||||
|
rowConstraints0.setPrefHeight(117.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints1 = new RowConstraints();
|
||||||
|
rowConstraints1.setMaxHeight(163.0);
|
||||||
|
rowConstraints1.setMinHeight(10.0);
|
||||||
|
rowConstraints1.setPrefHeight(112.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints2 = new RowConstraints();
|
||||||
|
rowConstraints2.setMaxHeight(126.0);
|
||||||
|
rowConstraints2.setMinHeight(0.0);
|
||||||
|
rowConstraints2.setPrefHeight(42.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints3 = new RowConstraints();
|
||||||
|
rowConstraints3.setMaxHeight(269.0);
|
||||||
|
rowConstraints3.setMinHeight(10.0);
|
||||||
|
rowConstraints3.setPrefHeight(118.0);
|
||||||
|
|
||||||
|
RowConstraints rowConstraints4 = new RowConstraints();
|
||||||
|
rowConstraints4.setMaxHeight(179.0);
|
||||||
|
rowConstraints4.setMinHeight(10.0);
|
||||||
|
rowConstraints4.setPrefHeight(52.0);
|
||||||
|
|
||||||
|
gridPane.setPadding(new Insets(10.0, 10.0, 10.0, 0.0));
|
||||||
|
|
||||||
|
HBox hBox = new HBox();
|
||||||
|
GridPane.setRowIndex(hBox, 1);
|
||||||
|
hBox.setPrefHeight(100.0);
|
||||||
|
hBox.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
HBox hBox0 = new HBox();
|
||||||
|
GridPane.setRowIndex(hBox0, 2);
|
||||||
|
hBox0.setPrefHeight(100.0);
|
||||||
|
hBox0.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
FlowPane flowPane = new FlowPane();
|
||||||
|
GridPane.setRowIndex(flowPane, 5);
|
||||||
|
flowPane.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
flowPane.setHgap(5.0);
|
||||||
|
flowPane.setPrefHeight(200.0);
|
||||||
|
flowPane.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
//Creating the continue and quit buttons
|
||||||
|
quitButton.setPrefHeight(25.0);
|
||||||
|
quitButton.setMnemonicParsing(false);
|
||||||
|
quitButton.setPrefWidth(90.0);
|
||||||
|
quitButton.setText("Go back");
|
||||||
|
|
||||||
|
continueButton.setPrefHeight(25.0);
|
||||||
|
continueButton.setMnemonicParsing(false);
|
||||||
|
continueButton.setPrefWidth(90.0);
|
||||||
|
continueButton.setText("Continue");
|
||||||
|
continueButton.setVisible(false);
|
||||||
|
|
||||||
|
//Goes back to shop
|
||||||
|
quitButton.setOnAction(event -> {
|
||||||
|
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(player);
|
||||||
|
taipanShopGUI.initializeShop(stage);
|
||||||
|
stage.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
//Continues on to either shop or shipwarfare
|
||||||
|
continueButton.setOnAction(event -> {
|
||||||
|
if(peasantShipScene){
|
||||||
|
ShipWarfareGUI ship = new ShipWarfareGUI(player);
|
||||||
|
ship.initializeShip(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
else if(shopScene){
|
||||||
|
TaipanShopGUI shop = new TaipanShopGUI(player);
|
||||||
|
shop.initializeShop(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Text input for where the player needs to go inside of the game world
|
||||||
|
numberInput.setAlignment(javafx.geometry.Pos.CENTER_RIGHT);
|
||||||
|
numberInput.setText("Enter preferred location.");
|
||||||
|
numberInput.setOnKeyPressed(event -> {
|
||||||
|
if(event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)) {
|
||||||
|
int response;
|
||||||
|
try {
|
||||||
|
response = Integer.parseInt(numberInput.getText().replace(" ", ""));
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
response = 0;
|
||||||
|
}
|
||||||
|
boolean hasTraveled = false;
|
||||||
|
//Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory.
|
||||||
|
if(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){
|
||||||
|
//Just in case the player types something that was not intended. It will refresh the question and ask it again
|
||||||
|
try {
|
||||||
|
//Makes sure you can't travel to your own location.
|
||||||
|
if (response != player.getLocation() && response != 0 && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
|
||||||
|
randomEventSea(response,stage);
|
||||||
|
hasTraveled = seaAtlas(response);
|
||||||
|
player.setBank((int) (player.getBank() * 1.01));
|
||||||
|
player.setDebt((int) (player.getDebt() * 1.01));
|
||||||
|
shopScene = false;
|
||||||
|
stormScene = false;
|
||||||
|
} else{
|
||||||
|
textOut.setText(" " + "You're already here " + player.getName());
|
||||||
|
textOut.setText(textOut.getText() + ", do you wish to go to:\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
textOut.setText(" " + "Sorry, " + player.getName() + " could you say that again?");
|
||||||
|
}
|
||||||
|
if (hasTraveled) {
|
||||||
|
continueButton.setVisible(true);
|
||||||
|
quitButton.setVisible(false);
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
shopScene = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (player.getCargoSpace() < (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){
|
||||||
|
textOut.setText(" "+player.getName() + " the cargo is too heavy! We can't set sail!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
firm.setAlignment(Pos.CENTER);
|
||||||
|
firm.setPrefHeight(27.0);
|
||||||
|
firm.setPrefWidth(632.0);
|
||||||
|
firm.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
Label warehouseText = new Label();
|
||||||
|
warehouseText.setAlignment(Pos.CENTER);
|
||||||
|
warehouseText.setPrefHeight(108.0);
|
||||||
|
warehouseText.setPrefWidth(100.0);
|
||||||
|
warehouseText.setText("Warehouse\n\tOpium\n\tSilk\n\tArms\n\tGeneral");
|
||||||
|
warehouseText.setFont(size14);
|
||||||
|
|
||||||
|
wItemsText.setAlignment(Pos.CENTER);
|
||||||
|
wItemsText.setPrefWidth(100.0);
|
||||||
|
wItemsText.setPrefHeight(108.0);
|
||||||
|
wItemsText.setFont(size14);
|
||||||
|
|
||||||
|
wItemSpaceText.setPrefHeight(108.0);
|
||||||
|
wItemSpaceText.setPrefWidth(215.0);
|
||||||
|
wItemSpaceText.setFont(size14);
|
||||||
|
|
||||||
|
locationText.setAlignment(Pos.BOTTOM_CENTER);
|
||||||
|
locationText.setPrefHeight(106.0);
|
||||||
|
locationText.setPrefWidth(175.0);
|
||||||
|
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
locationText.setFont(size14);
|
||||||
|
|
||||||
|
inventoryText.setAlignment(Pos.CENTER);
|
||||||
|
inventoryText.setFont(size14);
|
||||||
|
|
||||||
|
inventoryHeldText.setAlignment(Pos.CENTER);
|
||||||
|
inventoryHeldText.setPrefHeight(108.0);
|
||||||
|
inventoryHeldText.setPrefWidth(100.0);
|
||||||
|
inventoryHeldText.setFont(size14);
|
||||||
|
|
||||||
|
gunsText.setPrefHeight(108.0);
|
||||||
|
gunsText.setPrefWidth(212.0);
|
||||||
|
gunsText.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
gunsText.setFont(size14);
|
||||||
|
|
||||||
|
shipStatusText.setAlignment(Pos.TOP_CENTER);
|
||||||
|
shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
shipStatusText.setPrefHeight(110.0);
|
||||||
|
shipStatusText.setPrefWidth(180.0);
|
||||||
|
shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
shipStatusText.setFont(size14);
|
||||||
|
|
||||||
|
GridPane.setRowIndex(cashText, 3);
|
||||||
|
cashText.setPrefHeight(17.0);
|
||||||
|
cashText.setPrefWidth(209.0);
|
||||||
|
cashText.setFont(size14);
|
||||||
|
|
||||||
|
GridPane.setHalignment(bankText, javafx.geometry.HPos.CENTER);
|
||||||
|
GridPane.setRowIndex(bankText, 3);
|
||||||
|
bankText.setAlignment(Pos.CENTER);
|
||||||
|
bankText.setPrefHeight(20.0);
|
||||||
|
bankText.setPrefWidth(264.0);
|
||||||
|
bankText.setFont(size14);
|
||||||
|
|
||||||
|
GridPane.setRowIndex(textOut, 4);
|
||||||
|
textOut.setAlignment(Pos.TOP_LEFT);
|
||||||
|
textOut.setContentDisplay(javafx.scene.control.ContentDisplay.TOP);
|
||||||
|
textOut.setPrefHeight(163.0);
|
||||||
|
textOut.setPrefWidth(583.0);
|
||||||
|
textOut.setText(" Taipan, do you wish to go to:\n\n 1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n 5) Manila, 6) Singapore, or 7) Batavia?\n After typing the number you want to go to press 'Enter' or 'Z'");
|
||||||
|
textOut.setFont(size14);
|
||||||
|
|
||||||
|
//Added all the nodes into a single scene
|
||||||
|
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);
|
||||||
|
|
||||||
|
hBox.getChildren().addAll(warehouseText, wItemsText, wItemSpaceText, locationText);
|
||||||
|
|
||||||
|
hBox0.getChildren().addAll(inventoryText, inventoryHeldText, gunsText, shipStatusText);
|
||||||
|
|
||||||
|
flowPane.getChildren().addAll(numberInput, quitButton, continueButton);
|
||||||
|
|
||||||
|
gridPane.getColumnConstraints().add(columnConstraints);
|
||||||
|
gridPane.getRowConstraints().addAll(rowConstraints, rowConstraints0, rowConstraints1, rowConstraints2, rowConstraints3, rowConstraints4);
|
||||||
|
gridPane.getChildren().addAll(firm, hBox, hBox0, cashText, bankText, textOut, flowPane);
|
||||||
|
|
||||||
|
anchorPane.getChildren().add(gridPane);
|
||||||
|
|
||||||
|
Scene root = new Scene(anchorPane, 600, 480);
|
||||||
|
|
||||||
|
stage.setTitle("Travel");
|
||||||
|
stage.setResizable(false);
|
||||||
|
stage.setScene(root);
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When provided a location number: the method returns a print statement stating the location's name and call another
|
||||||
|
* method to change the location of the Player object.
|
||||||
|
*
|
||||||
|
* @param locationOfTravel is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
private Boolean seaAtlas(int locationOfTravel) {
|
||||||
|
switch (locationOfTravel) {
|
||||||
|
case 1:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Hong Kong");
|
||||||
|
player.setLocation(1);
|
||||||
|
return true;
|
||||||
|
case 2:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai");
|
||||||
|
player.setLocation(2);
|
||||||
|
return true;
|
||||||
|
case 3:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki");
|
||||||
|
player.setLocation(3);
|
||||||
|
return true;
|
||||||
|
case 4:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon");
|
||||||
|
player.setLocation(4);
|
||||||
|
return true;
|
||||||
|
case 5:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Manila");
|
||||||
|
player.setLocation(5);
|
||||||
|
return true;
|
||||||
|
case 6:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore");
|
||||||
|
player.setLocation(6);
|
||||||
|
return true;
|
||||||
|
case 7:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia");
|
||||||
|
player.setLocation(7);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
textOut.setText(" " + "Sorry but could you say that again " + player.getName() + "?");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on random chance either attacks the player with enemy ships, throws them to a different location or does nothing.
|
||||||
|
*
|
||||||
|
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
|
||||||
|
* by a typhoon.
|
||||||
|
**/
|
||||||
|
private void randomEventSea(int locationOfTravel, Stage stage) {
|
||||||
|
Random rand = new Random();
|
||||||
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
if (randGenNum == 1) {
|
||||||
|
continueButton.setVisible(true);
|
||||||
|
quitButton.setVisible(false);
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
peasantShipScene = true;
|
||||||
|
textOut.setText(" We see a ship on the horizon " + player.getName() + "; Prepare for combat!");
|
||||||
|
//System.out.println(textOut.getText() + "\n " + "PLACEHOLDER FOR SHIPWARFARE");
|
||||||
|
}else if (randGenNum == 2) {
|
||||||
|
stormScene = true;
|
||||||
|
disaster(locationOfTravel);
|
||||||
|
textOut.setText(textOut.getText() + "\n " + "We made it!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on random chance either throws the player character off course, or continues them on their way to their
|
||||||
|
* destination.
|
||||||
|
*
|
||||||
|
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
|
||||||
|
* by a typhoon.
|
||||||
|
**/
|
||||||
|
private void disaster(int locationOfTravel) {
|
||||||
|
//Tells player that there is a storm approaching.
|
||||||
|
textOut.setText(" " + "Storm " + player.getName() + "! ");
|
||||||
|
Random rand = new Random();
|
||||||
|
int randGenNum = rand.nextInt(5) + 1;
|
||||||
|
|
||||||
|
//If the player lands within this range, nothing happens to them
|
||||||
|
//Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel).
|
||||||
|
if (randGenNum <= 2) {
|
||||||
|
textOut.setText(textOut.getText() + "\n " + "We got through the storm " + player.getName() + "!");
|
||||||
|
}else {
|
||||||
|
while (randGenNum == locationOfTravel) {
|
||||||
|
randGenNum = rand.nextInt(7) + 1;
|
||||||
|
if (randGenNum != locationOfTravel) {
|
||||||
|
textOut.setText(textOut.getText() + "\n " + "We've been blown off course!");
|
||||||
|
seaAtlas(randGenNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts the user's location (an integer) to a String, and returns it.
|
||||||
|
*
|
||||||
|
* @return location -- the user's location as a string; the actual name of the location.
|
||||||
|
*/
|
||||||
|
public String getStringLocation(){
|
||||||
|
String location;
|
||||||
|
switch(player.getLocation()){
|
||||||
|
case 1: location = "Hong Kong"; break;
|
||||||
|
case 2: location = "Shanghai"; break;
|
||||||
|
case 3: location = "Nagasaki"; break;
|
||||||
|
case 4: location = "Saigon"; break;
|
||||||
|
case 5: location = "Manila"; break;
|
||||||
|
case 6: location = "Singapore"; break;
|
||||||
|
case 7: location = "Batavia"; break;
|
||||||
|
default: location = "Error"; break;
|
||||||
|
}
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the user's condition based upon their current HP.
|
||||||
|
*
|
||||||
|
* @return shipStatus -- a representation of their ship's health in words.
|
||||||
|
*/
|
||||||
|
public String shipStatusString(){
|
||||||
|
String shipStatus;
|
||||||
|
switch(player.getHP()/10){
|
||||||
|
case 10: shipStatus = "Mint Condition"; break;
|
||||||
|
case 9: shipStatus = "Near Perfect"; break;
|
||||||
|
case 8: shipStatus = "Great"; break;
|
||||||
|
case 7: shipStatus = "Good"; break;
|
||||||
|
case 6: shipStatus = "Acceptable"; break;
|
||||||
|
case 5: shipStatus = "Tolerable"; break;
|
||||||
|
case 4: shipStatus = "Needs Repair"; break;
|
||||||
|
case 3: shipStatus = "Damaged"; break;
|
||||||
|
case 2: shipStatus = "Indangered"; break;
|
||||||
|
case 1: shipStatus = "Near Sinking"; break;
|
||||||
|
case 0: shipStatus = "Sinking"; break;
|
||||||
|
default: shipStatus = "Invincible"; break;
|
||||||
|
}
|
||||||
|
return shipStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates the text associated with the user's inventory.
|
||||||
|
*/
|
||||||
|
public void updateStage(){
|
||||||
|
firm.setText(String.format("Firm: %s, %s", player.getName(), getStringLocation()));
|
||||||
|
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", player.getwOpium(), player.getwSilk(), player.getwArms(), player.getwGeneral()));
|
||||||
|
int itemsInWarehouse = player.getwOpium()+player.getwGeneral()+player.getwArms()+player.getwSilk();
|
||||||
|
wItemSpaceText.setText(String.format("\n\t\tIn use:\n\t\t %d \n\t\tVacant:\n\t\t %d", itemsInWarehouse, (10000-itemsInWarehouse)));
|
||||||
|
locationText.setText(String.format("Location\n%s", getStringLocation()));
|
||||||
|
int itemsInInventory = player.getCargoSpace()-player.getSilkHeld()-player.getOpiumHeld()-player.getGeneralHeld()-player.getArmsHeld()-10*player.getGuns();
|
||||||
|
if(itemsInInventory < 0){
|
||||||
|
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
|
||||||
|
}else{
|
||||||
|
inventoryText.setText(String.format(" Hold %d\n\t Opium\n\t Silk\n\t Arms\n\t General", itemsInInventory));
|
||||||
|
}
|
||||||
|
gunsText.setText(String.format("Guns %d\n\n\n\n ", player.getGuns()));
|
||||||
|
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", player.getOpiumHeld(), player.getSilkHeld(), player.getArmsHeld(), player.getGeneralHeld()));
|
||||||
|
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", player.getDebt(), shipStatusString(), player.getHP()));
|
||||||
|
cashText.setText(String.format(" Cash: $%,d", player.getMoney()));
|
||||||
|
bankText.setText(String.format("Bank: %d", player.getBank()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Warehouse {
|
|
||||||
/*private int wOpium = 0;
|
|
||||||
private int wSilk = 0;
|
|
||||||
private int wGeneral = 0;
|
|
||||||
private int wArms = 0;*/
|
|
||||||
private Player player;
|
|
||||||
|
|
||||||
|
|
||||||
public void setPlayer(Player player) {
|
|
||||||
Player playerDumy = new Player(player);
|
|
||||||
this.player = playerDumy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
return playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Warehouse(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void addAmount() {
|
|
||||||
boolean askGood = false;
|
|
||||||
String amount;
|
|
||||||
int finalAmount = 0;
|
|
||||||
System.out.println("Please enter the amount of the good you would like to ADD.");
|
|
||||||
Scanner keyboard = new Scanner(System.in);
|
|
||||||
amount = keyboard.nextLine();
|
|
||||||
try {
|
|
||||||
if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) {
|
|
||||||
finalAmount = Integer.parseInt(amount);
|
|
||||||
askGood = true;
|
|
||||||
} else {
|
|
||||||
System.out.println("Nice try but you don't have any items of that quantity!");
|
|
||||||
askGood = false;
|
|
||||||
}
|
|
||||||
if (askGood == true) {
|
|
||||||
String good;
|
|
||||||
System.out.println("Please enter a good to transfer O, S, G, A :");
|
|
||||||
good = keyboard.nextLine();
|
|
||||||
int held = 0;
|
|
||||||
if (Integer.parseInt(amount) > 0) {
|
|
||||||
if (good.equalsIgnoreCase("O")) {
|
|
||||||
if (player.getOpiumHeld() >= Integer.parseInt(amount)) {
|
|
||||||
player.setwOpium(player.getwOpium() + finalAmount);
|
|
||||||
held = player.getOpiumHeld();
|
|
||||||
player.setOpiumHeld(held - finalAmount);
|
|
||||||
System.out.println(player.getOpiumHeld());
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't even have that much opium!");
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("S")) {
|
|
||||||
if (player.getSilkHeld() >= Integer.parseInt(amount)) {
|
|
||||||
player.setwSilk(player.getwSilk() + finalAmount);
|
|
||||||
held = player.getSilkHeld();
|
|
||||||
player.setSilkHeld(held - finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't even have that much silk!");
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("G")) {
|
|
||||||
if (player.getGeneralHeld() >= Integer.parseInt(amount)) {
|
|
||||||
player.setwGeneral(player.getwGeneral() + finalAmount);
|
|
||||||
held = player.getGeneralHeld();
|
|
||||||
player.setGeneralHeld(held - finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't even have that much general cargo!");
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("A")) {
|
|
||||||
if (player.getArmsHeld() >= Integer.parseInt(amount)) {
|
|
||||||
player.setwArms(player.getwArms() + finalAmount);
|
|
||||||
held = player.getArmsHeld();
|
|
||||||
player.setArmsHeld(held - finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't even have that much Arms!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("Sorry this transfer cannot be made");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Wait, that's not a valid input please try again");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeAmount() {
|
|
||||||
String amount;
|
|
||||||
boolean askGood = false;
|
|
||||||
int finalAmount = 0;
|
|
||||||
System.out.println("Please enter the amount of the good you would like to REMOVE");
|
|
||||||
Scanner keyboard = new Scanner(System.in);
|
|
||||||
amount = keyboard.nextLine();
|
|
||||||
try {
|
|
||||||
if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) {
|
|
||||||
finalAmount = Integer.parseInt(amount);
|
|
||||||
askGood = true;
|
|
||||||
} else {
|
|
||||||
System.out.println("Nice try but you don't have any items of that quantity in the warehouse!");
|
|
||||||
askGood = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (askGood == true) {
|
|
||||||
String good;
|
|
||||||
System.out.println("Please enter a good to transfer O, S, G, A :");
|
|
||||||
good = keyboard.nextLine();
|
|
||||||
int held = 0;
|
|
||||||
if (Integer.parseInt(amount) > 0) {
|
|
||||||
if (good.equalsIgnoreCase("O")) {
|
|
||||||
if (player.getwOpium() >= Integer.parseInt(amount)) {
|
|
||||||
player.setwOpium(player.getwOpium() - Integer.parseInt(amount));
|
|
||||||
held = player.getOpiumHeld();
|
|
||||||
player.setOpiumHeld(held + finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't have that much opium stored in the warehouse!");
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("S")) {
|
|
||||||
if (player.getwSilk() >= Integer.parseInt(amount)) {
|
|
||||||
player.setwSilk(player.getwSilk() - Integer.parseInt(amount));
|
|
||||||
held = player.getSilkHeld();
|
|
||||||
player.setSilkHeld(held + finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't have that much silk stored in the warehouse!");
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("G")) {
|
|
||||||
if (player.getwGeneral() >= Integer.parseInt(amount)) {
|
|
||||||
player.setwGeneral(player.getwGeneral() - Integer.parseInt(amount));
|
|
||||||
held = player.getGeneralHeld();
|
|
||||||
player.setGeneralHeld(held + finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't have that much general cargo stored in the warehouse!");
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (good.equalsIgnoreCase("A")) {
|
|
||||||
if (player.getwArms() >= Integer.parseInt(amount)) {
|
|
||||||
player.setwArms(player.getwArms() - Integer.parseInt(amount));
|
|
||||||
held = player.getArmsHeld();
|
|
||||||
player.setArmsHeld(held + finalAmount);
|
|
||||||
} else {
|
|
||||||
System.out.println("You don't have that much arms stored in the warehouse!");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("Sorry this transfer cannot be made");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
System.out.println("Wait, that's not a valid input please try again");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void showWarehouse() {
|
|
||||||
System.out.println("--------------------\nWarehouse\n--------------------");
|
|
||||||
System.out.println("Opium : " + player.getwOpium());
|
|
||||||
System.out.println("Silk : " + player.getwSilk());
|
|
||||||
System.out.println("General : " + player.getwGeneral());
|
|
||||||
System.out.println("Arms : " + player.getwArms());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void changeWarehouse() {
|
|
||||||
boolean keepGoing = true;
|
|
||||||
while (keepGoing) {
|
|
||||||
this.showWarehouse();
|
|
||||||
String input = " ";
|
|
||||||
System.out.println("Would you like to add(A) or remove(R) resources? ");
|
|
||||||
Scanner keyboard = new Scanner(System.in);
|
|
||||||
input = keyboard.next();
|
|
||||||
if (input.equalsIgnoreCase("R")) {
|
|
||||||
this.removeAmount();
|
|
||||||
this.showWarehouse();
|
|
||||||
} else if (input.equalsIgnoreCase("A")) {
|
|
||||||
this.addAmount();
|
|
||||||
this.showWarehouse();
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
System.out.println("Don't waste the warehouse's time, try again later with a valid input");
|
|
||||||
}
|
|
||||||
|
|
||||||
String check;
|
|
||||||
System.out.println("Would you like to do any other business? Y / N?");
|
|
||||||
check = keyboard.nextLine();
|
|
||||||
check = keyboard.nextLine();
|
|
||||||
|
|
||||||
if (check.equalsIgnoreCase("Y")) {
|
|
||||||
keepGoing = true;
|
|
||||||
} else if (check.equalsIgnoreCase("N")) {
|
|
||||||
keepGoing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
638
src/WarehouseGUI.java
Normal file
638
src/WarehouseGUI.java
Normal file
@@ -0,0 +1,638 @@
|
|||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.scene.text.Text;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that makes the GUI for the Warehouse class.
|
||||||
|
*/
|
||||||
|
public class WarehouseGUI {
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
private Text title;
|
||||||
|
private HBox hBox;
|
||||||
|
private Button withdraw;
|
||||||
|
private Button deposit;
|
||||||
|
private Button goBack;
|
||||||
|
private VBox vBox;
|
||||||
|
private Text playerName;
|
||||||
|
private Text text;
|
||||||
|
private Label opiumPlayer;
|
||||||
|
private Label silkPlayer;
|
||||||
|
private Label armsPlayer;
|
||||||
|
private Label generalPlayer;
|
||||||
|
private VBox vBox0;
|
||||||
|
private Text text0;
|
||||||
|
private Text text1;
|
||||||
|
private Text opiumWarehouse;
|
||||||
|
private Text silkWarehouse;
|
||||||
|
private Text armsWarehouse;
|
||||||
|
private Text generalWarehouse;
|
||||||
|
private VBox vBox1;
|
||||||
|
private Text inUseWarehouse;
|
||||||
|
private Text vacantWarehouse;
|
||||||
|
private BorderPane borderPane;
|
||||||
|
private TextField textIn;
|
||||||
|
private SplitMenuButton splitMenu;
|
||||||
|
private CheckMenuItem general;
|
||||||
|
private CheckMenuItem arms;
|
||||||
|
private CheckMenuItem silk;
|
||||||
|
private CheckMenuItem opium;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A constructor that takes an object of type Player as an argument
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public WarehouseGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter method for the Player object, player
|
||||||
|
*
|
||||||
|
* @param player an object of type Player
|
||||||
|
*/
|
||||||
|
public void setPlayer(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.player = playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter method for the Player object, player.
|
||||||
|
*
|
||||||
|
* @return returns a copy of the Player object, player
|
||||||
|
*/
|
||||||
|
public Player getPlayer() {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
return playerDummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initializes the GUI for the warehouse aspect of our game.
|
||||||
|
*
|
||||||
|
* @param stage an object of type Stage
|
||||||
|
* @return returns the stage of the GUI
|
||||||
|
*/
|
||||||
|
public Stage initializeWarehouse(Stage stage) {
|
||||||
|
|
||||||
|
title = new Text();
|
||||||
|
hBox = new HBox();
|
||||||
|
withdraw = new Button();
|
||||||
|
deposit = new Button();
|
||||||
|
vBox = new VBox();
|
||||||
|
playerName = new Text();
|
||||||
|
text = new Text();
|
||||||
|
opiumPlayer = new Label();
|
||||||
|
silkPlayer = new Label();
|
||||||
|
armsPlayer = new Label();
|
||||||
|
generalPlayer = new Label();
|
||||||
|
vBox0 = new VBox();
|
||||||
|
text0 = new Text();
|
||||||
|
text1 = new Text();
|
||||||
|
opiumWarehouse = new Text();
|
||||||
|
silkWarehouse = new Text();
|
||||||
|
armsWarehouse = new Text();
|
||||||
|
generalWarehouse = new Text();
|
||||||
|
vBox1 = new VBox();
|
||||||
|
inUseWarehouse = new Text();
|
||||||
|
vacantWarehouse = new Text();
|
||||||
|
borderPane = new BorderPane();
|
||||||
|
textIn = new TextField();
|
||||||
|
splitMenu = new SplitMenuButton();
|
||||||
|
general = new CheckMenuItem();
|
||||||
|
arms = new CheckMenuItem();
|
||||||
|
silk = new CheckMenuItem();
|
||||||
|
opium = new CheckMenuItem();
|
||||||
|
|
||||||
|
borderPane.setPrefHeight(480.0);
|
||||||
|
borderPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the preferred width and height of the borderpane window to 600 by 480.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
borderPane.setPrefHeight(480.0);
|
||||||
|
borderPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label "Hong Kong Warehouse: at the top of the borderpane.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BorderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
|
||||||
|
|
||||||
|
title.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
title.setStrokeWidth(0.0);
|
||||||
|
title.setText("Hong Kong Warehouse");
|
||||||
|
title.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
title.setWrappingWidth(393.63671875);
|
||||||
|
title.setFont(new Font(24.0));
|
||||||
|
borderPane.setPrefHeight(480.0);
|
||||||
|
borderPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
BorderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
|
||||||
|
title.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
title.setStrokeWidth(0.0);
|
||||||
|
title.setText("Hong Kong Warehouse");
|
||||||
|
title.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
title.setWrappingWidth(393.63671875);
|
||||||
|
title.setFont(new Font(24.0));
|
||||||
|
borderPane.setTop(title);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates an HBox at the center of the borderpane with a width of 200 and height of 100.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setPrefHeight(100.0);
|
||||||
|
hBox.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a button with text "Withdraw" which handles user events.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
withdraw.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
withdraw.setMnemonicParsing(false);
|
||||||
|
withdraw.setText("Withdraw");
|
||||||
|
updateLabels();
|
||||||
|
withdraw.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
/**
|
||||||
|
* Creates a button with text "Deposit" which handles user events.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
|
||||||
|
int withdraw = Integer.parseInt(textIn.getText());
|
||||||
|
updateLabels();
|
||||||
|
if (opium.isSelected()) {
|
||||||
|
if (player.getwOpium() >= withdraw) {
|
||||||
|
player.setwOpium(player.getwOpium() - withdraw);
|
||||||
|
player.setOpiumHeld(player.getOpiumHeld() + withdraw);
|
||||||
|
} else {
|
||||||
|
title.setText("You don't have that much opium stored in the warehouse!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (silk.isSelected()) {
|
||||||
|
if (player.getwSilk() >= withdraw) {
|
||||||
|
player.setwSilk(player.getwSilk() - withdraw);
|
||||||
|
player.setSilkHeld(player.getSilkHeld() + withdraw);
|
||||||
|
} else {
|
||||||
|
title.setText("You don't have that much silk stored in the warehouse!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (arms.isSelected()) {
|
||||||
|
if (player.getwArms() >= withdraw) {
|
||||||
|
player.setwArms(player.getwArms() - withdraw);
|
||||||
|
player.setArmsHeld(player.getArmsHeld() + withdraw);
|
||||||
|
} else {
|
||||||
|
title.setText("You don't have that much arms stored in the warehouse!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (general.isSelected()) {
|
||||||
|
if (player.getwGeneral() >= withdraw) {
|
||||||
|
player.setwGeneral(player.getwGeneral() - withdraw);
|
||||||
|
player.setGeneralHeld(player.getGeneralHeld() + withdraw);
|
||||||
|
} else {
|
||||||
|
title.setText("You don't have that much general stored in the warehouse!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
deposit.setMnemonicParsing(false);
|
||||||
|
deposit.setText("Deposit");
|
||||||
|
deposit.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
borderPane.setBottom(hBox);
|
||||||
|
|
||||||
|
deposit.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
updateLabels();
|
||||||
|
int deposit = Integer.parseInt(textIn.getText());
|
||||||
|
if (opium.isSelected()) {
|
||||||
|
if (player.getOpiumHeld() >= deposit) {
|
||||||
|
player.setwOpium(player.getwOpium() + deposit);
|
||||||
|
player.setOpiumHeld(player.getOpiumHeld() - deposit);
|
||||||
|
} else {
|
||||||
|
title.setText("You don't have that much opium stored in the ship!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (silk.isSelected()) {
|
||||||
|
if (player.getwSilk() >= deposit) {
|
||||||
|
player.setwSilk(player.getwSilk() + deposit);
|
||||||
|
player.setSilkHeld(player.getSilkHeld() - deposit);
|
||||||
|
} else {
|
||||||
|
title.setText("You don't have that much silk stored in the ship!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (arms.isSelected()) {
|
||||||
|
if (player.getwArms() >= deposit) {
|
||||||
|
player.setwArms(player.getwArms() + deposit);
|
||||||
|
player.setArmsHeld(player.getArmsHeld() - deposit);
|
||||||
|
} else {
|
||||||
|
title.setText("You don't have that much arms stored in the ship!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (general.isSelected()) {
|
||||||
|
if (player.getwGeneral() >= deposit) {
|
||||||
|
player.setwGeneral(player.getwGeneral() + deposit);
|
||||||
|
player.setGeneralHeld(player.getGeneralHeld() - deposit);
|
||||||
|
} else {
|
||||||
|
title.setText("You don't have that much general stored in the ship!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
splitMenu.setMnemonicParsing(false);
|
||||||
|
splitMenu.setText("Item");
|
||||||
|
|
||||||
|
general.setMnemonicParsing(false);
|
||||||
|
general.setText("General");
|
||||||
|
|
||||||
|
arms.setMnemonicParsing(false);
|
||||||
|
arms.setText("Arms");
|
||||||
|
|
||||||
|
silk.setMnemonicParsing(false);
|
||||||
|
silk.setText("Silk");
|
||||||
|
|
||||||
|
opium.setMnemonicParsing(false);
|
||||||
|
opium.setText("Opium");
|
||||||
|
borderPane.setBottom(hBox);
|
||||||
|
|
||||||
|
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER_LEFT);
|
||||||
|
vBox.setPrefHeight(156.0);
|
||||||
|
vBox.setPrefWidth(106.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Player" with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
playerName.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
playerName.setStrokeWidth(0.0);
|
||||||
|
playerName.setText("Player");
|
||||||
|
playerName.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
playerName.setWrappingWidth(103.47265625);
|
||||||
|
playerName.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with no text for aesthetic spacing purposes.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
text.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
text.setStrokeWidth(0.0);
|
||||||
|
text.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
text.setWrappingWidth(103.47265625);
|
||||||
|
text.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Opium" under the "Player" label with size 18 font and default font style
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
opiumPlayer.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
opiumPlayer.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
opiumPlayer.setPrefWidth(100.0);
|
||||||
|
opiumPlayer.setText("Opium");
|
||||||
|
opiumPlayer.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
opiumPlayer.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Silk" under the "Player" label with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
silkPlayer.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
silkPlayer.setPrefWidth(100.0);
|
||||||
|
silkPlayer.setText("Silk");
|
||||||
|
silkPlayer.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Arms" under the "Player" label with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
armsPlayer.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
armsPlayer.setPrefWidth(100.0);
|
||||||
|
armsPlayer.setText("Arms");
|
||||||
|
armsPlayer.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "General" under the "Player" label with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
generalPlayer.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
generalPlayer.setPrefWidth(100.0);
|
||||||
|
generalPlayer.setText("General");
|
||||||
|
generalPlayer.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
generalPlayer.setFont(new Font(18.0));
|
||||||
|
borderPane.setLeft(vBox);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a VBox at the center of the borderpane with a width of 261 and a height of 343.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BorderPane.setAlignment(vBox0, javafx.geometry.Pos.TOP_LEFT);
|
||||||
|
vBox0.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
vBox0.setPrefHeight(343.0);
|
||||||
|
vBox0.setPrefWidth(261.0);
|
||||||
|
|
||||||
|
text0.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
text0.setStrokeWidth(0.0);
|
||||||
|
text0.setText("Warehouse");
|
||||||
|
text0.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
text0.setWrappingWidth(103.47265625);
|
||||||
|
text0.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
text1.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
text1.setStrokeWidth(0.0);
|
||||||
|
text1.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
text1.setWrappingWidth(103.47265625);
|
||||||
|
text1.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
opiumWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
opiumWarehouse.setStrokeWidth(0.0);
|
||||||
|
opiumWarehouse.setText("Opium");
|
||||||
|
opiumWarehouse.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
opiumWarehouse.setWrappingWidth(103.47265625);
|
||||||
|
opiumWarehouse.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
silkWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
silkWarehouse.setStrokeWidth(0.0);
|
||||||
|
silkWarehouse.setText("Silk");
|
||||||
|
silkWarehouse.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
silkWarehouse.setWrappingWidth(103.47265625);
|
||||||
|
silkWarehouse.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
armsWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
armsWarehouse.setStrokeWidth(0.0);
|
||||||
|
armsWarehouse.setText("Arms");
|
||||||
|
armsWarehouse.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
armsWarehouse.setWrappingWidth(103.47265625);
|
||||||
|
armsWarehouse.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
generalWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
generalWarehouse.setStrokeWidth(0.0);
|
||||||
|
generalWarehouse.setText("General");
|
||||||
|
generalWarehouse.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
generalWarehouse.setWrappingWidth(103.47265625);
|
||||||
|
generalWarehouse.setFont(new Font(18.0));
|
||||||
|
borderPane.setCenter(vBox0);
|
||||||
|
|
||||||
|
BorderPane.setAlignment(vBox1, javafx.geometry.Pos.CENTER);
|
||||||
|
vBox1.setPrefHeight(48.0);
|
||||||
|
vBox1.setPrefWidth(152.0);
|
||||||
|
|
||||||
|
inUseWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
inUseWarehouse.setStrokeWidth(0.0);
|
||||||
|
inUseWarehouse.setText("In use:");
|
||||||
|
inUseWarehouse.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
vacantWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
vacantWarehouse.setStrokeWidth(0.0);
|
||||||
|
vacantWarehouse.setText("Vacant:");
|
||||||
|
vacantWarehouse.setFont(new Font(18.0));
|
||||||
|
borderPane.setRight(vBox1);
|
||||||
|
borderPane.setTop(title);
|
||||||
|
|
||||||
|
BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
hBox.setPrefHeight(100.0);
|
||||||
|
hBox.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
withdraw.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
withdraw.setMnemonicParsing(false);
|
||||||
|
withdraw.setText("Withdraw");
|
||||||
|
|
||||||
|
deposit.setMnemonicParsing(false);
|
||||||
|
deposit.setText("Deposit");
|
||||||
|
deposit.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
|
||||||
|
splitMenu.setMnemonicParsing(false);
|
||||||
|
splitMenu.setText("Item");
|
||||||
|
|
||||||
|
general.setMnemonicParsing(false);
|
||||||
|
general.setText("General");
|
||||||
|
|
||||||
|
arms.setMnemonicParsing(false);
|
||||||
|
arms.setText("Arms");
|
||||||
|
|
||||||
|
silk.setMnemonicParsing(false);
|
||||||
|
silk.setText("Silk");
|
||||||
|
|
||||||
|
opium.setMnemonicParsing(false);
|
||||||
|
opium.setText("Opium");
|
||||||
|
borderPane.setBottom(hBox);
|
||||||
|
|
||||||
|
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER_LEFT);
|
||||||
|
vBox.setPrefHeight(156.0);
|
||||||
|
vBox.setPrefWidth(106.0);
|
||||||
|
|
||||||
|
playerName.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
playerName.setStrokeWidth(0.0);
|
||||||
|
playerName.setText("Player");
|
||||||
|
playerName.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
playerName.setWrappingWidth(103.47265625);
|
||||||
|
playerName.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
text.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
text.setStrokeWidth(0.0);
|
||||||
|
text.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
text.setWrappingWidth(103.47265625);
|
||||||
|
text.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
opiumPlayer.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
opiumPlayer.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
|
opiumPlayer.setPrefWidth(100.0);
|
||||||
|
opiumPlayer.setText("Opium");
|
||||||
|
opiumPlayer.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
opiumPlayer.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
silkPlayer.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
silkPlayer.setPrefWidth(100.0);
|
||||||
|
silkPlayer.setText("Silk");
|
||||||
|
silkPlayer.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
armsPlayer.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
armsPlayer.setPrefWidth(100.0);
|
||||||
|
armsPlayer.setText("Arms");
|
||||||
|
armsPlayer.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
generalPlayer.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
generalPlayer.setPrefWidth(100.0);
|
||||||
|
generalPlayer.setText("General");
|
||||||
|
generalPlayer.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
generalPlayer.setFont(new Font(18.0));
|
||||||
|
borderPane.setLeft(vBox);
|
||||||
|
|
||||||
|
BorderPane.setAlignment(vBox0, javafx.geometry.Pos.TOP_LEFT);
|
||||||
|
vBox0.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
|
vBox0.setPrefHeight(343.0);
|
||||||
|
vBox0.setPrefWidth(261.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Warehouse" with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
text0.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
text0.setStrokeWidth(0.0);
|
||||||
|
text0.setText("Warehouse");
|
||||||
|
text0.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
text0.setWrappingWidth(103.47265625);
|
||||||
|
text0.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with no text for aesthetic spacing purposes.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
text1.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
text1.setStrokeWidth(0.0);
|
||||||
|
text1.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
text1.setWrappingWidth(103.47265625);
|
||||||
|
text1.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Opium" under the "Warehouse" label with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
opiumWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
opiumWarehouse.setStrokeWidth(0.0);
|
||||||
|
opiumWarehouse.setText("Opium");
|
||||||
|
opiumWarehouse.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
opiumWarehouse.setWrappingWidth(103.47265625);
|
||||||
|
opiumWarehouse.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Silk" under the "Warehouse" label with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
silkWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
silkWarehouse.setStrokeWidth(0.0);
|
||||||
|
silkWarehouse.setText("Silk");
|
||||||
|
silkWarehouse.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
silkWarehouse.setWrappingWidth(103.47265625);
|
||||||
|
silkWarehouse.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "Arms" under the "Warehouse" label with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
armsWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
armsWarehouse.setStrokeWidth(0.0);
|
||||||
|
armsWarehouse.setText("Arms");
|
||||||
|
armsWarehouse.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
armsWarehouse.setWrappingWidth(103.47265625);
|
||||||
|
armsWarehouse.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with text "General" under the "Warehouse" label with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
generalWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
generalWarehouse.setStrokeWidth(0.0);
|
||||||
|
generalWarehouse.setText("General");
|
||||||
|
generalWarehouse.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
|
generalWarehouse.setWrappingWidth(103.47265625);
|
||||||
|
generalWarehouse.setFont(new Font(18.0));
|
||||||
|
borderPane.setCenter(vBox0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a VBox at the center of the borderpane with a width of 152 and a height of 48.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BorderPane.setAlignment(vBox1, javafx.geometry.Pos.CENTER);
|
||||||
|
vBox1.setPrefHeight(48.0);
|
||||||
|
vBox1.setPrefWidth(152.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with "In use:" text with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
inUseWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
inUseWarehouse.setStrokeWidth(0.0);
|
||||||
|
inUseWarehouse.setText("In use:");
|
||||||
|
inUseWarehouse.setFont(new Font(18.0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a label with "Vacant:" text with size 18 font and default font style.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
vacantWarehouse.setStrokeType(javafx.scene.shape.StrokeType.OUTSIDE);
|
||||||
|
vacantWarehouse.setStrokeWidth(0.0);
|
||||||
|
vacantWarehouse.setText("Vacant:");
|
||||||
|
vacantWarehouse.setFont(new Font(18.0));
|
||||||
|
borderPane.setRight(vBox1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds all the labels and buttons to their respective boxes.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
splitMenu.getItems().add(general);
|
||||||
|
splitMenu.getItems().add(arms);
|
||||||
|
splitMenu.getItems().add(silk);
|
||||||
|
splitMenu.getItems().add(opium);
|
||||||
|
hBox.getChildren().add(textIn);
|
||||||
|
hBox.getChildren().add(withdraw);
|
||||||
|
hBox.getChildren().add(deposit);
|
||||||
|
hBox.getChildren().add(splitMenu);
|
||||||
|
vBox.getChildren().add(playerName);
|
||||||
|
vBox.getChildren().add(text);
|
||||||
|
vBox.getChildren().add(opiumPlayer);
|
||||||
|
vBox.getChildren().add(silkPlayer);
|
||||||
|
vBox.getChildren().add(armsPlayer);
|
||||||
|
vBox.getChildren().add(generalPlayer);
|
||||||
|
vBox0.getChildren().add(text0);
|
||||||
|
vBox0.getChildren().add(text1);
|
||||||
|
vBox0.getChildren().add(opiumWarehouse);
|
||||||
|
vBox0.getChildren().add(silkWarehouse);
|
||||||
|
vBox0.getChildren().add(armsWarehouse);
|
||||||
|
vBox0.getChildren().add(generalWarehouse);
|
||||||
|
vBox1.getChildren().add(inUseWarehouse);
|
||||||
|
vBox1.getChildren().add(vacantWarehouse);
|
||||||
|
|
||||||
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
|
|
||||||
|
stage.setTitle("Warehouse");
|
||||||
|
stage.setResizable(false);
|
||||||
|
stage.setScene(root);
|
||||||
|
updateLabels();
|
||||||
|
|
||||||
|
return stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When run, shows the stage as a graphical interface through JavaFX.
|
||||||
|
*
|
||||||
|
* @param primaryStage object of type Stage
|
||||||
|
*/
|
||||||
|
public void start(Stage primaryStage) {
|
||||||
|
WarehouseGUI warehouseGUI = new WarehouseGUI(player);
|
||||||
|
warehouseGUI.initializeWarehouse(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The purpose of this class is to create a warehouse where the goods
|
||||||
|
* can be safely stored without holing space on the ship!
|
||||||
|
*/
|
||||||
|
public void updateLabels() {
|
||||||
|
generalPlayer.setText("General: " + player.getGeneralHeld());
|
||||||
|
armsPlayer.setText("Arms: " + player.getArmsHeld());
|
||||||
|
silkPlayer.setText("Silk: " + player.getSilkHeld());
|
||||||
|
opiumPlayer.setText("Opium: " + player.getOpiumHeld());
|
||||||
|
|
||||||
|
generalWarehouse.setText("General: " + player.getwGeneral());
|
||||||
|
armsWarehouse.setText("Arms: " + player.getwArms());
|
||||||
|
silkWarehouse.setText("Silk: " + player.getwSilk());
|
||||||
|
opiumWarehouse.setText("Opium: " + player.getwOpium());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class loanShark {
|
|
||||||
private Player player;
|
|
||||||
public void setPlayer(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer(){
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
return playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public loanShark(Player player){
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
this.player = playerDummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loanMoney() {
|
|
||||||
boolean keepGoing = true;
|
|
||||||
while(keepGoing) {
|
|
||||||
String check;
|
|
||||||
Scanner keyboard = new Scanner(System.in);
|
|
||||||
System.out.println("Would you like to return money or borrow money?");
|
|
||||||
check = keyboard.nextLine();
|
|
||||||
if(check.equalsIgnoreCase("r")){
|
|
||||||
int returnAsk = 0;
|
|
||||||
System.out.println("Please enter how much you would like to return?");
|
|
||||||
returnAsk = keyboard.nextInt();
|
|
||||||
if(returnAsk <= player.getDebt() && returnAsk >= 0) {
|
|
||||||
player.setDebt(player.getDebt() - returnAsk);
|
|
||||||
player.setMoney(player.getMoney() - returnAsk);
|
|
||||||
}//updated
|
|
||||||
else if(returnAsk > player.getDebt()){
|
|
||||||
System.out.println("You don't need to return that much!");
|
|
||||||
}else{
|
|
||||||
System.out.println("You can't return a negative amount.");
|
|
||||||
}
|
|
||||||
}else if(check.equalsIgnoreCase("b")){
|
|
||||||
int loanAsk = 0;
|
|
||||||
System.out.println("Please enter how much you would like to borrow");
|
|
||||||
loanAsk = keyboard.nextInt();
|
|
||||||
if(loanAsk <= 2*(player.getMoney() - player.getDebt())&& loanAsk >= 0) {
|
|
||||||
player.setDebt(player.getDebt() + loanAsk);
|
|
||||||
player.setMoney(player.getMoney() + loanAsk);
|
|
||||||
}//updated
|
|
||||||
else{
|
|
||||||
System.out.println("Sorry you can't be loaned that much");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Would you like to do any other business? Y / N?");
|
|
||||||
check = keyboard.nextLine();
|
|
||||||
check = keyboard.nextLine();
|
|
||||||
|
|
||||||
if(check.equalsIgnoreCase("Y")) {
|
|
||||||
keepGoing = true;
|
|
||||||
}
|
|
||||||
else if(check.equalsIgnoreCase("N")) {
|
|
||||||
keepGoing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
public class main {
|
|
||||||
|
|
||||||
private Player player = new Player();
|
|
||||||
|
|
||||||
public Player getPlayer(){
|
|
||||||
Player copy = new Player(player);
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shop(TaipanShop shop){
|
|
||||||
shop.setPlayer(player);
|
|
||||||
shop.shop();
|
|
||||||
player = shop.getPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start(Start start){
|
|
||||||
start.setPlayer(player);
|
|
||||||
start.intialize();
|
|
||||||
player = start.getPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
main main = new main();
|
|
||||||
TaipanShop littyShop = new TaipanShop(main.getPlayer());
|
|
||||||
Start start = new Start(main.getPlayer());
|
|
||||||
|
|
||||||
main.start(start);
|
|
||||||
while(!main.getPlayer().getRetire()){
|
|
||||||
main.shop(littyShop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user