Compare commits
68 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49a62c4a4d | ||
|
|
f0416db9c2 | ||
|
|
2d4a1add07 | ||
|
|
984beaabf9 | ||
|
|
b697978614 | ||
| 805341797f | |||
| 6c411b6c3b | |||
| 8222cdaecb | |||
| f89c1aa209 | |||
| 03ff12b832 | |||
|
|
b4f9ce761c | ||
|
|
0b5df085bf | ||
|
|
44f1ee5b2a | ||
|
|
0086abb2a7 | ||
|
|
0221a5a2f1 | ||
|
|
7134a6825e | ||
|
|
74f0f31a46 | ||
|
|
c6b34f49b3 | ||
|
|
36a89bc713 | ||
|
|
dbf92288c5 | ||
| 7ca1e3e4a3 | |||
|
|
ff4dd2b733 | ||
|
|
4ec469de7d | ||
|
|
a2c7d7dd67 | ||
| ea5faaca36 | |||
| a2e3879cae | |||
|
|
784272e362 | ||
|
|
e6b8ac33ef | ||
|
|
1d47933bae | ||
|
|
195c3793db | ||
| 3f68202bb5 | |||
| 26064ebac3 | |||
| f37aa91fad | |||
| e2ad32c4ee | |||
|
|
9e97877e6e | ||
|
|
f834afb98f | ||
|
|
fff5456b45 | ||
|
|
548448bda1 | ||
| ea591057cd | |||
| 7901ac94c4 | |||
| 4e53d590a9 | |||
| 5283b60c4f | |||
|
|
97927dc3f8 | ||
| ca778137a5 | |||
|
|
4db5b6e318 | ||
| ab596f60b0 | |||
| ae8cac6595 | |||
|
|
5a77f8c4e8 | ||
|
|
cb4e13b888 | ||
|
|
233521b6a7 | ||
|
|
8786e5d3c6 | ||
|
|
b11db35eb0 | ||
|
|
f8ee683728 | ||
| 5d0e349ffb | |||
|
|
256706377d | ||
| 9959de99f6 | |||
| 5e7667aa31 | |||
|
|
8d07d531de | ||
| 05c25c01e0 | |||
|
|
92cd1db4f5 | ||
| 7f1e8a4be8 | |||
| 3beb1ff33d | |||
|
|
6bbd852c8b | ||
|
|
9c17adfb38 | ||
|
|
bd162428a5 | ||
|
|
9ee378279b | ||
|
|
61ba606e89 | ||
|
|
02efa7a9ba |
6
.idea/cssdialects.xml
generated
Normal file
6
.idea/cssdialects.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CssDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/styleguide.css" dialect="CLASSIC" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
1
.idea/encodings.xml
generated
1
.idea/encodings.xml
generated
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="Encoding" addBOMForNewFiles="with NO BOM">
|
<component name="Encoding" addBOMForNewFiles="with NO BOM">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/saves/playerSave.txt" charset="windows-1252" />
|
||||||
<file url="PROJECT" charset="UTF-8" />
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
11
.idea/libraries/hamcrest_core_1_3.xml
generated
Normal file
11
.idea/libraries/hamcrest_core_1_3.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="hamcrest-core-1.3">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/src/hamcrest-core-1.3.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/src/jfxrt.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/src/junit-4.12.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -9,7 +9,7 @@
|
|||||||
<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>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_201" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_141" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
<component name="SvnBranchConfigurationManager">
|
<component name="SvnBranchConfigurationManager">
|
||||||
|
|||||||
1164
.idea/workspace.xml
generated
1164
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
36
README.md
36
README.md
@@ -7,12 +7,42 @@ If you are using intellij, extract "TaipanClone-master.zip", and open the "Taipa
|
|||||||
Place jfxt.jar, hamcrest-core-1.3.jar and junit-4.12.jar into the src folder
|
Place jfxt.jar, hamcrest-core-1.3.jar and junit-4.12.jar into the src folder
|
||||||
Then, run MainGUI.java.
|
Then, run MainGUI.java.
|
||||||
|
|
||||||
|
# To play the game
|
||||||
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.
|
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 -cp .:junit-4.12.jar:hamcrest-core-1.3.jar *.java", this compiles all the necessary files. Now, run MainGUI.java using "java MainGUI".
|
Then, if you are using Linux, type in
|
||||||
|
```
|
||||||
To run the test file PlayerTest.java, type in "javac -cp .:junit-4.12.jar:hamcrest-core-1.3.jar *.java", this compiles all the necessary files. Now, run PlayerTest.java using "java PlayerTest".
|
"javac -cp .:junit-4.12.jar:hamcrest-core-1.3.jar:jfxrt.jar gui/*.java text/*.java logic/*.java tests/*.java"
|
||||||
|
```
|
||||||
|
Otherwise, if you are using Windows, type in
|
||||||
|
```
|
||||||
|
"javac -cp .;junit-4.12.jar;hamcrest-core-1.3.jar;jfxrt.jar gui/*.java text/*.java logic/*.java tests/*.java"
|
||||||
|
```
|
||||||
|
This compiles all the necessary files. Now, to play the GUI version run MainGUI.java using
|
||||||
|
```
|
||||||
|
java gui.MainGUI
|
||||||
|
```
|
||||||
|
To play the text-based version run MainText.java using
|
||||||
|
```
|
||||||
|
java text.MainText
|
||||||
|
```
|
||||||
|
|
||||||
|
# To run the test file PlayerTest.java for Linux type in:
|
||||||
|
```
|
||||||
|
javac -cp .:junit-4.12.jar:hamcrest-core-1.3.jar:jfxrt.jar gui/*.java text/*.java logic/*.java tests/*.java
|
||||||
|
```
|
||||||
|
This compiles all the necessary files. Now, run PlayerTest.java by typing in
|
||||||
|
```
|
||||||
|
java -cp .:junit-4.12.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore tests.PlayerTest
|
||||||
|
```
|
||||||
|
# To run the test file PlayerTest.java for Windows, type in:
|
||||||
|
```
|
||||||
|
javac -cp .;junit-4.12.jar;hamcrest-core-1.3.jar;jfxrt.jar gui/*.java text/*.java logic/*.java tests/*.java
|
||||||
|
```
|
||||||
|
This compiles all the necessary files. Now, run PlayerTest.java by typing in
|
||||||
|
```
|
||||||
|
java -cp .;junit-4.12.jar;hamcrest-core-1.3.jar org.junit.runner.JUnitCore tests.PlayerTest
|
||||||
|
```
|
||||||
Additional information:
|
Additional information:
|
||||||
|
|
||||||
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.
|
||||||
|
|||||||
187
src/BankGUI.java
187
src/BankGUI.java
@@ -1,187 +0,0 @@
|
|||||||
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.layout.BorderPane;
|
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
public class BankGUI extends Player{
|
|
||||||
/**
|
|
||||||
* 2019-03-10
|
|
||||||
* Authors: Siddhant Dewani
|
|
||||||
* BankGUI allows the user to store cash and gain interest off of the cash
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Constructor that takes in a type player as a parameter
|
|
||||||
*
|
|
||||||
* @param player object of the class Player
|
|
||||||
*/
|
|
||||||
public BankGUI(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
setPlayer(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: " + getName());
|
|
||||||
Label l2 = new Label("Balance: " + getBank());
|
|
||||||
Label l3 = new Label("Enter Amount: ");
|
|
||||||
Label l4 = new Label("Cash: " + 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);
|
|
||||||
hbx1.setPadding(new Insets(0,0,20,0));
|
|
||||||
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);
|
|
||||||
vbx1.setPadding(new Insets(20,0,0,0));
|
|
||||||
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) {
|
|
||||||
try {
|
|
||||||
int withdraw = Integer.parseInt(txtField1.getText());
|
|
||||||
if(withdraw < 0){
|
|
||||||
l5.setText("Come on " + getName() + ", are you trying to fool me?\nNo negative numbers please!");
|
|
||||||
}
|
|
||||||
else if (withdraw <= getBank()) {
|
|
||||||
setMoney(withdraw + getMoney());
|
|
||||||
setBank(getBank() - withdraw);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
l5.setText("Sorry, you can not withdraw that much.");
|
|
||||||
}
|
|
||||||
l2.setText("Balance: " + getBank());
|
|
||||||
l4.setText("Cash: " + getMoney());
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
l5.setText("Please enter a valid response.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
try {
|
|
||||||
int deposit = Integer.parseInt(txtField1.getText());
|
|
||||||
if(deposit < 0){
|
|
||||||
l5.setText("Nice try! You can not enter negative numbers.");
|
|
||||||
}
|
|
||||||
else if (deposit <= getMoney()) {
|
|
||||||
setBank(deposit + getBank());
|
|
||||||
setMoney(getMoney() - deposit);
|
|
||||||
} else {
|
|
||||||
l5.setText("Sorry, you can not deposit that much.");
|
|
||||||
}
|
|
||||||
l2.setText("Balance: " + getBank());
|
|
||||||
l4.setText("Cash: " + getMoney());
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
l5.setText("Please enter a valid response.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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(getPlayer());
|
|
||||||
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);
|
|
||||||
scene.getStylesheets().add("styleguide.css");
|
|
||||||
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(getPlayer());
|
|
||||||
bank.initializeBank(primaryStage);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
import java.io.*;
|
|
||||||
/**
|
|
||||||
* 2019-03-10 (Edited on 2019-03-19)
|
|
||||||
* Authors:
|
|
||||||
* FileSaving Class allows the user to save the current status of the game and to continue from where they left off.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class FileSaving extends Player implements Serializable {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*loads the file of type player which contains all the player instances
|
|
||||||
* @return player
|
|
||||||
*/
|
|
||||||
public Player loadFile() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
|
|
||||||
ObjectInputStream inObject = new ObjectInputStream(in);
|
|
||||||
Player player = (Player) inObject.readObject();
|
|
||||||
in.close();
|
|
||||||
inObject.close();
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
try {
|
|
||||||
InputStream in = new FileInputStream(new File("saves/playerSave.txt"));
|
|
||||||
ObjectInputStream inObject = new ObjectInputStream(in);
|
|
||||||
Player player = (Player) inObject.readObject();
|
|
||||||
in.close();
|
|
||||||
inObject.close();
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
catch(Exception e2){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean saveFile(Player player){
|
|
||||||
try{
|
|
||||||
FileOutputStream out = new FileOutputStream(new File("src/saves/playerSave.txt"));
|
|
||||||
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
|
||||||
outObject.writeObject(player);
|
|
||||||
|
|
||||||
out.close();
|
|
||||||
outObject.close();
|
|
||||||
|
|
||||||
//returns true if program can save file
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
try {
|
|
||||||
FileOutputStream out = new FileOutputStream(new File("saves/playerSave.txt"));
|
|
||||||
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
|
||||||
outObject.writeObject(player);
|
|
||||||
|
|
||||||
out.close();
|
|
||||||
outObject.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch(Exception e2){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,181 +0,0 @@
|
|||||||
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.layout.BorderPane;
|
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 2019-03-10
|
|
||||||
* Authors: Siddhant Dewani
|
|
||||||
* LoanShark GUI Class allows the user to get a loan from the loan shark
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class LoanSharkGUI extends Player {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Constructor that takes in a type player as a parameter
|
|
||||||
*
|
|
||||||
* @param player object of the class Player
|
|
||||||
*/
|
|
||||||
public LoanSharkGUI(Player player) {
|
|
||||||
Player playerDummy = new Player(player);
|
|
||||||
setPlayer(playerDummy);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 if their debt exceeds the cash balance, the loan
|
|
||||||
* cannot be given.
|
|
||||||
*
|
|
||||||
* @param primaryStage the stage upon which the GUI will be imposed
|
|
||||||
*/
|
|
||||||
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: " + getName());
|
|
||||||
Label l2 = new Label("Debt " + getDebt());
|
|
||||||
Label l4 = new Label("Cash: " + 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);
|
|
||||||
hbx1.setPadding(new Insets(0,0,20,0));
|
|
||||||
|
|
||||||
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);
|
|
||||||
vbx1.setPadding(new Insets(20,0,0,0));
|
|
||||||
brdr1.setTop(vbx1);
|
|
||||||
|
|
||||||
// Set the event handler when the deposit button is clicked
|
|
||||||
b1.setOnAction(new EventHandler<ActionEvent>() {
|
|
||||||
@Override
|
|
||||||
public void handle(ActionEvent event) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
int loanAsk = Integer.parseInt(txtField1.getText());
|
|
||||||
if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) {
|
|
||||||
setDebt(getDebt() + loanAsk);
|
|
||||||
setMoney(getMoney() + loanAsk);
|
|
||||||
l4.setText("Cash: " + getMoney());
|
|
||||||
} else if (loanAsk < 0) {
|
|
||||||
l5.setText("Sorry you cannot enter negative numbers");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
l5.setText("Sorry you cannot get the loan requested");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
l2.setText("Debt: " + getDebt());
|
|
||||||
} catch (Exception e) {
|
|
||||||
l5.setText("Please enter a valid value");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set the event handler when the withdraw button is clicked
|
|
||||||
b2.setOnAction(new EventHandler<ActionEvent>() {
|
|
||||||
@Override
|
|
||||||
public void handle(ActionEvent event) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
|
||||||
int returnAsk = Integer.parseInt(txtField1.getText());
|
|
||||||
if (returnAsk > getDebt()) {
|
|
||||||
l5.setText("You do not need to return that much.");
|
|
||||||
}
|
|
||||||
else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) {
|
|
||||||
setDebt(getDebt() - returnAsk);
|
|
||||||
setMoney(getMoney() - returnAsk);
|
|
||||||
l4.setText("Cash: " + getMoney());
|
|
||||||
}
|
|
||||||
else if(getMoney() < returnAsk) {
|
|
||||||
l5.setText("Look " + getName() + ", you are being cheap!");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
l5.setText("Sorry, you can not return a negative amount!");
|
|
||||||
}
|
|
||||||
l2.setText("Debt: " + getDebt());
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
l5.setText("Please enter a valid value");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
b3.setOnAction(new EventHandler<ActionEvent>() {
|
|
||||||
@Override
|
|
||||||
public void handle(ActionEvent event) {
|
|
||||||
TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
|
|
||||||
shopGUI.initializeShop(primaryStage);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
//Setting the Scene and displaying it
|
|
||||||
Scene scene = new Scene(brdr1, 600, 480);
|
|
||||||
scene.getStylesheets().add("styleguide.css");
|
|
||||||
primaryStage.setScene(scene);
|
|
||||||
//primaryStage.show();
|
|
||||||
return primaryStage;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void start(Stage primaryStage) {
|
|
||||||
LoanSharkGUI loan = new LoanSharkGUI(getPlayer());
|
|
||||||
loan.initializeLoanShark(primaryStage);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,506 +0,0 @@
|
|||||||
/**
|
|
||||||
* TravelGUI is the class in which takes the player from location to location
|
|
||||||
*
|
|
||||||
* Author: Harkamal Randhawa
|
|
||||||
*/
|
|
||||||
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.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class TravelGUI extends Player{
|
|
||||||
private TaipanShopGUI shop;
|
|
||||||
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;
|
|
||||||
private Boolean sceneContinue = 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);
|
|
||||||
setPlayer(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(getPlayer());
|
|
||||||
taipanShopGUI.initializeShop(stage);
|
|
||||||
stage.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
//Continues on to either shop or shipwarfare
|
|
||||||
continueButton.setOnAction(event -> {
|
|
||||||
if(peasantShipScene && getAttackingShips()){
|
|
||||||
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
|
|
||||||
try {
|
|
||||||
ship.initializeShip(stage);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
stage.show();
|
|
||||||
}
|
|
||||||
else if(shopScene){
|
|
||||||
Random rand = new Random();
|
|
||||||
int randGenNum = rand.nextInt(3) + 1;
|
|
||||||
if(randGenNum >= 2) {
|
|
||||||
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
|
|
||||||
shop.initializeShop(stage);
|
|
||||||
stage.show();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
RandomEventGUI randomEventGUI = new RandomEventGUI(getPlayer());
|
|
||||||
randomEventGUI.initializeRandomEventGUI(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(getCargoSpace() >= (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + 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 != getLocation() && response > 0 && 8 > response && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
|
|
||||||
hasTraveled = seaAtlas(response);
|
|
||||||
randomEventSea(response,stage);
|
|
||||||
setBank((int) (getBank() * 1.01));
|
|
||||||
setDebt((int) (getDebt() * 1.01));
|
|
||||||
setIsPriceChanged(2);
|
|
||||||
//shopScene = false;
|
|
||||||
//stormScene = false;
|
|
||||||
|
|
||||||
} else{
|
|
||||||
if(response == getLocation()){
|
|
||||||
textOut.setText(" " + "You're already here " + getName() + "\n");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
textOut.setText(" " + getName() + "; Sorry but could you say that again?");
|
|
||||||
}
|
|
||||||
|
|
||||||
textOut.setText(textOut.getText() + "\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, " + getName() + " could you say that again?");
|
|
||||||
}
|
|
||||||
if (hasTraveled) {
|
|
||||||
continueButton.setVisible(true);
|
|
||||||
continueButton.setDefaultButton(true);
|
|
||||||
quitButton.setVisible(false);
|
|
||||||
numberInput.setVisible(false);
|
|
||||||
shopScene = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
|
|
||||||
textOut.setText(" "+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(210.0);
|
|
||||||
wItemSpaceText.setFont(size14);
|
|
||||||
|
|
||||||
locationText.setAlignment(Pos.BOTTOM_RIGHT);
|
|
||||||
locationText.setPrefHeight(106.0);
|
|
||||||
locationText.setPrefWidth(140.0);
|
|
||||||
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
|
||||||
locationText.setFont(size14);
|
|
||||||
|
|
||||||
inventoryText.setAlignment(Pos.CENTER);
|
|
||||||
inventoryText.setPrefWidth(110.0);
|
|
||||||
inventoryText.setPrefHeight(108.0);
|
|
||||||
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(200.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);
|
|
||||||
|
|
||||||
numberInput.requestFocus();
|
|
||||||
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);
|
|
||||||
root.getStylesheets().add("styleguide.css");
|
|
||||||
|
|
||||||
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");
|
|
||||||
setLocation(1);
|
|
||||||
return true;
|
|
||||||
case 2:
|
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai");
|
|
||||||
setLocation(2);
|
|
||||||
return true;
|
|
||||||
case 3:
|
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki");
|
|
||||||
setLocation(3);
|
|
||||||
return true;
|
|
||||||
case 4:
|
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon");
|
|
||||||
setLocation(4);
|
|
||||||
return true;
|
|
||||||
case 5:
|
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Manila");
|
|
||||||
setLocation(5);
|
|
||||||
return true;
|
|
||||||
case 6:
|
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore");
|
|
||||||
setLocation(6);
|
|
||||||
return true;
|
|
||||||
case 7:
|
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia");
|
|
||||||
setLocation(7);
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
textOut.setText(" " + "Sorry but could you say that again " + 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);
|
|
||||||
continueButton.setDefaultButton(true);
|
|
||||||
quitButton.setVisible(false);
|
|
||||||
numberInput.setVisible(false);
|
|
||||||
textOut.setText(" We see a ship on the horizon " + getName() + "; Prepare for combat!");
|
|
||||||
peasantShipScene = true;
|
|
||||||
}else if (randGenNum == 2) {
|
|
||||||
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 " + 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 " + 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(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(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", getName(), getStringLocation()));
|
|
||||||
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", getwOpium(), getwSilk(), getwArms(), getwGeneral()));
|
|
||||||
int itemsInWarehouse = getwOpium()+getwGeneral()+getwArms()+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 = getCargoSpace()-getSilkHeld()-getOpiumHeld()-getGeneralHeld()-getArmsHeld()-10*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 ", getGuns()));
|
|
||||||
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", getOpiumHeld(), getSilkHeld(), getArmsHeld(), getGeneralHeld()));
|
|
||||||
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", getDebt(), shipStatusString(), getHP()));
|
|
||||||
cashText.setText(String.format(" Cash: $%,d", getMoney()));
|
|
||||||
bankText.setText(String.format("Bank: $%,d", getBank()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
185
src/gui/BankGUI.java
Normal file
185
src/gui/BankGUI.java
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
|
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.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import logic.BankLogic;
|
||||||
|
import logic.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2019-03-10
|
||||||
|
* Authors: Siddhant Dewani
|
||||||
|
* BankGUI allows the user to store cash and gain interest off of the cash
|
||||||
|
*/
|
||||||
|
public class BankGUI extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public BankGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the GUI for the Bank in our game.
|
||||||
|
* @param primaryStage the stage in which everything in this class is shown
|
||||||
|
* @return Returns the stage in which can be used by other stages
|
||||||
|
*/
|
||||||
|
public void 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: " + getName());
|
||||||
|
Label l2 = new Label("Balance: " + getBank());
|
||||||
|
Label l3 = new Label("Enter Amount: ");
|
||||||
|
Label l4 = new Label("Cash: " + 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);
|
||||||
|
hbx1.setPadding(new Insets(0, 0, 20, 0));
|
||||||
|
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);
|
||||||
|
vbx1.setPadding(new Insets(20, 0, 0, 0));
|
||||||
|
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) {
|
||||||
|
withdraw(txtField1, l5, l2, l4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
deposits(txtField1, l5, l2, l4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(getPlayer());
|
||||||
|
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);
|
||||||
|
scene.getStylesheets().add("styleguide.css");
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The deposit button within the scene above. Runs the deposit logic class when run
|
||||||
|
* @param txtField1,l5,l2,l4 assigned from the original element inside of the JavaFX scene
|
||||||
|
*/
|
||||||
|
private void deposits(TextField txtField1, Label l5, Label l2, Label l4) {
|
||||||
|
try {
|
||||||
|
int deposit = Integer.parseInt(txtField1.getText());
|
||||||
|
if (deposit < 0) {
|
||||||
|
l5.setText("Nice try! You can not enter negative numbers.");
|
||||||
|
} else if (deposit <= getMoney()) {
|
||||||
|
BankLogic bankLogic = new BankLogic(getPlayer());
|
||||||
|
bankLogic.depositing(deposit);
|
||||||
|
setPlayer(bankLogic.getPlayer());
|
||||||
|
} else {
|
||||||
|
l5.setText("Sorry, you can not deposit that much.");
|
||||||
|
}
|
||||||
|
l2.setText("Balance: " + getBank());
|
||||||
|
l4.setText("Cash: " + getMoney());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
l5.setText("Please enter a valid response.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The withdraw button within the scene above. Runs the withdraw logic class when run
|
||||||
|
* @param txtField1,l5,l2,l4 assigned from the original element inside of the JavaFX scene
|
||||||
|
*/
|
||||||
|
private void withdraw(TextField txtField1, Label l5, Label l2, Label l4) {
|
||||||
|
try {
|
||||||
|
int withdraw = Integer.parseInt(txtField1.getText());
|
||||||
|
if (withdraw < 0) {
|
||||||
|
l5.setText("Come on " + getName() + ", are you trying to fool me?\nNo negative numbers please!");
|
||||||
|
} else if (withdraw <= getBank()) {
|
||||||
|
BankLogic bankLogic = new BankLogic(getPlayer());
|
||||||
|
bankLogic.withdrawing(withdraw);
|
||||||
|
setPlayer(bankLogic.getPlayer());
|
||||||
|
} else {
|
||||||
|
l5.setText("Sorry, you can not withdraw that much.");
|
||||||
|
}
|
||||||
|
l2.setText("Balance: " + getBank());
|
||||||
|
l4.setText("Cash: " + getMoney());
|
||||||
|
} catch (Exception e) {
|
||||||
|
l5.setText("Please enter a valid response.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
@@ -5,6 +7,8 @@ import javafx.scene.layout.BorderPane;
|
|||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import logic.Player;
|
||||||
|
import logic.GameEndLogic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-10
|
* 2019-03-10
|
||||||
@@ -21,6 +25,11 @@ public class GameEndGUI extends Player{
|
|||||||
private Label netWorth;
|
private Label netWorth;
|
||||||
private BorderPane borderPane;
|
private BorderPane borderPane;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
public GameEndGUI(Player player) {
|
public GameEndGUI(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
@@ -32,7 +41,7 @@ public class GameEndGUI extends Player{
|
|||||||
* @param stage sets the stage to which we will execute the scene of the GameEndGUI 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
|
* @return stage so that another class can switch to the stage
|
||||||
*/
|
*/
|
||||||
public Stage initializeGameEndGUI(Stage stage) {
|
public void initializeGameEndGUI(Stage stage) {
|
||||||
|
|
||||||
//Creating all the nodes
|
//Creating all the nodes
|
||||||
title = new Label();
|
title = new Label();
|
||||||
@@ -69,33 +78,21 @@ public class GameEndGUI extends Player{
|
|||||||
netWorth.setFont(new Font(22.0));
|
netWorth.setFont(new Font(22.0));
|
||||||
borderPane.setCenter(vBox);
|
borderPane.setCenter(vBox);
|
||||||
|
|
||||||
|
//Calculating the netWorth of the Player
|
||||||
|
GameEndLogic gameEndLogic = new GameEndLogic(getPlayer());
|
||||||
|
netWorthInt = gameEndLogic.getNetWorth();
|
||||||
|
|
||||||
//Adding the labels to the character's stats to the VBox which will show up on the screen
|
//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(firmName);
|
||||||
vBox.getChildren().add(gunsHeld);
|
vBox.getChildren().add(gunsHeld);
|
||||||
vBox.getChildren().add(netWorth);
|
vBox.getChildren().add(netWorth);
|
||||||
|
title.setText(gameEndLogic.endGameText());
|
||||||
|
|
||||||
/**
|
String[] strings = gameEndLogic.endGameStats(netWorthInt);
|
||||||
* If health is below or equal to 0 then the game will either show the gameOver screen or the win screen
|
|
||||||
* */
|
|
||||||
if (getHP() <= 0) {
|
|
||||||
title.setText("Game Over!");
|
|
||||||
} else {
|
|
||||||
title.setText("Congratulations!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the networth of the player by the end of the game
|
|
||||||
* */
|
|
||||||
netWorthInt = getMoney() + (getOpiumHeld() * 16000) + (getSilkHeld() * 160) + (getArmsHeld() * 160) + (getGeneralHeld() * 8);
|
|
||||||
netWorthInt += (getwOpium() * 16000) + (getwSilk() * 160) + (getwArms() * 160) + (getwGeneral() * 8);
|
|
||||||
netWorthInt -= getDebt();
|
|
||||||
|
|
||||||
|
|
||||||
//Updating the endgame stats of the player
|
//Updating the endgame stats of the player
|
||||||
firmName.setText("Firm Name: " + getName());
|
firmName.setText(strings[0]);
|
||||||
gunsHeld.setText("Guns Held: " + getGuns());
|
gunsHeld.setText(strings[1]);
|
||||||
netWorth.setText("Net Worth: " + netWorthInt);
|
netWorth.setText(strings[2]);
|
||||||
|
|
||||||
Scene root = new Scene(borderPane, 600, 480);
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
root.getStylesheets().add("styleguide.css");
|
root.getStylesheets().add("styleguide.css");
|
||||||
@@ -103,18 +100,7 @@ public class GameEndGUI extends Player{
|
|||||||
stage.setTitle("End Game Stats");
|
stage.setTitle("End Game Stats");
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
stage.setScene(root);
|
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(getPlayer());
|
|
||||||
gameEndGUI.initializeGameEndGUI(primaryStage);
|
|
||||||
primaryStage.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
186
src/gui/LoanSharkGUI.java
Normal file
186
src/gui/LoanSharkGUI.java
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
|
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.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import logic.LoanSharkLogic;
|
||||||
|
import logic.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2019-03-10
|
||||||
|
* Authors: Siddhant Dewani
|
||||||
|
* LoanShark GUI Class allows the user to get a loan from the loan shark
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class LoanSharkGUI extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public LoanSharkGUI(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 if their debt exceeds the cash balance, the loan
|
||||||
|
* cannot be given.
|
||||||
|
*
|
||||||
|
* @param primaryStage the stage upon which the GUI will be imposed
|
||||||
|
*/
|
||||||
|
public void 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: " + getName());
|
||||||
|
Label l2 = new Label("Debt " + getDebt());
|
||||||
|
Label l4 = new Label("Cash: " + 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);
|
||||||
|
hbx1.setPadding(new Insets(0,0,20,0));
|
||||||
|
|
||||||
|
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);
|
||||||
|
vbx1.setPadding(new Insets(20,0,0,0));
|
||||||
|
brdr1.setTop(vbx1);
|
||||||
|
|
||||||
|
// Set the event handler when the deposit button is clicked
|
||||||
|
b1.setOnAction(event -> {
|
||||||
|
depositButton(l2, l4, l5, txtField1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set the event handler when the withdraw button is clicked
|
||||||
|
b2.setOnAction(event -> {
|
||||||
|
withdrawButton(l2, l4, l5, txtField1);
|
||||||
|
});
|
||||||
|
|
||||||
|
b3.setOnAction(event -> {
|
||||||
|
TaipanShopGUI shopGUI = new TaipanShopGUI(getPlayer());
|
||||||
|
shopGUI.initializeShop(primaryStage);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//Setting the Scene and displaying it
|
||||||
|
Scene scene = new Scene(brdr1, 600, 480);
|
||||||
|
scene.getStylesheets().add("styleguide.css");
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The withdraw button within the scene above. Runs the withdraw logic class when run
|
||||||
|
* @param txtField1,l2,l4,l5 assigned from the original element inside of the JavaFX scene
|
||||||
|
*/
|
||||||
|
public void withdrawButton(Label l2, Label l4, Label l5, TextField txtField1) {
|
||||||
|
try {
|
||||||
|
int returnAsk = Integer.parseInt(txtField1.getText());
|
||||||
|
//If the player enters a invalid number
|
||||||
|
if (returnAsk > getDebt()) {
|
||||||
|
l5.setText("You do not need to return that much.");
|
||||||
|
}
|
||||||
|
//If the player enters a valid number
|
||||||
|
else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) {
|
||||||
|
LoanSharkLogic loanSharkLogic = new LoanSharkLogic(getPlayer());
|
||||||
|
loanSharkLogic.changeLoan(getDebt() - returnAsk, getMoney() - returnAsk);
|
||||||
|
setPlayer(loanSharkLogic.getPlayer());
|
||||||
|
l4.setText("Cash: " + getMoney());
|
||||||
|
}
|
||||||
|
//If the player enters a invalid number
|
||||||
|
else if(getMoney() < returnAsk) {
|
||||||
|
l5.setText("Look " + getName() + ", you are being cheap!");
|
||||||
|
}
|
||||||
|
//If the player enters a negative number
|
||||||
|
else {
|
||||||
|
l5.setText("Sorry, you can not return a negative amount!");
|
||||||
|
}
|
||||||
|
l2.setText("Debt: " + getDebt());
|
||||||
|
}
|
||||||
|
//Only runs if the user gives an invalid input
|
||||||
|
catch (Exception e) {
|
||||||
|
l5.setText("Please enter a valid value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The deposit button within the scene above. Runs the deposit logic class when run
|
||||||
|
* @param txtField1,l5,l2,l4 assigned from the original element inside of the JavaFX scene
|
||||||
|
*/
|
||||||
|
public void depositButton(Label l2, Label l4, Label l5, TextField txtField1) {
|
||||||
|
try {
|
||||||
|
int loanAsk = Integer.parseInt(txtField1.getText());
|
||||||
|
//If the player enters a valid number
|
||||||
|
if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) {
|
||||||
|
LoanSharkLogic loanSharkLogic = new LoanSharkLogic(getPlayer());
|
||||||
|
loanSharkLogic.changeLoan(getDebt() + loanAsk, getMoney() + loanAsk);
|
||||||
|
setPlayer(loanSharkLogic.getPlayer());
|
||||||
|
l4.setText("Cash: " + getMoney());
|
||||||
|
}
|
||||||
|
//If the player enters a negative number
|
||||||
|
else if (loanAsk < 0) {
|
||||||
|
l5.setText("Sorry you cannot enter negative numbers");
|
||||||
|
}
|
||||||
|
//If the player enters a invalid number
|
||||||
|
else{
|
||||||
|
l5.setText("Sorry you cannot get the loan requested");
|
||||||
|
}
|
||||||
|
l2.setText("Debt: " + getDebt());
|
||||||
|
}
|
||||||
|
//Only runs if the user gives an invalid input
|
||||||
|
catch (Exception e) {
|
||||||
|
l5.setText("Please enter a valid value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,26 +1,30 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import logic.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-10
|
* 2019-03-10
|
||||||
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
|
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
|
||||||
* MainGUI class, Initializes the entire game and runs the game for user to play
|
* MainGUI class, Initializes the entire game and runs the game for user to play
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MainGUI extends Application {
|
public class MainGUI extends Application {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates main class with player data and starts the game.
|
* 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.
|
* 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.
|
* @param args Just the console for the player to look at.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(Stage primaryStage) throws Exception {
|
/**
|
||||||
|
* Starts the game as a whole, combines all of the other necessary classes
|
||||||
|
* @param primaryStage Creates new stage for scene to be utilized
|
||||||
|
*/
|
||||||
|
public void start(Stage primaryStage){
|
||||||
StartGUI start = new StartGUI(new Player());
|
StartGUI start = new StartGUI(new Player());
|
||||||
start.initializeStart(primaryStage);
|
start.initializeStart(primaryStage);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
@@ -5,8 +7,8 @@ import javafx.scene.layout.BorderPane;
|
|||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import logic.Player;
|
||||||
import java.util.Random;
|
import logic.RandomEventLogic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-19
|
* 2019-03-19
|
||||||
@@ -46,11 +48,11 @@ public class RandomEventGUI extends Player{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes randomEvent on the given stage as a parameter.
|
* Sets up the graphical part of RandomEventGUI and includes all logic for the class
|
||||||
*
|
*
|
||||||
* @param stage
|
* @param stage sets the stage to which we will execute the scene of the RandomEventGUI class
|
||||||
*/
|
*/
|
||||||
public Stage initializeRandomEventGUI(Stage stage) {
|
public void initializeRandomEventGUI(Stage stage) {
|
||||||
//Creating the nodes within the event screen
|
//Creating the nodes within the event screen
|
||||||
hBox = new HBox();
|
hBox = new HBox();
|
||||||
yesButton = new Button();
|
yesButton = new Button();
|
||||||
@@ -129,39 +131,28 @@ public class RandomEventGUI extends Player{
|
|||||||
* 2: Paying Liu Yuen
|
* 2: Paying Liu Yuen
|
||||||
* 3: Repairing the Ship
|
* 3: Repairing the Ship
|
||||||
*/
|
*/
|
||||||
Random rand = new Random();
|
RandomEventLogic randomEventLogic = new RandomEventLogic(getPlayer());
|
||||||
int randGenNum = rand.nextInt(3) + 1;
|
int[] randEvent = randomEventLogic.randEvent();
|
||||||
while(true){
|
eventNumber = randEvent[0];
|
||||||
//Buy Guns
|
itemPrice = randEvent[1];
|
||||||
if (randGenNum == 1) {
|
|
||||||
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
|
||||||
sellingItemLabel.setText("A vender is selling a gun for $" + itemPrice + " for a gun?");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//Liu Yuen
|
|
||||||
if (randGenNum == 2) {
|
|
||||||
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
|
||||||
sellingItemLabel.setText("Liu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
|
|
||||||
setAttackingShips(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//Ship Repair
|
|
||||||
if (randGenNum == 3 && getHP() < 100) {
|
|
||||||
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
|
|
||||||
sellingItemLabel.setText("Mc Henry from the Hong Kong shipyard has arrived,\n would be willing to repair your ship for $" + itemPrice);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
randGenNum = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
eventNumber = randGenNum;
|
|
||||||
|
|
||||||
|
if(eventNumber == 1){
|
||||||
|
sellingItemLabel.setText("A vender is selling a gun for $" + itemPrice + " for a gun?");
|
||||||
|
}
|
||||||
|
if(eventNumber == 2){
|
||||||
|
sellingItemLabel.setText("Liu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
|
||||||
|
}
|
||||||
|
if(eventNumber == 3){
|
||||||
|
sellingItemLabel.setText("Mc Henry from the Hong Kong shipyard has arrived,\n would be willing to repair your ship for $" + itemPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Only runs if the player doesn't have enough space and is given a gun
|
||||||
if((eventNumber == 1 && getCargoSpace() < 10)){
|
if((eventNumber == 1 && getCargoSpace() < 10)){
|
||||||
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
||||||
taipanShopGUI.initializeShop(stage);
|
taipanShopGUI.initializeShop(stage);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
//Only runs if the player has 100 or greater HP and they got the ship repair man
|
||||||
if((eventNumber == 3 && getPlayer().getHP() >= 100)){
|
if((eventNumber == 3 && getPlayer().getHP() >= 100)){
|
||||||
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
TaipanShopGUI taipanShopGUI = new TaipanShopGUI(getPlayer());
|
||||||
taipanShopGUI.initializeShop(stage);
|
taipanShopGUI.initializeShop(stage);
|
||||||
@@ -221,9 +212,10 @@ public class RandomEventGUI extends Player{
|
|||||||
Scene root = new Scene(borderPane, 600, 480);
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
root.getStylesheets().add("styleguide.css");
|
root.getStylesheets().add("styleguide.css");
|
||||||
|
|
||||||
stage.setTitle("Travel");
|
stage.setTitle("Random Event");
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
stage.setScene(root);
|
stage.setScene(root);
|
||||||
return stage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
import javafx.animation.*;
|
import javafx.animation.*;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
@@ -14,19 +14,23 @@ import javafx.scene.layout.VBox;
|
|||||||
import javafx.scene.shape.Circle;
|
import javafx.scene.shape.Circle;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
import logic.Player;
|
||||||
|
import logic.ShipWarfareLogic;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-10 (Edited on 2019-03-23)
|
* 2019-03-10 (Edited on 2019-03-23)
|
||||||
* Author: Haris Muhammad
|
* Author: Haris Muhammad
|
||||||
* ShipWarfareGUI class, Generates and utilizes ships which the user can attack or run from
|
* ShipWarfareGUI class, Generates and utilizes ships which the user can attack or run from
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class ShipWarfareGUI extends Player {
|
public class ShipWarfareGUI extends Player {
|
||||||
|
|
||||||
|
ShipWarfareLogic logic = new ShipWarfareLogic(getPlayer());
|
||||||
|
|
||||||
private ShipWarfareGUI ship;
|
private ShipWarfareGUI ship;
|
||||||
private Circle cannon;
|
private Circle cannon;
|
||||||
private VBox buttonBox;
|
private VBox buttonBox;
|
||||||
@@ -45,12 +49,7 @@ public class ShipWarfareGUI extends Player {
|
|||||||
private boolean winOrLose = false;
|
private boolean winOrLose = false;
|
||||||
|
|
||||||
|
|
||||||
private int counter1;
|
|
||||||
private int timeCounter;
|
|
||||||
|
|
||||||
private int numOfLittyShips = 0;
|
|
||||||
private boolean userAttacks = true;
|
private boolean userAttacks = true;
|
||||||
private int startingLittyShips = 0;
|
|
||||||
private int howMuchRun = 0;
|
private int howMuchRun = 0;
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
private String pirateName = "Liu Yen";
|
private String pirateName = "Liu Yen";
|
||||||
@@ -74,99 +73,93 @@ public class ShipWarfareGUI extends Player {
|
|||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 (getMoney() <= 100000) {
|
|
||||||
//Minimum one ship will attack, maximum 20
|
|
||||||
numOfShipsAttacking = randomValue.nextInt(20) + 1;
|
|
||||||
} else if (getMoney() <= 200000) {
|
|
||||||
//Minimum 30 Ships will attack, maximum 70
|
|
||||||
numOfShipsAttacking = randomValue.nextInt(40) + 31;
|
|
||||||
} else if (getMoney() <= 500000) {
|
|
||||||
//Minimum 50 ships will attack, maximum 140
|
|
||||||
numOfShipsAttacking = randomValue.nextInt(90) + 51;
|
|
||||||
} else if (getMoney() >= 1000000) {
|
|
||||||
//Minimum 100 ships will attack, maximum 300 ships
|
|
||||||
numOfShipsAttacking = randomValue.nextInt(200) + 101;
|
|
||||||
}
|
|
||||||
|
|
||||||
return numOfShipsAttacking;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setter method that takes in an integer as an argument
|
* Sets most of the labels invisible
|
||||||
*
|
|
||||||
* @param numOfLittyShips the number of ships to be used in the peasant fleet attack
|
|
||||||
*/
|
|
||||||
public void setNumOfLittyShips(int numOfLittyShips) {
|
|
||||||
counter1++;
|
|
||||||
this.numOfLittyShips = numOfLittyShips;
|
|
||||||
if (counter1 == 1) {
|
|
||||||
startingLittyShips = numOfLittyShips;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
public void wipe() {
|
||||||
|
wipeWithTitle(title);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wipe many of the labels including title
|
||||||
|
*
|
||||||
|
* @param title for GUI
|
||||||
|
*/
|
||||||
|
public void wipeWithTitle(Label title) {
|
||||||
title.setVisible(false);
|
title.setVisible(false);
|
||||||
runAwayOrLeft.setVisible(false);
|
runAwayOrLeft.setVisible(false);
|
||||||
shipsRemaining.setVisible(false);
|
shipsRemaining.setVisible(false);
|
||||||
HPLeft.setVisible(false);
|
HPLeft.setVisible(false);
|
||||||
gunsLeftOrTaken.setVisible(false);
|
gunsLeftOrTaken.setVisible(false);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets most of the labels invisible including the fight or run label
|
* Sets most of the labels invisible including the fight or run label
|
||||||
*/
|
*/
|
||||||
public void completeWipe() {
|
public void completeWipe() {
|
||||||
title.setVisible(false);
|
wipe();
|
||||||
runAwayOrLeft.setVisible(false);
|
|
||||||
shipsRemaining.setVisible(false);
|
|
||||||
HPLeft.setVisible(false);
|
|
||||||
gunsLeftOrTaken.setVisible(false);
|
|
||||||
report.setVisible(false);
|
report.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attacks the enemy fleet and sees how much shots miss and how much shots hit
|
||||||
|
*
|
||||||
|
* @param exitValue to distingusih if the player won, lost, or ran
|
||||||
|
* @param hitCounter to see how much of the shots hit the ships
|
||||||
|
* @param missCounter to see how much of the shots missed the ships
|
||||||
|
* @param random to utilize the random object
|
||||||
|
* @return an array of values
|
||||||
|
*/
|
||||||
|
public int[] successfulHitOrNot(int exitValue, int hitCounter, int missCounter, Random random) {
|
||||||
|
int hitOrMiss = random.nextInt(2) + 1;
|
||||||
|
|
||||||
|
if (userAttacks && hitOrMiss == 2) {
|
||||||
|
if (logic.getNumOfShips() <= 0) {
|
||||||
|
exitValue = 1;
|
||||||
|
}
|
||||||
|
hitCounter++;
|
||||||
|
logic.setNumOfShips(logic.getNumOfShips() - 1);
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
missCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new int[]{exitValue, hitCounter, missCounter};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports how many ships escape or run
|
||||||
|
*/
|
||||||
|
public void howMuchEscapeOrRun() {
|
||||||
|
if (howMuchRun != 0 && howMuchRun < logic.getNumOfShips()) {
|
||||||
|
|
||||||
|
logic.setNumOfShips(logic.getNumOfShips() - howMuchRun);
|
||||||
|
if (userAttacks == true) {
|
||||||
|
if (howMuchRun > 0) {
|
||||||
|
runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, super.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
report.setText((String.format("Escaped %d of them %s!", howMuchRun, super.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user faces off against the litty ships and either prevails, dies, or runs away
|
* The user faces off against the ships and either prevails, dies, or runs away
|
||||||
*
|
*
|
||||||
* @return true if the user wins, loses, or flees, it returns false otherwise
|
* @return true if the user wins, loses, or flees, it returns false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean destroyLittyShipsOrEscape(Stage stage) throws Exception {
|
public boolean destroyShipsOrEscape(Stage stage) throws Exception {
|
||||||
|
|
||||||
cannon.setLayoutX(beginningX);
|
cannon.setLayoutX(beginningX);
|
||||||
cannon.setLayoutY(beginningY);
|
cannon.setLayoutY(beginningY);
|
||||||
int calculateLoot = 0;
|
int calculateLoot = 0;
|
||||||
@@ -176,39 +169,17 @@ public class ShipWarfareGUI extends Player {
|
|||||||
boolean gunFrustration = false;
|
boolean gunFrustration = false;
|
||||||
|
|
||||||
|
|
||||||
|
runAwayOrLeft.setText("No ships ran away");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Random randomValue = new Random();
|
Random randomValue = new Random();
|
||||||
int exitValue = 0;
|
int exitValue = 0;
|
||||||
//Player volley
|
//Player volley
|
||||||
//while (exitValue == 0) {
|
if (super.getGuns() > 0) {
|
||||||
if (getGuns() > 0) {
|
|
||||||
|
|
||||||
for (int j = 0; j < getGuns(); j++) {
|
for (int j = 0; j < super.getGuns(); j++) {
|
||||||
if (userAttacks == true) {
|
int array[] = successfulHitOrNot(exitValue, hitCounter, missCounter, randomValue);
|
||||||
|
exitValue = array[0];
|
||||||
int hitOrMiss = randomValue.nextInt(2) + 1;
|
hitCounter = array[1];
|
||||||
if (hitOrMiss == 2) {
|
missCounter = array[2];
|
||||||
numOfLittyShips--;
|
|
||||||
if (numOfLittyShips <= 0) {
|
|
||||||
exitValue = 1;
|
|
||||||
//break;
|
|
||||||
}
|
|
||||||
hitCounter++;
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
missCounter++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
//continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (userAttacks == true) {
|
if (userAttacks == true) {
|
||||||
report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
|
report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
|
||||||
@@ -219,69 +190,56 @@ public class ShipWarfareGUI extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (numOfLittyShips <= 0) {
|
if (logic.getNumOfShips() <= 0) {
|
||||||
exitValue = 1;
|
exitValue = 1;
|
||||||
//break;
|
|
||||||
}
|
}
|
||||||
if (getGuns() > 0) {
|
|
||||||
|
if (super.getGuns() > 0) {
|
||||||
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
||||||
if (chanceOfEnemyRun == 2) {
|
if (chanceOfEnemyRun == 2) {
|
||||||
howMuchRun = randomValue.nextInt(15) + 1;
|
howMuchRun = randomValue.nextInt(15) + 1;
|
||||||
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
|
howMuchEscapeOrRun();
|
||||||
|
|
||||||
|
|
||||||
setNumOfLittyShips(numOfLittyShips - howMuchRun);
|
|
||||||
if (userAttacks == true) {
|
|
||||||
if (howMuchRun > 0) {
|
|
||||||
runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, getName()));
|
|
||||||
|
|
||||||
//runAwayOrLeft.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
report.setText((String.format("Escaped %d of them %s!", howMuchRun, getName())));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
shipsRemaining.setText(String.format("%d ships remaining and they look angry!", numOfLittyShips));
|
shipsRemaining.setText(String.format("%d ships remaining and they look angry!", logic.getNumOfShips()));
|
||||||
//Computer volley
|
//Computer volley
|
||||||
int takeGunChance = randomValue.nextInt(4) + 1;
|
int takeGunChance = randomValue.nextInt(4) + 1;
|
||||||
if (takeGunChance == 1 && getGuns() > 0) {
|
if (takeGunChance == 1 && super.getGuns() > 0) {
|
||||||
setGuns(getGuns() - 1);
|
super.setGuns(super.getGuns() - 1);
|
||||||
gunFrustration = true;
|
gunFrustration = true;
|
||||||
} else {
|
} else {
|
||||||
if (numOfLittyShips > 0) {
|
if (logic.getNumOfShips() > 0) {
|
||||||
int HPTaken = randomValue.nextInt(10);
|
int HPTaken = randomValue.nextInt(10) + 1;
|
||||||
setHP(getHP() - (HPTaken));
|
super.setHP(super.getHP() - (HPTaken));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getHP() <= 0) {
|
if (super.getHP() <= 0) {
|
||||||
exitValue = 2;
|
exitValue = 2;
|
||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
if (gunFrustration == true) {
|
if (gunFrustration == true) {
|
||||||
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", getGuns()));
|
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", super.getGuns()));
|
||||||
playerShoots(getGuns() + 1);
|
playerShoots(getGuns() + 1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
gunsLeftOrTaken.setText(String.format("We still have %d guns left", getGuns()));
|
gunsLeftOrTaken.setText(String.format("We still have %d guns left", super.getGuns()));
|
||||||
}
|
}
|
||||||
|
|
||||||
HPLeft.setText(String.format("EEK, our current ship status is %d%% ", getHP()));
|
HPLeft.setText(String.format("EEK, our current ship status is %d%% ", super.getHP()));
|
||||||
if (userAttacks == false) {
|
if (userAttacks == false) {
|
||||||
userAttacks = true;
|
userAttacks = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//The user defeats the enemy fleet
|
||||||
if (exitValue == 1) {
|
if (exitValue == 1) {
|
||||||
wipe();
|
wipe();
|
||||||
calculateLoot = (startingLittyShips * 100) + randomValue.nextInt(startingLittyShips) * 200;
|
calculateLoot = logic.calculateLoot();
|
||||||
setMoney(getMoney() + calculateLoot);
|
super.setMoney(logic.getMoney());
|
||||||
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
|
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
|
||||||
continueButton.setVisible(true);
|
continueButton.setVisible(true);
|
||||||
completeWipe();
|
completeWipe();
|
||||||
@@ -289,21 +247,14 @@ public class ShipWarfareGUI extends Player {
|
|||||||
runButton.setVisible(false);
|
runButton.setVisible(false);
|
||||||
continueButton.setDefaultButton(true);
|
continueButton.setDefaultButton(true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (exitValue == 2) {
|
} else if (exitValue == 2) {
|
||||||
GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
|
GameEndGUI gameEndGUI = new GameEndGUI(getPlayer());
|
||||||
gameEndGUI.initializeGameEndGUI(stage);
|
gameEndGUI.initializeGameEndGUI(stage);
|
||||||
stage.show();
|
stage.show();
|
||||||
return true;
|
return true;
|
||||||
} else if (exitValue == 3) {
|
|
||||||
report.setText(String.format("We made it out at %d%% ship status!", getHP()));
|
|
||||||
|
|
||||||
continueButton.setVisible(true);
|
|
||||||
completeWipe();
|
|
||||||
fightButton.setVisible(false);
|
|
||||||
runButton.setVisible(false);
|
|
||||||
continueButton.setDefaultButton(true);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -312,16 +263,14 @@ public class ShipWarfareGUI extends Player {
|
|||||||
* Player attacks enemy ships in an animation
|
* Player attacks enemy ships in an animation
|
||||||
*/
|
*/
|
||||||
public void playerShoots(int amountOfShots) {
|
public void playerShoots(int amountOfShots) {
|
||||||
userAttacks=true;
|
|
||||||
shotsFired.setFromX(0);
|
shotsFired.setFromX(0);
|
||||||
shotsFired.setFromY(0);
|
shotsFired.setFromY(0);
|
||||||
shotsFired.setToX(endX);
|
shotsFired.setToX(endX);
|
||||||
shotsFired.setToY(endY);
|
shotsFired.setToY(endY);
|
||||||
shotsFired.setDuration(Duration.seconds(0.5));
|
shotsFired.setDuration(Duration.seconds(0.5));
|
||||||
if(getGuns()>0) {
|
if (super.getGuns() > 0) {
|
||||||
shotsFired.setCycleCount(amountOfShots);
|
shotsFired.setCycleCount(amountOfShots);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
shotsFired.setCycleCount(0);
|
shotsFired.setCycleCount(0);
|
||||||
shotsFired.stop();
|
shotsFired.stop();
|
||||||
cannon.setVisible(false);
|
cannon.setVisible(false);
|
||||||
@@ -333,7 +282,6 @@ public class ShipWarfareGUI extends Player {
|
|||||||
/**
|
/**
|
||||||
* Ships attack player ship back in an animation
|
* Ships attack player ship back in an animation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void shipsRetaliate() {
|
public void shipsRetaliate() {
|
||||||
cannon.setVisible(true);
|
cannon.setVisible(true);
|
||||||
enemyShots.setFromX(270);
|
enemyShots.setFromX(270);
|
||||||
@@ -371,24 +319,25 @@ public class ShipWarfareGUI extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generaties ships and deploys logic for the shipwarfare
|
* Generaties ships and deploys logic for the shipwarfare
|
||||||
|
*
|
||||||
* @param primaryStage sets up the stage to whcih the GUI may be based around
|
* @param primaryStage sets up the stage to whcih the GUI may be based around
|
||||||
* @throws Exception in case of interruptions withing the graphical interface
|
* @throws Exception in case of interruptions withing the graphical interface
|
||||||
*/
|
*/
|
||||||
public void initializeShip(Stage primaryStage) throws Exception {
|
public void initializeShip(Stage primaryStage) throws Exception {
|
||||||
setNumOfLittyShips(numOfShips());
|
|
||||||
|
logic.setNumOfShips(logic.numOfShips());
|
||||||
|
|
||||||
Pane root = new Pane();
|
Pane root = new Pane();
|
||||||
HBox usAgainstEnemyDivisor;
|
HBox usAgainstEnemyDivisor;
|
||||||
BorderPane centeringUserShipPane = new BorderPane();
|
BorderPane centeringUserShipPane = new BorderPane();
|
||||||
Circle cannon;
|
Circle cannon;
|
||||||
BorderPane centeringLittyShipPane = new BorderPane();
|
BorderPane centeringShipPane = new BorderPane();
|
||||||
BorderPane encompassingPane = new BorderPane();
|
BorderPane encompassingPane = new BorderPane();
|
||||||
usAgainstEnemyDivisor = new HBox();
|
usAgainstEnemyDivisor = new HBox();
|
||||||
cannon = new Circle();
|
cannon = new Circle();
|
||||||
this.cannon = cannon;
|
this.cannon = cannon;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cannon.setVisible(false);
|
cannon.setVisible(false);
|
||||||
|
|
||||||
buttonBox = new VBox();
|
buttonBox = new VBox();
|
||||||
@@ -404,7 +353,7 @@ public class ShipWarfareGUI extends Player {
|
|||||||
shipsRemaining = new Label();
|
shipsRemaining = new Label();
|
||||||
report = new Label();
|
report = new Label();
|
||||||
|
|
||||||
title.setText(String.format("%d ships from Liu Yuen's Fleet are attacking, Would you like to fight or run?", numOfLittyShips));
|
title.setText(String.format("%d ships from Liu Yuen's Fleet are attacking, Would you like to fight or run?", logic.getNumOfShips()));
|
||||||
|
|
||||||
|
|
||||||
fightButton.setText("Fight");
|
fightButton.setText("Fight");
|
||||||
@@ -463,7 +412,7 @@ public class ShipWarfareGUI extends Player {
|
|||||||
|
|
||||||
//Setting the image view
|
//Setting the image view
|
||||||
ImageView userShip = new ImageView(ourShip);
|
ImageView userShip = new ImageView(ourShip);
|
||||||
ImageView littyShip = new ImageView(enemyShip);
|
ImageView Ship = new ImageView(enemyShip);
|
||||||
|
|
||||||
BorderPane.setAlignment(userShip, javafx.geometry.Pos.CENTER);
|
BorderPane.setAlignment(userShip, javafx.geometry.Pos.CENTER);
|
||||||
userShip.setFitHeight(150.0);
|
userShip.setFitHeight(150.0);
|
||||||
@@ -482,21 +431,21 @@ public class ShipWarfareGUI extends Player {
|
|||||||
cannon.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
|
cannon.setStrokeType(javafx.scene.shape.StrokeType.INSIDE);
|
||||||
centeringUserShipPane.setRight(cannon);
|
centeringUserShipPane.setRight(cannon);
|
||||||
|
|
||||||
centeringLittyShipPane.setPrefHeight(200.0);
|
centeringShipPane.setPrefHeight(200.0);
|
||||||
centeringLittyShipPane.setPrefWidth(200.0);
|
centeringShipPane.setPrefWidth(200.0);
|
||||||
centeringLittyShipPane.setOpaqueInsets(new Insets(0.0));
|
centeringShipPane.setOpaqueInsets(new Insets(0.0));
|
||||||
HBox.setMargin(centeringLittyShipPane, new Insets(0.0, 0.0, 0.0, 200.0));
|
HBox.setMargin(centeringShipPane, new Insets(0.0, 0.0, 0.0, 200.0));
|
||||||
|
|
||||||
encompassingPane.setAlignment(littyShip, javafx.geometry.Pos.CENTER);
|
encompassingPane.setAlignment(Ship, javafx.geometry.Pos.CENTER);
|
||||||
littyShip.setFitHeight(165.0);
|
Ship.setFitHeight(165.0);
|
||||||
littyShip.setFitWidth(180.0);
|
Ship.setFitWidth(180.0);
|
||||||
littyShip.setPickOnBounds(true);
|
Ship.setPickOnBounds(true);
|
||||||
littyShip.setPreserveRatio(true);
|
Ship.setPreserveRatio(true);
|
||||||
encompassingPane.setMargin(littyShip, new Insets(0.0, 0.0, 20.0, 0.0));
|
encompassingPane.setMargin(Ship, new Insets(0.0, 0.0, 20.0, 0.0));
|
||||||
centeringLittyShipPane.setCenter(littyShip);
|
centeringShipPane.setCenter(Ship);
|
||||||
|
|
||||||
usAgainstEnemyDivisor.getChildren().add(centeringUserShipPane);
|
usAgainstEnemyDivisor.getChildren().add(centeringUserShipPane);
|
||||||
usAgainstEnemyDivisor.getChildren().add(centeringLittyShipPane);
|
usAgainstEnemyDivisor.getChildren().add(centeringShipPane);
|
||||||
fightRunBox.getChildren().add(fightButton);
|
fightRunBox.getChildren().add(fightButton);
|
||||||
fightRunBox.getChildren().add(continueButton);
|
fightRunBox.getChildren().add(continueButton);
|
||||||
fightRunBox.getChildren().add(runButton);
|
fightRunBox.getChildren().add(runButton);
|
||||||
@@ -523,13 +472,11 @@ public class ShipWarfareGUI extends Player {
|
|||||||
primaryStage.setTitle("Ship Warfare");
|
primaryStage.setTitle("Ship Warfare");
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
continueButton.setOnAction(new EventHandler<ActionEvent>() {
|
|
||||||
@Override
|
|
||||||
/**
|
/**
|
||||||
* Continue Button, engages in run logic and graphical interface
|
* Continue Button, engages in run logic and graphical interface
|
||||||
* @param event, once button is clicked, executes graphical information
|
* @param event, once button is clicked, executes graphical information
|
||||||
*/
|
*/
|
||||||
public void handle(ActionEvent event) {
|
continueButton.setOnAction(event -> {
|
||||||
shotsFired.stop();
|
shotsFired.stop();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -540,38 +487,36 @@ public class ShipWarfareGUI extends Player {
|
|||||||
shop.initializeShop(primaryStage);
|
shop.initializeShop(primaryStage);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Flee
|
//Flee
|
||||||
runButton.setOnAction(new EventHandler<ActionEvent>() {
|
|
||||||
@Override
|
|
||||||
/**
|
/**
|
||||||
* Run Button, engages in run logic and graphical interface
|
* Run Button, engages in run logic and graphical interface
|
||||||
* @param event, once button is clicked, executes graphical information
|
* @param event, once button is clicked, executes graphical information
|
||||||
*/
|
*/
|
||||||
public void handle(ActionEvent event) {
|
runButton.setOnAction(event -> {
|
||||||
|
userAttacks = false;
|
||||||
|
|
||||||
report.setVisible(true);
|
report.setVisible(true);
|
||||||
title.setVisible(true);
|
title.setVisible(true);
|
||||||
shipsRemaining.setVisible(true);
|
shipsRemaining.setVisible(true);
|
||||||
gunsLeftOrTaken.setVisible(true);
|
gunsLeftOrTaken.setVisible(true);
|
||||||
|
|
||||||
title.setText("Ayy captain we will try to run!");
|
title.setText("Ayy captain we will try to run!");
|
||||||
report.setText("Epic");
|
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
if (runFromShips() == false) {
|
if (logic.runFromShips() == false) {
|
||||||
report.setText(("Couldn't run away"));
|
report.setText(("Couldn't run away"));
|
||||||
try {
|
try {
|
||||||
winOrLose= destroyLittyShipsOrEscape(primaryStage);
|
winOrLose = destroyShipsOrEscape(primaryStage);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (winOrLose == true) {
|
if (winOrLose == true) {
|
||||||
report.setVisible(true);
|
report.setVisible(false);
|
||||||
title.setVisible(true);
|
title.setVisible(false);
|
||||||
shipsRemaining.setVisible(true);
|
shipsRemaining.setVisible(false);
|
||||||
gunsLeftOrTaken.setVisible(true);
|
gunsLeftOrTaken.setVisible(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -582,28 +527,22 @@ public class ShipWarfareGUI extends Player {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Fight
|
//Fight
|
||||||
fightButton.setOnAction(new EventHandler<ActionEvent>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
/**
|
/**
|
||||||
* Fight Button, engages in fight logic and graphical interface
|
* Fight Button, engages in fight logic and graphical interface
|
||||||
* @param event, once button is clicked, executes graphical information
|
* @param event, once button is clicked, executes graphical information
|
||||||
*/
|
*/
|
||||||
public void handle(ActionEvent event) {
|
fightButton.setOnAction(event -> {
|
||||||
report.setVisible(false);
|
userAttacks = true;
|
||||||
runAwayOrLeft.setVisible(false);
|
|
||||||
shipsRemaining.setVisible(false);
|
wipeWithTitle(report);
|
||||||
HPLeft.setVisible(false);
|
|
||||||
gunsLeftOrTaken.setVisible(false);
|
|
||||||
fightButton.setVisible(false);
|
fightButton.setVisible(false);
|
||||||
runButton.setVisible(false);
|
runButton.setVisible(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
winOrLose= destroyLittyShipsOrEscape(primaryStage);
|
winOrLose = destroyShipsOrEscape(primaryStage);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -621,18 +560,27 @@ public class ShipWarfareGUI extends Player {
|
|||||||
|
|
||||||
playerShoots(getGuns());
|
playerShoots(getGuns());
|
||||||
|
|
||||||
shotsFired.setOnFinished(new EventHandler<ActionEvent>() {
|
|
||||||
@Override
|
|
||||||
/**
|
/**
|
||||||
* When the user is completed their volley this information will be accessed
|
* When the user is completed their volley this information will be accessed
|
||||||
* @param event, once the shots fired transition is completed, execute graphical information
|
* @param event, once the shots fired transition is completed, execute graphical information
|
||||||
*/
|
*/
|
||||||
public void handle(ActionEvent event) {
|
shootingAnimation(usAgainstEnemyDivisor, cannon);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the animation of ships being destroyed and our ship being hit
|
||||||
|
* @param usAgainstEnemyDivisor divisor for us against enemy
|
||||||
|
* @param cannon circle node for displaying cannon fire
|
||||||
|
*/
|
||||||
|
public void shootingAnimation(HBox usAgainstEnemyDivisor, Circle cannon) {
|
||||||
|
shotsFired.setOnFinished(event1 -> {
|
||||||
shotsFired.stop();
|
shotsFired.stop();
|
||||||
if (!winOrLose) {
|
if (!winOrLose) {
|
||||||
shipsRetaliate();
|
shipsRetaliate();
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
report.setVisible(true);
|
report.setVisible(true);
|
||||||
continueButton.setVisible(true);
|
continueButton.setVisible(true);
|
||||||
usAgainstEnemyDivisor.setVisible(false);
|
usAgainstEnemyDivisor.setVisible(false);
|
||||||
@@ -640,13 +588,11 @@ public class ShipWarfareGUI extends Player {
|
|||||||
shotsFired.stop();
|
shotsFired.stop();
|
||||||
|
|
||||||
}
|
}
|
||||||
enemyShots.setOnFinished(new EventHandler<ActionEvent>() {
|
|
||||||
@Override
|
|
||||||
/**
|
/**
|
||||||
* When the user is completed their volley, this information will be accessed
|
* When the user is completed their volley, this information will be accessed
|
||||||
* @param event, once the enemy shots transition is completed, execute graphical information
|
* @param event, once the enemy shots transition is completed, execute graphical information
|
||||||
*/
|
*/
|
||||||
public void handle(ActionEvent event) {
|
enemyShots.setOnFinished(event11 -> {
|
||||||
fightButton.setVisible(true);
|
fightButton.setVisible(true);
|
||||||
runButton.setVisible(true);
|
runButton.setVisible(true);
|
||||||
report.setVisible(true);
|
report.setVisible(true);
|
||||||
@@ -661,21 +607,8 @@ public class ShipWarfareGUI extends Player {
|
|||||||
usAgainstEnemyDivisor.setVisible(false);
|
usAgainstEnemyDivisor.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import javafx.event.ActionEvent;
|
package gui;
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
@@ -8,12 +8,14 @@ import javafx.scene.layout.HBox;
|
|||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import logic.Player;
|
||||||
|
import logic.FileSaving;
|
||||||
|
import logic.StartLogic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-10
|
* 2019-03-10
|
||||||
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
|
* Authors: Harkamal, Vikram, Haris, Siddhant, Nathan
|
||||||
* StartGUI class, Initializes and displays the start menu for Taipan
|
* StartGUI class, Initializes and displays the start menu for Taipan
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -56,12 +58,10 @@ public class StartGUI extends Player{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the Start GUI the game.
|
* Sets up the graphical part of StartGUI and includes all logic for the class
|
||||||
*
|
* @param stage sets the stage to which we will execute the scene of the StartGUI class
|
||||||
* @param stage object of type Stage
|
|
||||||
* @return returns the stage of GUI
|
|
||||||
*/
|
*/
|
||||||
public Stage initializeStart(Stage stage) {
|
public void initializeStart(Stage stage) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an HBox at the center of the borderpane with a width of 200, height of 100 and spacing of 10.
|
* Creates an HBox at the center of the borderpane with a width of 200, height of 100 and spacing of 10.
|
||||||
@@ -186,38 +186,30 @@ public class StartGUI extends Player{
|
|||||||
* scenario 2 gives the player 5 guns.
|
* scenario 2 gives the player 5 guns.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
startButton.setOnAction(new EventHandler<ActionEvent>() {
|
startButton.setOnAction(event -> {
|
||||||
@Override
|
StartLogic startLogic = new StartLogic(getPlayer());
|
||||||
public void handle(ActionEvent event) {
|
|
||||||
if (Start.getSelectedToggle() == cashChoice) {
|
if (Start.getSelectedToggle() == cashChoice) {
|
||||||
setMoney(400);
|
startLogic.money_and_debt();
|
||||||
setDebt(5000);
|
|
||||||
setGuns(0);
|
|
||||||
}
|
}
|
||||||
if (Start.getSelectedToggle() == gunChoice) {
|
if (Start.getSelectedToggle() == gunChoice) {
|
||||||
setGuns(5);
|
startLogic.guns();
|
||||||
}
|
}
|
||||||
|
|
||||||
String response = nameField.getText();
|
String response = nameField.getText();
|
||||||
// purely for testing purposes.
|
// purely for testing purposes.
|
||||||
if (response.equalsIgnoreCase("Vikram")) {
|
if (response.equalsIgnoreCase("Vikram")) {
|
||||||
setMoney(999999999);
|
startLogic.cheat();
|
||||||
setBank(999999999);
|
|
||||||
setGuns(999);
|
|
||||||
setHP(99999999);
|
|
||||||
setCargoSpace(Integer.MAX_VALUE);
|
setCargoSpace(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
setFirm(response);
|
setFirm(response);
|
||||||
|
|
||||||
|
setPlayer(startLogic.getPlayer());
|
||||||
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
|
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
|
||||||
shop.initializeShop(stage);
|
shop.initializeShop(stage);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
continueButton.setOnAction(new EventHandler<ActionEvent>() {
|
continueButton.setOnAction(event -> {
|
||||||
@Override
|
|
||||||
public void handle(ActionEvent event) {
|
|
||||||
FileSaving saving = new FileSaving();
|
FileSaving saving = new FileSaving();
|
||||||
if(saving.loadFile() != null){
|
if(saving.loadFile() != null){
|
||||||
TaipanShopGUI shop = new TaipanShopGUI(saving.loadFile());
|
TaipanShopGUI shop = new TaipanShopGUI(saving.loadFile());
|
||||||
@@ -227,7 +219,6 @@ public class StartGUI extends Player{
|
|||||||
else{
|
else{
|
||||||
authors.setText("There are no previous saves!");
|
authors.setText("There are no previous saves!");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Scene root = new Scene(borderPane, 600, 480);
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
@@ -238,6 +229,5 @@ public class StartGUI extends Player{
|
|||||||
stage.setScene(root);
|
stage.setScene(root);
|
||||||
stage.setHeight(510);
|
stage.setHeight(510);
|
||||||
stage.setWidth(600);
|
stage.setWidth(600);
|
||||||
return stage;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* TaipanShopGUI deals with setting the stage for shop; the shop shows much of the user's inventory
|
* TaipanShopGUI deals with setting the stage for shop.
|
||||||
* and features the buying and selling aspect of the game.
|
|
||||||
*
|
*
|
||||||
* Author: Vikram Bawa
|
* Author: Vikram Bawa
|
||||||
*/
|
*/
|
||||||
|
package gui;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
@@ -15,10 +15,14 @@ import javafx.scene.control.TextField;
|
|||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
|
import javafx.scene.shape.StrokeType;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import java.util.Random;
|
import logic.FileSaving;
|
||||||
|
import logic.Player;
|
||||||
|
import logic.TaipanShopLogic;
|
||||||
|
|
||||||
public class TaipanShopGUI extends Player {
|
public class TaipanShopGUI extends Player {
|
||||||
private Label firm = new Label();
|
private Label firm = new Label();
|
||||||
@@ -45,12 +49,13 @@ public class TaipanShopGUI extends Player{
|
|||||||
private Button generalButton = new Button();
|
private Button generalButton = new Button();
|
||||||
private TextField numberInput = new TextField();
|
private TextField numberInput = new TextField();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
* 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.
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
*/
|
*/
|
||||||
public TaipanShopGUI(Player player) {
|
public TaipanShopGUI(logic.Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
}
|
}
|
||||||
@@ -65,56 +70,6 @@ public class TaipanShopGUI extends Player{
|
|||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* this method is when the shop is accessed, randomizing the prices of all the items.
|
|
||||||
*/
|
|
||||||
public void updatePrices() {
|
|
||||||
String s = "\t" + getName() + ", the price of ";
|
|
||||||
double value = 80 * Math.random();
|
|
||||||
Random rand = new Random();
|
|
||||||
setOpiumPrice((rand.nextInt(201) + 60) * 100);
|
|
||||||
setSilkPrice((rand.nextInt(201) + 60) * 10);
|
|
||||||
setArmsPrice((rand.nextInt(21) + 6) * 10);
|
|
||||||
setGeneralPrice((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) {
|
|
||||||
setOpiumPrice(getOpiumPrice() / 5);
|
|
||||||
textOut.setText(s + "Opium has dropped to " + getOpiumPrice() + "!!!\n" + textOut.getText());
|
|
||||||
} else {
|
|
||||||
setOpiumPrice(getOpiumPrice() * 5);
|
|
||||||
textOut.setText(s + "Opium has risen to " + getOpiumPrice() + "!!!\n" + textOut.getText());
|
|
||||||
}
|
|
||||||
} else if (value < 4) {
|
|
||||||
if (value < 3) {
|
|
||||||
setSilkPrice(getSilkPrice() / 5);
|
|
||||||
textOut.setText(s + "Silk has dropped to " + getSilkPrice() + "!!!\n" + textOut.getText());
|
|
||||||
} else {
|
|
||||||
setSilkPrice(getSilkPrice() * 5);
|
|
||||||
textOut.setText(s + "Silk has risen to " + getSilkPrice() + "!!!\n" + textOut.getText());
|
|
||||||
}
|
|
||||||
} else if (value < 6) {
|
|
||||||
if (value < 3) {
|
|
||||||
setArmsPrice(getArmsPrice() / 5);
|
|
||||||
textOut.setText(s + "Arms has dropped to " + getArmsPrice() + "!!!\n" + textOut.getText());
|
|
||||||
} else {
|
|
||||||
setArmsPrice(getArmsPrice() * 5);
|
|
||||||
textOut.setText(s + "Arms has risen to " + getArmsPrice() + "!!!\n" + textOut.getText());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (value < 7) {
|
|
||||||
setGeneralPrice(1);
|
|
||||||
textOut.setText(s + "General Cargo has dropped to 1!!!\n" + textOut.getText());
|
|
||||||
} else {
|
|
||||||
setGeneralPrice(getGeneralPrice() * 5);
|
|
||||||
textOut.setText(s + "General Cargo has risen to " + getGeneralPrice() + "!!!\n" + textOut.getText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default dialogue of simply stating the prices of the items.
|
* Sets the default dialogue of simply stating the prices of the items.
|
||||||
*/
|
*/
|
||||||
@@ -161,7 +116,6 @@ public class TaipanShopGUI extends Player{
|
|||||||
loanButton.setVisible(false);
|
loanButton.setVisible(false);
|
||||||
armsButton.setVisible(false);
|
armsButton.setVisible(false);
|
||||||
quitButton.setVisible(true);
|
quitButton.setVisible(true);
|
||||||
//quitButton.setDefaultButton(true);
|
|
||||||
opiumButton.setVisible(false);
|
opiumButton.setVisible(false);
|
||||||
silkButton.setVisible(false);
|
silkButton.setVisible(false);
|
||||||
numberInput.setVisible(false);
|
numberInput.setVisible(false);
|
||||||
@@ -175,7 +129,6 @@ public class TaipanShopGUI extends Player{
|
|||||||
cargoButton.setVisible(true);
|
cargoButton.setVisible(true);
|
||||||
loanButton.setVisible(true);
|
loanButton.setVisible(true);
|
||||||
quitButton.setVisible(true);
|
quitButton.setVisible(true);
|
||||||
//quitButton.setDefaultButton(true);
|
|
||||||
opiumButton.setVisible(false);
|
opiumButton.setVisible(false);
|
||||||
silkButton.setVisible(false);
|
silkButton.setVisible(false);
|
||||||
numberInput.setVisible(false);
|
numberInput.setVisible(false);
|
||||||
@@ -190,7 +143,6 @@ public class TaipanShopGUI extends Player{
|
|||||||
loanButton.setVisible(true);
|
loanButton.setVisible(true);
|
||||||
numberInput.setVisible(false);
|
numberInput.setVisible(false);
|
||||||
quitButton.setVisible(true);
|
quitButton.setVisible(true);
|
||||||
//quitButton.setDefaultButton(true);
|
|
||||||
opiumButton.setVisible(false);
|
opiumButton.setVisible(false);
|
||||||
silkButton.setVisible(false);
|
silkButton.setVisible(false);
|
||||||
generalButton.setVisible(false);
|
generalButton.setVisible(false);
|
||||||
@@ -200,16 +152,16 @@ public class TaipanShopGUI extends Player{
|
|||||||
} else if (state.equals("input")) {
|
} else if (state.equals("input")) {
|
||||||
buyButton.setVisible(false);
|
buyButton.setVisible(false);
|
||||||
sellButton.setVisible(false);
|
sellButton.setVisible(false);
|
||||||
|
generalButton.setVisible(false);
|
||||||
bankButton.setVisible(false);
|
bankButton.setVisible(false);
|
||||||
cargoButton.setVisible(false);
|
|
||||||
loanButton.setVisible(false);
|
loanButton.setVisible(false);
|
||||||
numberInput.setVisible(true);
|
|
||||||
quitButton.setVisible(false);
|
quitButton.setVisible(false);
|
||||||
opiumButton.setVisible(false);
|
opiumButton.setVisible(false);
|
||||||
|
cargoButton.setVisible(false);
|
||||||
silkButton.setVisible(false);
|
silkButton.setVisible(false);
|
||||||
generalButton.setVisible(false);
|
|
||||||
armsButton.setVisible(false);
|
armsButton.setVisible(false);
|
||||||
retireButton.setVisible(false);
|
retireButton.setVisible(false);
|
||||||
|
numberInput.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,102 +235,14 @@ public class TaipanShopGUI extends Player{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the shop on the given stage as a parameter.
|
* Sets up the graphical part of TaipanGUI and includes all logic for the class
|
||||||
*
|
*
|
||||||
* @param stage
|
* @param stage sets the stage to which we will execute the scene of the TaipanGUI class
|
||||||
*/
|
*/
|
||||||
public void initializeShop(Stage stage) {
|
public void initializeShop(Stage stage) {
|
||||||
FileSaving saving = new FileSaving();
|
FileSaving saving = new FileSaving();
|
||||||
saving.saveFile(getPlayer());
|
saving.saveFile(getPlayer());
|
||||||
|
|
||||||
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();
|
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.setMnemonicParsing(false);
|
||||||
buyButton.setPrefHeight(25.0);
|
buyButton.setPrefHeight(25.0);
|
||||||
@@ -492,7 +356,6 @@ public class TaipanShopGUI extends Player{
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
saving.saveFile(getPlayer());
|
|
||||||
setIsPriceChanged(1);
|
setIsPriceChanged(1);
|
||||||
TravelGUI travelGUI = new TravelGUI(getPlayer());
|
TravelGUI travelGUI = new TravelGUI(getPlayer());
|
||||||
travelGUI.initializeTravel(stage);
|
travelGUI.initializeTravel(stage);
|
||||||
@@ -656,19 +519,137 @@ public class TaipanShopGUI extends Player{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateStage();
|
updateStage(firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText);
|
||||||
|
|
||||||
buttonSetup("reset");
|
buttonSetup("reset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
stage.setTitle("Shop");
|
||||||
|
stage.setResizable(false);
|
||||||
|
flowPane.getChildren().addAll(buyButton, sellButton, bankButton, cargoButton, loanButton, quitButton, retireButton, opiumButton, silkButton, armsButton, generalButton, numberInput);
|
||||||
|
Scene root = new Scene(declareStage(flowPane,firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText,textOut), 600, 480);
|
||||||
|
stage.setScene(root);
|
||||||
|
root.getStylesheets().add("styleguide.css");
|
||||||
|
|
||||||
|
// general updates to the buttons, user stats/inventory, and text.
|
||||||
|
buttonSetup("reset");
|
||||||
|
if(getIsPriceChanged() == 0 || getIsPriceChanged() == 2){
|
||||||
|
TaipanShopLogic logic = new TaipanShopLogic(getPlayer());
|
||||||
|
String temp = logic.updatePrices();
|
||||||
|
setPlayer(logic.getPlayer());
|
||||||
|
defaultTextOut();
|
||||||
|
textOut.setText(temp + textOut.getText());
|
||||||
|
}
|
||||||
|
defaultTextOut();
|
||||||
|
updateStage(firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The anchor pane shown to the user, used to display the current stats of the player
|
||||||
|
* @param flowPane,firm,wItemsText,wItemSpaceText,locationText, gunsText, inventoryText, inventoryHeldText, shipStatusText, cashText, bankText assigned from the original element inside of the JavaFX scene
|
||||||
|
* @param textOut the output so that the player can see all of the text given
|
||||||
|
* @return The AnchorPane with all the elements already declared
|
||||||
|
*/
|
||||||
|
public AnchorPane declareStage(FlowPane flowPane,Label firm, Label wItemsText, Label wItemSpaceText, Label locationText, Label gunsText, Label inventoryText, Label inventoryHeldText, Label shipStatusText, Label cashText, Label bankText, Label textOut) {
|
||||||
|
//Declaring all the elements required for the information on screen
|
||||||
|
Rectangle dialogueRectangle = new Rectangle();
|
||||||
|
Rectangle inventoryRectangle = new Rectangle();
|
||||||
|
Rectangle warehouseRectangle = new Rectangle();
|
||||||
|
AnchorPane anchorPane = new AnchorPane();
|
||||||
|
GridPane gridPane = new GridPane();
|
||||||
|
ColumnConstraints columnConstraints = new ColumnConstraints();
|
||||||
|
RowConstraints rowConstraints = new RowConstraints();
|
||||||
|
RowConstraints rowConstraints0 = new RowConstraints();
|
||||||
|
RowConstraints rowConstraints1 = new RowConstraints();
|
||||||
|
RowConstraints rowConstraints2 = new RowConstraints();
|
||||||
|
RowConstraints rowConstraints3 = new RowConstraints();
|
||||||
|
RowConstraints rowConstraints4 = new RowConstraints();
|
||||||
|
HBox hBox = new HBox();
|
||||||
|
HBox hBox0 = new HBox();
|
||||||
|
Font size14 = new Font(14.0);
|
||||||
|
Label warehouseText = new Label();
|
||||||
|
|
||||||
|
dialogueRectangle.setFill(Color.WHITE);
|
||||||
|
dialogueRectangle.setHeight(180.0);
|
||||||
|
dialogueRectangle.setLayoutX(8.0);
|
||||||
|
dialogueRectangle.setLayoutY(294.0);
|
||||||
|
dialogueRectangle.setStroke(Color.BLACK);
|
||||||
|
dialogueRectangle.setStrokeType(StrokeType.INSIDE);
|
||||||
|
dialogueRectangle.setWidth(582.0);
|
||||||
|
|
||||||
|
inventoryRectangle.setFill(Color.WHITE);
|
||||||
|
inventoryRectangle.setHeight(108.0);
|
||||||
|
inventoryRectangle.setLayoutX(8.0);
|
||||||
|
inventoryRectangle.setLayoutY(147.0);
|
||||||
|
inventoryRectangle.setStroke(Color.BLACK);
|
||||||
|
inventoryRectangle.setStrokeType(StrokeType.INSIDE);
|
||||||
|
inventoryRectangle.setWidth(405.0);
|
||||||
|
|
||||||
|
warehouseRectangle.setFill(Color.WHITE);
|
||||||
|
warehouseRectangle.setHeight(108.0);
|
||||||
|
warehouseRectangle.setLayoutY(33.0);
|
||||||
|
warehouseRectangle.setLayoutX(8.0);
|
||||||
|
warehouseRectangle.setStroke(Color.BLACK);
|
||||||
|
warehouseRectangle.setStrokeType(StrokeType.INSIDE);
|
||||||
|
warehouseRectangle.setWidth(405.0);
|
||||||
|
|
||||||
|
anchorPane.setPrefHeight(480.0);
|
||||||
|
anchorPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
gridPane.setPrefHeight(480.0);
|
||||||
|
gridPane.setPrefWidth(600.0);
|
||||||
|
|
||||||
|
columnConstraints.setMaxWidth(590.0);
|
||||||
|
columnConstraints.setMinWidth(0.0);
|
||||||
|
columnConstraints.setPrefWidth(590.0);
|
||||||
|
|
||||||
|
rowConstraints.setMinHeight(20.0);
|
||||||
|
rowConstraints.setPrefHeight(20.0);
|
||||||
|
|
||||||
|
rowConstraints0.setMaxHeight(122.0);
|
||||||
|
rowConstraints0.setMinHeight(10.0);
|
||||||
|
rowConstraints0.setPrefHeight(117.0);
|
||||||
|
|
||||||
|
rowConstraints1.setMaxHeight(163.0);
|
||||||
|
rowConstraints1.setMinHeight(10.0);
|
||||||
|
rowConstraints1.setPrefHeight(112.0);
|
||||||
|
|
||||||
|
rowConstraints2.setMaxHeight(126.0);
|
||||||
|
rowConstraints2.setMinHeight(0.0);
|
||||||
|
rowConstraints2.setPrefHeight(42.0);
|
||||||
|
|
||||||
|
rowConstraints3.setMaxHeight(269.0);
|
||||||
|
rowConstraints3.setMinHeight(10.0);
|
||||||
|
rowConstraints3.setPrefHeight(118.0);
|
||||||
|
|
||||||
|
rowConstraints4.setMaxHeight(179.0);
|
||||||
|
rowConstraints4.setMinHeight(10.0);
|
||||||
|
rowConstraints4.setPrefHeight(52.0);
|
||||||
|
|
||||||
|
gridPane.setPadding(new Insets(10.0, 10.0, 10.0, 0.0));
|
||||||
|
|
||||||
|
GridPane.setRowIndex(hBox, 1);
|
||||||
|
hBox.setPrefHeight(100.0);
|
||||||
|
hBox.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
GridPane.setRowIndex(hBox0, 2);
|
||||||
|
hBox0.setPrefHeight(100.0);
|
||||||
|
hBox0.setPrefWidth(200.0);
|
||||||
|
|
||||||
|
GridPane.setRowIndex(flowPane, 5);
|
||||||
|
flowPane.setAlignment(Pos.CENTER);
|
||||||
|
flowPane.setHgap(5.0);
|
||||||
|
flowPane.setPrefHeight(200.0);
|
||||||
|
flowPane.setPrefWidth(200.0);
|
||||||
|
|
||||||
firm.setAlignment(Pos.CENTER);
|
firm.setAlignment(Pos.CENTER);
|
||||||
firm.setPrefHeight(27.0);
|
firm.setPrefHeight(27.0);
|
||||||
firm.setPrefWidth(632.0);
|
firm.setPrefWidth(632.0);
|
||||||
firm.setFont(new Font(18.0));
|
firm.setFont(new Font(18.0));
|
||||||
|
|
||||||
Label warehouseText = new Label();
|
|
||||||
warehouseText.setAlignment(Pos.CENTER);
|
warehouseText.setAlignment(Pos.CENTER);
|
||||||
warehouseText.setPrefHeight(108.0);
|
warehouseText.setPrefHeight(108.0);
|
||||||
warehouseText.setPrefWidth(100.0);
|
warehouseText.setPrefWidth(100.0);
|
||||||
@@ -681,18 +662,16 @@ public class TaipanShopGUI extends Player{
|
|||||||
wItemsText.setFont(size14);
|
wItemsText.setFont(size14);
|
||||||
|
|
||||||
wItemSpaceText.setPrefHeight(108.0);
|
wItemSpaceText.setPrefHeight(108.0);
|
||||||
wItemSpaceText.setPrefWidth(210.0);
|
wItemSpaceText.setPrefWidth(215.0);
|
||||||
wItemSpaceText.setFont(size14);
|
wItemSpaceText.setFont(size14);
|
||||||
|
|
||||||
locationText.setAlignment(Pos.BOTTOM_RIGHT);
|
locationText.setAlignment(Pos.BOTTOM_CENTER);
|
||||||
locationText.setPrefHeight(106.0);
|
locationText.setPrefHeight(106.0);
|
||||||
locationText.setPrefWidth(140.0);
|
locationText.setPrefWidth(175.0);
|
||||||
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
locationText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
locationText.setFont(size14);
|
locationText.setFont(size14);
|
||||||
|
|
||||||
inventoryText.setAlignment(Pos.CENTER);
|
inventoryText.setAlignment(Pos.CENTER);
|
||||||
inventoryText.setPrefWidth(110.0);
|
|
||||||
inventoryText.setPrefHeight(108.0);
|
|
||||||
inventoryText.setFont(size14);
|
inventoryText.setFont(size14);
|
||||||
|
|
||||||
inventoryHeldText.setAlignment(Pos.CENTER);
|
inventoryHeldText.setAlignment(Pos.CENTER);
|
||||||
@@ -708,7 +687,7 @@ public class TaipanShopGUI extends Player{
|
|||||||
shipStatusText.setAlignment(Pos.TOP_CENTER);
|
shipStatusText.setAlignment(Pos.TOP_CENTER);
|
||||||
shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
shipStatusText.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||||
shipStatusText.setPrefHeight(110.0);
|
shipStatusText.setPrefHeight(110.0);
|
||||||
shipStatusText.setPrefWidth(200.0);
|
shipStatusText.setPrefWidth(180.0);
|
||||||
shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
shipStatusText.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);
|
||||||
shipStatusText.setFont(size14);
|
shipStatusText.setFont(size14);
|
||||||
|
|
||||||
@@ -738,146 +717,39 @@ public class TaipanShopGUI extends Player{
|
|||||||
|
|
||||||
hBox0.getChildren().addAll(inventoryText, inventoryHeldText, gunsText, shipStatusText);
|
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.getColumnConstraints().add(columnConstraints);
|
||||||
gridPane.getRowConstraints().addAll(rowConstraints, rowConstraints0, rowConstraints1, rowConstraints2, rowConstraints3, rowConstraints4);
|
gridPane.getRowConstraints().addAll(rowConstraints, rowConstraints0, rowConstraints1, rowConstraints2, rowConstraints3, rowConstraints4);
|
||||||
gridPane.getChildren().addAll(firm, hBox, hBox0, cashText, bankText, textOut, flowPane);
|
gridPane.getChildren().addAll(firm, hBox, hBox0, cashText, bankText, textOut, flowPane);
|
||||||
|
|
||||||
anchorPane.getChildren().add(gridPane);
|
anchorPane.getChildren().add(gridPane);
|
||||||
|
|
||||||
Scene root = new Scene(anchorPane, 600, 480);
|
return anchorPane;
|
||||||
|
|
||||||
root.getStylesheets().add("styleguide.css");
|
|
||||||
stage.setTitle("Shop");
|
|
||||||
stage.setResizable(false);
|
|
||||||
stage.setScene(root);
|
|
||||||
buyButton.setFocusTraversable(false);
|
|
||||||
sellButton.setFocusTraversable(false);
|
|
||||||
bankButton.setFocusTraversable(false);
|
|
||||||
loanButton.setFocusTraversable(false);
|
|
||||||
generalButton.setFocusTraversable(false);
|
|
||||||
armsButton.setFocusTraversable(false);
|
|
||||||
silkButton.setFocusTraversable(false);
|
|
||||||
opiumButton.setFocusTraversable(false);
|
|
||||||
sellButton.setFocusTraversable(false);
|
|
||||||
retireButton.setFocusTraversable(false);
|
|
||||||
cargoButton.setFocusTraversable(false);
|
|
||||||
quitButton.setFocusTraversable(false);
|
|
||||||
|
|
||||||
// general updates to the buttons, user stats/inventory, and text.
|
|
||||||
buttonSetup("reset");
|
|
||||||
if(getIsPriceChanged() == 0 || getIsPriceChanged() == 2){
|
|
||||||
updatePrices();
|
|
||||||
}
|
|
||||||
defaultTextOut();
|
|
||||||
updateStage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* converts the user's location (an integer) to a String, and returns it.
|
* Updates the current stage shown to the player with all the brand new information
|
||||||
*
|
* @param firm,wItemsText,wItemSpaceText,locationText, gunsText, inventoryText, inventoryHeldText, shipStatusText, cashText, bankText assigned from the original element inside of the JavaFX scene
|
||||||
* @return location -- the user's location as a string; the actual name of the location.
|
|
||||||
*/
|
*/
|
||||||
public String getStringLocation() {
|
public void updateStage(Label firm, Label wItemsText, Label wItemSpaceText, Label locationText, Label gunsText, Label inventoryText, Label inventoryHeldText, Label shipStatusText, Label cashText, Label bankText) {
|
||||||
String location;
|
TaipanShopLogic logic = new TaipanShopLogic(super.getPlayer());
|
||||||
switch (getLocation()) {
|
firm.setText(String.format("Firm: %s, %s", getName(), logic.getStringLocation()));
|
||||||
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 (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", getName(), getStringLocation()));
|
|
||||||
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", getwOpium(), getwSilk(), getwArms(), getwGeneral()));
|
wItemsText.setText(String.format("\n %d\n %d\n %d\n %d", getwOpium(), getwSilk(), getwArms(), getwGeneral()));
|
||||||
int itemsInWarehouse = getwOpium() + getwGeneral() + getwArms() + getwSilk();
|
int itemsInWarehouse = getwOpium() + getwGeneral() + getwArms() + getwSilk();
|
||||||
wItemSpaceText.setText(String.format("\n\t\tIn use:\n\t\t %d \n\t\tVacant:\n\t\t %d", itemsInWarehouse, (10000 - itemsInWarehouse)));
|
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()));
|
locationText.setText(String.format("Location\n%s", logic.getStringLocation()));
|
||||||
int itemsInInventory = getCargoSpace() - getSilkHeld() - getOpiumHeld() - getGeneralHeld() - getArmsHeld() - 10 * getGuns();
|
int itemsInInventory = getCargoSpace() - getSilkHeld() - getOpiumHeld() - getGeneralHeld() - getArmsHeld() - 10 * getGuns();
|
||||||
|
//If the inventory is too full
|
||||||
if (itemsInInventory < 0) {
|
if (itemsInInventory < 0) {
|
||||||
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
|
inventoryText.setText(" Overloaded\n\t Opium\n\t Silk\n\t Arms\n\t General");
|
||||||
} else {
|
}
|
||||||
|
//If the inventory isn't too full
|
||||||
|
else {
|
||||||
inventoryText.setText(String.format(" Hold %d\n\t Opium\n\t Silk\n\t Arms\n\t General", itemsInInventory));
|
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 ", getGuns()));
|
gunsText.setText(String.format("Guns %d\n\n\n\n ", getGuns()));
|
||||||
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", getOpiumHeld(), getSilkHeld(), getArmsHeld(), getGeneralHeld()));
|
inventoryHeldText.setText(String.format("\n %d\n %d\n %d\n %d", getOpiumHeld(), getSilkHeld(), getArmsHeld(), getGeneralHeld()));
|
||||||
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", getDebt(), shipStatusString(), getHP()));
|
shipStatusText.setText(String.format("\tDebt\n\t%d\n\n\tShip status\n\t%s: %d", getDebt(), logic.shipStatusString(), getHP()));
|
||||||
cashText.setText(String.format(" Cash: $%,d", getMoney()));
|
cashText.setText(String.format(" Cash: $%,d", getMoney()));
|
||||||
bankText.setText(String.format("Bank: $%,d", getBank()));
|
bankText.setText(String.format("Bank: $%,d", getBank()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
283
src/gui/TravelGUI.java
Normal file
283
src/gui/TravelGUI.java
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TravelGUI is the class in which takes the player from location to location
|
||||||
|
* Author: Harkamal Randhawa
|
||||||
|
*/
|
||||||
|
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.input.KeyEvent;
|
||||||
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import logic.Player;
|
||||||
|
import logic.TravelLogic;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class TravelGUI extends 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 FlowPane flowPane = new FlowPane();
|
||||||
|
|
||||||
|
private Button quitButton = new Button();
|
||||||
|
private Button continueButton = new Button();
|
||||||
|
private TextField numberInput = new TextField();
|
||||||
|
|
||||||
|
private Boolean peasantShipScene = 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);
|
||||||
|
setPlayer(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 void initializeTravel(Stage stage) {
|
||||||
|
|
||||||
|
|
||||||
|
//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(getPlayer());
|
||||||
|
taipanShopGUI.initializeShop(stage);
|
||||||
|
stage.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
//Continues on to either shop or shipwarfare
|
||||||
|
continueButton.setOnAction(event -> {
|
||||||
|
continueButton(stage);
|
||||||
|
});
|
||||||
|
|
||||||
|
//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 -> {
|
||||||
|
numberInput(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
firm.setAlignment(Pos.CENTER);
|
||||||
|
firm.setPrefHeight(27.0);
|
||||||
|
firm.setPrefWidth(632.0);
|
||||||
|
firm.setFont(new Font(18.0));
|
||||||
|
flowPane.getChildren().addAll(numberInput, quitButton, continueButton);
|
||||||
|
TaipanShopGUI shop = new TaipanShopGUI(super.getPlayer());
|
||||||
|
Scene root = new Scene(shop.declareStage(flowPane,firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText,textOut), 600, 480);
|
||||||
|
root.getStylesheets().add("styleguide.css");
|
||||||
|
//Updates the stage for the first-time you read it
|
||||||
|
shop.updateStage(firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText);
|
||||||
|
textOut.setText("\tTaipan, do you wish to go to:\n\n\t\t1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n\t\t5) Manila, 6) Singapore, or 7) Batavia?\n\n\tAfter typing the number you want to go to press 'Enter' or 'Z'");
|
||||||
|
stage.setTitle("Travel");
|
||||||
|
stage.setResizable(false);
|
||||||
|
stage.setScene(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs if the continue button is pressed. Used to leave the Travel Screen
|
||||||
|
* @param stage the stage in which the JavaFX class is brought into
|
||||||
|
*/
|
||||||
|
public void continueButton(Stage stage) {
|
||||||
|
//If there are ships attacking, move to the ShipWarfare method
|
||||||
|
if(peasantShipScene && getAttackingShips()){
|
||||||
|
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
|
||||||
|
try {
|
||||||
|
ship.initializeShip(stage);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
//If nothing is happening either create a random event or force the player into the shop
|
||||||
|
else if(shopScene){
|
||||||
|
Random rand = new Random();
|
||||||
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
//Forces the player into the shop
|
||||||
|
if(randGenNum >= 2) {
|
||||||
|
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
|
||||||
|
shop.initializeShop(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
//Creates a random event for the player
|
||||||
|
else {
|
||||||
|
RandomEventGUI randomEventGUI = new RandomEventGUI(getPlayer());
|
||||||
|
randomEventGUI.initializeRandomEventGUI(stage);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs if the numberInput is given and input and the Player has pressed Enter or Z
|
||||||
|
* @param event the input which will be processed and given a proper response afterwars
|
||||||
|
*/
|
||||||
|
public void numberInput(KeyEvent event) {
|
||||||
|
//Run the player has pressed Enter or Z
|
||||||
|
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(getCargoSpace() >= (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
|
||||||
|
traveling(event, response, hasTraveled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Run if the player cargo is too much
|
||||||
|
else if (getCargoSpace() < (getOpiumHeld()+ (getGuns()*10)+getSilkHeld() + getArmsHeld() + getGeneralHeld())){
|
||||||
|
textOut.setText(" "+getName() + " the cargo is too heavy! We can't set sail!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs if the numberInput is given and input and the Player has pressed Enter or Z
|
||||||
|
* @param event the input which will be processed and given a proper response afterwards
|
||||||
|
*/
|
||||||
|
public void traveling(KeyEvent event, int response, boolean hasTraveled) {
|
||||||
|
//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 != getLocation() && response > 0 && 8 > response && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
|
||||||
|
hasTraveled = seaAtlas(response);
|
||||||
|
randomEventSea(response);
|
||||||
|
setBank((int) (getBank() * 1.01));
|
||||||
|
setDebt((int) (getDebt() * 1.01));
|
||||||
|
setIsPriceChanged(2);
|
||||||
|
stormScene = false;
|
||||||
|
|
||||||
|
} else{
|
||||||
|
responseTravel(response);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
textOut.setText("\tSorry, " + getName() + " could you say that again?");
|
||||||
|
}
|
||||||
|
if (hasTraveled) {
|
||||||
|
continueButton.setVisible(true);
|
||||||
|
continueButton.setDefaultButton(true);
|
||||||
|
quitButton.setVisible(false);
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
shopScene = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the User's response to the location they want to travel to and returns a output
|
||||||
|
* @param response Based on the number either asks for the player's input again or stops.
|
||||||
|
*/
|
||||||
|
public void responseTravel(int response) {
|
||||||
|
if(response == getLocation()){
|
||||||
|
textOut.setText("\tYou're already here " + getName() + "\n");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
textOut.setText("\t" + getName() + "; Sorry but could you say that again?");
|
||||||
|
}
|
||||||
|
textOut.setText(textOut.getText() + "\n\n\t\t1) Hong Kong, 2) Shanghai, 3) Nagasaki, 4) Saigon,\n\t\t5) Manila, 6) Singapore, or 7) Batavia?");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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\tArriving at Hong Kong");
|
||||||
|
setLocation(1);
|
||||||
|
return true;
|
||||||
|
case 2:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Shanghai");
|
||||||
|
setLocation(2);
|
||||||
|
return true;
|
||||||
|
case 3:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Nagasaki");
|
||||||
|
setLocation(3);
|
||||||
|
return true;
|
||||||
|
case 4:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Saigon");
|
||||||
|
setLocation(4);
|
||||||
|
return true;
|
||||||
|
case 5:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Manila");
|
||||||
|
setLocation(5);
|
||||||
|
return true;
|
||||||
|
case 6:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Singapore");
|
||||||
|
setLocation(6);
|
||||||
|
return true;
|
||||||
|
case 7:
|
||||||
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Batavia");
|
||||||
|
setLocation(7);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
textOut.setText("\tSorry but could you say that again " + 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) {
|
||||||
|
Random rand = new Random();
|
||||||
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
if (randGenNum == 1) {
|
||||||
|
continueButton.setVisible(true);
|
||||||
|
continueButton.setDefaultButton(true);
|
||||||
|
quitButton.setVisible(false);
|
||||||
|
numberInput.setVisible(false);
|
||||||
|
textOut.setText("\tWe see a ship on the horizon " + getName() + "; Prepare for combat!");
|
||||||
|
peasantShipScene = true;
|
||||||
|
}else if (randGenNum == 2) {
|
||||||
|
textOut.setText("\tStorm " + getName() + "! ");
|
||||||
|
TravelLogic travelLogic = new TravelLogic(getPlayer());
|
||||||
|
textOut.setText(textOut.getText()+"\n\t" + travelLogic.disaster(locationOfTravel));
|
||||||
|
setPlayer(travelLogic.getPlayer());
|
||||||
|
textOut.setText(textOut.getText() + "\n " + "We made it!");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
@@ -6,10 +9,12 @@ import javafx.scene.layout.HBox;
|
|||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import logic.Player;
|
||||||
|
import logic.WarehouseLogic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-19
|
* 2019-03-19
|
||||||
* Authors:Siddhant, Vikram, Harkamal, Haris, Nathan
|
* Authors:Siddhant and Harkamal
|
||||||
* WarehouseGUI allows the user to store goods in a warehouse in order to have more hold on the ship
|
* WarehouseGUI allows the user to store goods in a warehouse in order to have more hold on the ship
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -87,13 +92,7 @@ public class WarehouseGUI extends Player{
|
|||||||
textField = new TextField();
|
textField = new TextField();
|
||||||
|
|
||||||
//Creating the box for the warehouse GUI
|
//Creating the box for the warehouse GUI
|
||||||
borderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
|
settingBorderFormat(hBox, vBox);
|
||||||
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
|
||||||
hBox.setPrefHeight(100.0);
|
|
||||||
hBox.setPrefWidth(200.0);
|
|
||||||
hBox.setSpacing(10.0);
|
|
||||||
|
|
||||||
vBox.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
|
||||||
vBox.setPrefHeight(200.0);
|
vBox.setPrefHeight(200.0);
|
||||||
vBox.setPrefWidth(100.0);
|
vBox.setPrefWidth(100.0);
|
||||||
|
|
||||||
@@ -134,20 +133,14 @@ public class WarehouseGUI extends Player{
|
|||||||
|
|
||||||
|
|
||||||
//Takes you to the HK warehouse
|
//Takes you to the HK warehouse
|
||||||
borderPane.setAlignment(title, javafx.geometry.Pos.CENTER);
|
borderPane.setAlignment(title, Pos.CENTER);
|
||||||
title.setText("Hong Kong Warehouse");
|
title.setText("Hong Kong Warehouse");
|
||||||
title.setFont(new Font(24.0));
|
title.setFont(new Font(24.0));
|
||||||
title.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
|
title.setPadding(new Insets(10.0, 0.0, 0.0, 0.0));
|
||||||
borderPane.setTop(title);
|
borderPane.setTop(title);
|
||||||
|
|
||||||
// Making the BOX again
|
// Making the BOX again
|
||||||
borderPane.setAlignment(hBox0, javafx.geometry.Pos.CENTER);
|
settingBorderFormat(hBox0, vBox0);
|
||||||
hBox0.setAlignment(javafx.geometry.Pos.CENTER);
|
|
||||||
hBox0.setPrefHeight(100.0);
|
|
||||||
hBox0.setPrefWidth(200.0);
|
|
||||||
hBox0.setSpacing(10.0);
|
|
||||||
|
|
||||||
vBox0.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
|
||||||
vBox0.setSpacing(10.0);
|
vBox0.setSpacing(10.0);
|
||||||
|
|
||||||
playerLabel.setText("Player:");
|
playerLabel.setText("Player:");
|
||||||
@@ -168,10 +161,10 @@ public class WarehouseGUI extends Player{
|
|||||||
|
|
||||||
playerOpium.setText("Opium:");
|
playerOpium.setText("Opium:");
|
||||||
|
|
||||||
vBox1.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
vBox1.setAlignment(Pos.CENTER_LEFT);
|
||||||
vBox1.setSpacing(10.0);
|
vBox1.setSpacing(10.0);
|
||||||
|
|
||||||
houseLabel.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
houseLabel.setAlignment(Pos.TOP_CENTER);
|
||||||
houseLabel.setText("Warehouse:");
|
houseLabel.setText("Warehouse:");
|
||||||
houseLabel.setFont(new Font(18.0));
|
houseLabel.setFont(new Font(18.0));
|
||||||
|
|
||||||
@@ -228,85 +221,46 @@ public class WarehouseGUI extends Player{
|
|||||||
taipanShopGUI.initializeShop(stage);
|
taipanShopGUI.initializeShop(stage);
|
||||||
stage.show();
|
stage.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
//Runs when the withdraw button is selected. and removes the amount of the selected good
|
//Runs when the withdraw button is selected. and removes the amount of the selected good
|
||||||
withdrawButton.setOnAction(event -> {
|
withdrawButton.setOnAction(event -> {
|
||||||
try {
|
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||||
int withdraw = Integer.parseInt(textField.getText());
|
if(Goods.getSelectedToggle() == generalRadio){
|
||||||
|
title.setText(warehouseLogic.withdraw(textField.getText(),1));
|
||||||
if(withdraw <= 0){
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
}
|
||||||
//Transfers general amount
|
else if(Goods.getSelectedToggle() == armsRadio){
|
||||||
else if(Goods.getSelectedToggle() == generalRadio && withdraw <= getwGeneral()){
|
title.setText(warehouseLogic.withdraw(textField.getText(),2));
|
||||||
setGeneralHeld(getPlayer().getGeneralHeld()+withdraw);
|
|
||||||
setwGeneral(getPlayer().getwGeneral()-withdraw);
|
|
||||||
}
|
}
|
||||||
//Transfers Arms amount
|
else if(Goods.getSelectedToggle() == silkRadio){
|
||||||
else if(Goods.getSelectedToggle() == armsRadio && withdraw <= getwArms()){
|
title.setText(warehouseLogic.withdraw(textField.getText(),3));
|
||||||
setArmsHeld(getPlayer().getArmsHeld()+withdraw);
|
|
||||||
setwArms(getPlayer().getwArms()-withdraw);
|
|
||||||
}
|
}
|
||||||
//Transfers Silk Amount
|
else if(Goods.getSelectedToggle() == opiumRadio){
|
||||||
else if(Goods.getSelectedToggle() == silkRadio && withdraw <= getwSilk()){
|
title.setText(warehouseLogic.withdraw(textField.getText(),4));
|
||||||
setSilkHeld(getPlayer().getSilkHeld()+withdraw);
|
|
||||||
setwSilk(getPlayer().getwSilk()-withdraw);
|
|
||||||
}
|
|
||||||
//Transfers Opium amount
|
|
||||||
else if(Goods.getSelectedToggle() == opiumRadio && withdraw <= getwOpium()) {
|
|
||||||
setOpiumHeld(getPlayer().getOpiumHeld() + withdraw);
|
|
||||||
setwOpium(getPlayer().getwOpium() - withdraw);
|
|
||||||
}
|
|
||||||
// Ensures a valid value is entered
|
|
||||||
else{
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
}
|
||||||
|
setPlayer(warehouseLogic.getPlayer());
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Button to add a user entered amount to the warehouse
|
//Button to add a user entered amount to the warehouse
|
||||||
depositButton.setOnAction(event -> {
|
depositButton.setOnAction(event -> {
|
||||||
try {
|
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||||
int deposit = Integer.parseInt(textField.getText());
|
if(Goods.getSelectedToggle() == generalRadio){
|
||||||
|
title.setText(warehouseLogic.deposit(textField.getText(),1));
|
||||||
if(deposit <= 0){
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
}
|
||||||
//Transfers general amount
|
else if(Goods.getSelectedToggle() == armsRadio){
|
||||||
else if(Goods.getSelectedToggle() == generalRadio && deposit <= getGeneralHeld()){
|
title.setText(warehouseLogic.deposit(textField.getText(),2));
|
||||||
setGeneralHeld(getPlayer().getGeneralHeld()-deposit);
|
|
||||||
setwGeneral(getPlayer().getwGeneral()+deposit);
|
|
||||||
}
|
}
|
||||||
//Transfers Arms amount
|
else if(Goods.getSelectedToggle() == silkRadio){
|
||||||
else if(Goods.getSelectedToggle() == armsRadio && deposit <= getArmsHeld()){
|
title.setText(warehouseLogic.deposit(textField.getText(),3));
|
||||||
setArmsHeld(getPlayer().getArmsHeld()-deposit);
|
|
||||||
setwArms(getPlayer().getwArms()+deposit);
|
|
||||||
}
|
}
|
||||||
//Transfers Silk amount
|
else if(Goods.getSelectedToggle() == opiumRadio){
|
||||||
else if(Goods.getSelectedToggle() == silkRadio && deposit <= getSilkHeld()){
|
title.setText(warehouseLogic.deposit(textField.getText(),4));
|
||||||
setSilkHeld(getPlayer().getSilkHeld()-deposit);
|
|
||||||
setwSilk(getPlayer().getwSilk()+deposit);
|
|
||||||
}
|
|
||||||
//Transfers Opium amount
|
|
||||||
else if(Goods.getSelectedToggle() == opiumRadio && deposit <= getOpiumHeld()){
|
|
||||||
setOpiumHeld(getPlayer().getOpiumHeld()-deposit);
|
|
||||||
setwOpium(getPlayer().getwOpium()+deposit);
|
|
||||||
}
|
|
||||||
//Checks if the correct value is entered
|
|
||||||
else{
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
}
|
||||||
|
setPlayer(warehouseLogic.getPlayer());
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
title.setText("Please enter a valid value");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Create the scene and box of the desired size
|
||||||
//Create the sceene and box of the desired size
|
|
||||||
Scene root = new Scene(borderPane, 600, 480);
|
Scene root = new Scene(borderPane, 600, 480);
|
||||||
root.getStylesheets().add("styleguide.css");
|
root.getStylesheets().add("styleguide.css");
|
||||||
|
|
||||||
@@ -316,6 +270,15 @@ public class WarehouseGUI extends Player{
|
|||||||
return stage;
|
return stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void settingBorderFormat(HBox hBox, VBox vBox) {
|
||||||
|
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);
|
||||||
|
vBox.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* As soon as the transfer is made the table of the amount of goods is updated using this method
|
* As soon as the transfer is made the table of the amount of goods is updated using this method
|
||||||
*/
|
*/
|
||||||
31
src/logic/BankLogic.java
Normal file
31
src/logic/BankLogic.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
public class BankLogic extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public BankLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Withdraws a set amount of money from the player's bank account and gives it to the player
|
||||||
|
* @param withdraw the amount of money which the player is withdrawing
|
||||||
|
*/
|
||||||
|
public void withdrawing(int withdraw) {
|
||||||
|
setMoney(withdraw + getMoney());
|
||||||
|
setBank(getBank() - withdraw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deposits a set amount of money from the player to the player's bank account
|
||||||
|
* @param deposit the amount of money which the player is depositing
|
||||||
|
*/
|
||||||
|
public void depositing(int deposit) {
|
||||||
|
setBank(deposit + getBank());
|
||||||
|
setMoney(getMoney() - deposit);
|
||||||
|
}
|
||||||
|
}
|
||||||
85
src/logic/FileSaving.java
Normal file
85
src/logic/FileSaving.java
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
/**
|
||||||
|
* 2019-03-10 (Edited on 2019-03-19)
|
||||||
|
* Authors: Harkamal Randhawa
|
||||||
|
* FileSaving Class allows the user to save the current status of the game and to continue from where they left off.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class FileSaving extends Player implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loads the file of type player which contains all the player instances
|
||||||
|
* @return player
|
||||||
|
*/
|
||||||
|
public Player loadFile() {
|
||||||
|
try {
|
||||||
|
//Load the previous save file
|
||||||
|
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
|
||||||
|
return getPlayer(in);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
try {
|
||||||
|
//Loads the player save in a alternate location if the original location isn't available
|
||||||
|
InputStream in = new FileInputStream(new File("saves/playerSave.txt"));
|
||||||
|
return getPlayer(in);
|
||||||
|
}
|
||||||
|
catch(Exception e2){
|
||||||
|
//Only it's impossible for the player to load a file
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only run inside this class, returns save files. Throws exceptions if it fails
|
||||||
|
* @param in The input stream from the previous save(If there is one)
|
||||||
|
* @return Returns the player object from the previous save file
|
||||||
|
* @throws IOException Only if the file cannot be read
|
||||||
|
* @throws ClassNotFoundException Only if there is no file available for the player to load
|
||||||
|
*/
|
||||||
|
private Player getPlayer(InputStream in) throws IOException, ClassNotFoundException {
|
||||||
|
ObjectInputStream inObject = new ObjectInputStream(in);
|
||||||
|
Player player = (Player) inObject.readObject();
|
||||||
|
in.close();
|
||||||
|
inObject.close();
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the file of type player which contains all the player instances
|
||||||
|
* @param player The player object being saved
|
||||||
|
*/
|
||||||
|
public boolean saveFile(Player player){
|
||||||
|
try{
|
||||||
|
//Saves the object to a file
|
||||||
|
FileOutputStream out = new FileOutputStream(new File("src/saves/playerSave.txt"));
|
||||||
|
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
||||||
|
outObject.writeObject(player);
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
outObject.close();
|
||||||
|
|
||||||
|
//returns true if program can save the file
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
try {
|
||||||
|
//If the player is running from the terminal it changes the files location, this catch statement fixes that
|
||||||
|
FileOutputStream out = new FileOutputStream(new File("saves/playerSave.txt"));
|
||||||
|
ObjectOutputStream outObject = new ObjectOutputStream(out);
|
||||||
|
outObject.writeObject(player);
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
outObject.close();
|
||||||
|
//returns true if the program can save the file
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception e2){
|
||||||
|
//returns false if it's impossible for the player to save the file
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
src/logic/GameEndLogic.java
Normal file
49
src/logic/GameEndLogic.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
public class GameEndLogic extends Player{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public GameEndLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the networth of the player by the end of the game.
|
||||||
|
* Calculation is based off the total guns and items bought throughout the game
|
||||||
|
* @return the total networth of the player
|
||||||
|
*/
|
||||||
|
public int getNetWorth() {
|
||||||
|
int netWorthInt;
|
||||||
|
netWorthInt = getMoney() + (getOpiumHeld() * 16000) + (getSilkHeld() * 160) + (getArmsHeld() * 160) + (getGeneralHeld() * 8);
|
||||||
|
netWorthInt += (getwOpium() * 16000) + (getwSilk() * 160) + (getwArms() * 160) + (getwGeneral() * 8);
|
||||||
|
netWorthInt -= getDebt();
|
||||||
|
return netWorthInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If health is below or equal to 0 then the game will either show the gameOver screen or the win screen
|
||||||
|
* @return the endGame message
|
||||||
|
*/
|
||||||
|
public String endGameText() {
|
||||||
|
if (getHP() <= 0) {
|
||||||
|
return "Game Over!";
|
||||||
|
} else {
|
||||||
|
return "Congratulations!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method that creates an array filled will all the user's stats
|
||||||
|
* @param netWorthInt the total net worth of the user
|
||||||
|
* @return Returns the firm name of the user, the guns they held and their total net worth
|
||||||
|
*/
|
||||||
|
public String[] endGameStats(int netWorthInt) {
|
||||||
|
return new String[]{"Firm Name: " + getName(), "Guns Held: " + getGuns(), "Net Worth: " + netWorthInt};
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/logic/LoanSharkLogic.java
Normal file
24
src/logic/LoanSharkLogic.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
public class LoanSharkLogic extends Player{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public LoanSharkLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to set and change loans for the Player
|
||||||
|
* @param debt the amount of money the loan is for
|
||||||
|
* @param money How much money is either taken or give to the Player
|
||||||
|
*/
|
||||||
|
public void changeLoan(int debt, int money) {
|
||||||
|
setDebt(debt);
|
||||||
|
setMoney(money);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
49
src/logic/RandomEventLogic.java
Normal file
49
src/logic/RandomEventLogic.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class RandomEventLogic extends Player{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public RandomEventLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that generates a random number and based on that number, a random event happens.
|
||||||
|
* @return randGenNum and itemPrice, randGen number is the number which dictates the event, the item price is how much it will cost
|
||||||
|
*/
|
||||||
|
public int[] randEvent() {
|
||||||
|
Random rand = new Random();
|
||||||
|
int itemPrice;
|
||||||
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
while(true){
|
||||||
|
//Buy Guns
|
||||||
|
if (randGenNum == 1) {
|
||||||
|
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Liu Yuen
|
||||||
|
if (randGenNum == 2) {
|
||||||
|
itemPrice = (int) ((getPlayer().getMoney() * 0.1) + 10);
|
||||||
|
setAttackingShips(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Ship Repair
|
||||||
|
if (randGenNum == 3 && getHP() < 100) {
|
||||||
|
itemPrice = (int) ((100 - getPlayer().getHP()) * 10 + 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Forces random event to be gun related if nothing else is avaliable
|
||||||
|
else {
|
||||||
|
randGenNum = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new int[]{randGenNum,itemPrice};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
103
src/logic/ShipWarfareLogic.java
Normal file
103
src/logic/ShipWarfareLogic.java
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package logic;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2019-03-10 (Edited on 2019-04-07)
|
||||||
|
* Author: Haris Muhammad
|
||||||
|
* ShipWarfareLogic class, logic for ships which the user can attack or run from
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public class ShipWarfareLogic extends Player {
|
||||||
|
|
||||||
|
private int numOfShips = 0;
|
||||||
|
private int startingShips = 0;
|
||||||
|
private int counter = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ShipWarfareLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter method that takes in an integer as an argument
|
||||||
|
*
|
||||||
|
* @param numOfShips the number of ships to be used in the peasant fleet attack
|
||||||
|
*/
|
||||||
|
public void setNumOfShips(int numOfShips) {
|
||||||
|
counter++;
|
||||||
|
this.numOfShips = numOfShips;
|
||||||
|
if (counter == 1) {
|
||||||
|
startingShips = numOfShips;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the number of ships attacking
|
||||||
|
*
|
||||||
|
* @return the number of ships attacking
|
||||||
|
*/
|
||||||
|
public int getNumOfShips() {
|
||||||
|
return numOfShips;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
||||||
|
Random randomValue = new Random();
|
||||||
|
int runSuccessChance = randomValue.nextInt(5) + 1;
|
||||||
|
if (runSuccessChance == 2) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 (super.getMoney() <= 100000) {
|
||||||
|
//Minimum one ship will attack, maximum 20
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(20) + 1;
|
||||||
|
} else if (super.getMoney() <= 200000) {
|
||||||
|
//Minimum 30 Ships will attack, maximum 70
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(40) + 31;
|
||||||
|
} else if (super.getMoney() <= 500000) {
|
||||||
|
//Minimum 50 ships will attack, maximum 140
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(90) + 51;
|
||||||
|
} else if (super.getMoney() >= 1000000) {
|
||||||
|
//Minimum 100 ships will attack, maximum 300 ships
|
||||||
|
numOfShipsAttacking = randomValue.nextInt(200) + 101;
|
||||||
|
}
|
||||||
|
|
||||||
|
return numOfShipsAttacking;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the loot for defeating a fleet
|
||||||
|
*
|
||||||
|
* @return the loot for defeating the fleet
|
||||||
|
*/
|
||||||
|
public int calculateLoot() {
|
||||||
|
Random randomValue = new Random();
|
||||||
|
int calculateLoot;
|
||||||
|
calculateLoot = (startingShips * 100) + randomValue.nextInt(startingShips) * 200;
|
||||||
|
return calculateLoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/logic/StartLogic.java
Normal file
45
src/logic/StartLogic.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
public class StartLogic extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public StartLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
this.setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used in the Start Class
|
||||||
|
* method that sets the player's money and debt to 400 and 5000 respectively.
|
||||||
|
* also sets the player's guns to 0.
|
||||||
|
*/
|
||||||
|
public void money_and_debt() {
|
||||||
|
setMoney(400);
|
||||||
|
setDebt(5000);
|
||||||
|
setGuns(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used in the Start Class
|
||||||
|
* method that sets the player's guns to 5.
|
||||||
|
*/
|
||||||
|
public void guns() {
|
||||||
|
setGuns(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used in the Start Class
|
||||||
|
* for testing purposes
|
||||||
|
* sets the player's money, bank, guns, hp, ad cargo space to max values.
|
||||||
|
*/
|
||||||
|
public void cheat() {
|
||||||
|
setMoney(1000000);
|
||||||
|
setBank(1000000);
|
||||||
|
setGuns(1000000);
|
||||||
|
setHP(1000000);
|
||||||
|
setCargoSpace(100000000);
|
||||||
|
}
|
||||||
|
}
|
||||||
116
src/logic/TaipanShopLogic.java
Normal file
116
src/logic/TaipanShopLogic.java
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TaipanShopLogic deals with the computations necessary for the shop such as randomizing prices.
|
||||||
|
* Author: Vikram Bawa
|
||||||
|
*/
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class TaipanShopLogic extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public TaipanShopLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used when the shop is accessed, randomizing the prices of all the items.
|
||||||
|
* @return Returns the string which will be said to the player when they open the shop
|
||||||
|
*/
|
||||||
|
public String updatePrices() {
|
||||||
|
String s = "\t" + getName() + ", the price of ";
|
||||||
|
String a = "";
|
||||||
|
double value = 80 * Math.random();
|
||||||
|
Random rand = new Random();
|
||||||
|
setOpiumPrice((rand.nextInt(201) + 60) * 100);
|
||||||
|
setSilkPrice((rand.nextInt(201) + 60) * 10);
|
||||||
|
setArmsPrice((rand.nextInt(21) + 6) * 10);
|
||||||
|
setGeneralPrice((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) {
|
||||||
|
setOpiumPrice(getOpiumPrice() / 5);
|
||||||
|
a = s + "Opium has dropped to " + getOpiumPrice() + "!!!\n";
|
||||||
|
} else {
|
||||||
|
setOpiumPrice(getOpiumPrice() * 5);
|
||||||
|
a = s + "Opium has risen to " + getOpiumPrice() + "!!!\n" ;
|
||||||
|
}
|
||||||
|
} else if (value < 4) {
|
||||||
|
if (value < 3) {
|
||||||
|
setSilkPrice(getSilkPrice() / 5);
|
||||||
|
a = s + "Silk has dropped to " + getSilkPrice() + "!!!\n";
|
||||||
|
} else {
|
||||||
|
setSilkPrice(getSilkPrice() * 5);
|
||||||
|
a = s + "Silk has risen to " + getSilkPrice() + "!!!\n";
|
||||||
|
}
|
||||||
|
} else if (value < 6) {
|
||||||
|
if (value < 3) {
|
||||||
|
setArmsPrice(getArmsPrice() / 5);
|
||||||
|
a = s + "Arms has dropped to " + getArmsPrice() + "!!!\n";
|
||||||
|
} else {
|
||||||
|
setArmsPrice(getArmsPrice() * 5);
|
||||||
|
a = s + "Arms has risen to " + getArmsPrice() + "!!!\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (value < 7) {
|
||||||
|
setGeneralPrice(1);
|
||||||
|
a = s + "General Cargo has dropped to 1!!!\n";
|
||||||
|
} else {
|
||||||
|
setGeneralPrice(getGeneralPrice() * 5);
|
||||||
|
a = s + "General Cargo has risen to " + getGeneralPrice() + "!!!\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
87
src/logic/TravelLogic.java
Normal file
87
src/logic/TravelLogic.java
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class TravelLogic extends Player {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public TravelLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
public void seaAtlas(int locationOfTravel) {
|
||||||
|
switch (locationOfTravel) {
|
||||||
|
case 1:
|
||||||
|
System.out.println("\nArriving at Hong Kong");
|
||||||
|
setLocation(1);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
System.out.println("\nArriving at Shanghai");
|
||||||
|
setLocation(2);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
System.out.println("\nArriving at Nagasaki");
|
||||||
|
setLocation(3);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
System.out.println("\nArriving at Saigon");
|
||||||
|
setLocation(4);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
System.out.println("\nArriving at Manila");
|
||||||
|
setLocation(5);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
System.out.println("\nArriving at Singapore");
|
||||||
|
setLocation(6);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
System.out.println("\nArriving at Batavia");
|
||||||
|
setLocation(7);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* @return returns the string which is to be said to the player
|
||||||
|
**/
|
||||||
|
public String disaster(int locationOfTravel) {
|
||||||
|
//Tells player that there is a storm approaching.
|
||||||
|
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) {
|
||||||
|
return "We got through the storm " + getName() + "!";
|
||||||
|
}else {
|
||||||
|
while (randGenNum == locationOfTravel) {
|
||||||
|
randGenNum = rand.nextInt(7) + 1;
|
||||||
|
if (randGenNum != locationOfTravel) {
|
||||||
|
seaAtlas(randGenNum);
|
||||||
|
return "We've been blown off course!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
104
src/logic/WarehouseLogic.java
Normal file
104
src/logic/WarehouseLogic.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package logic;
|
||||||
|
|
||||||
|
public class WarehouseLogic extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public WarehouseLogic(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that transfers your cargo from your ship to your warehouse.
|
||||||
|
* Has error handling to prevent incorrect inputs
|
||||||
|
* @return returns the string which is to be said to the player
|
||||||
|
*/
|
||||||
|
public String deposit(String str, int goodsNum) {
|
||||||
|
try {
|
||||||
|
int deposit = Integer.parseInt(str);
|
||||||
|
if(deposit <= 0){
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
//Transfers General amount
|
||||||
|
else if(goodsNum == 1 && deposit <= getGeneralHeld()){
|
||||||
|
setGeneralHeld(getPlayer().getGeneralHeld()-deposit);
|
||||||
|
setwGeneral(getPlayer().getwGeneral()+deposit);
|
||||||
|
return "Successful deposit";
|
||||||
|
}
|
||||||
|
//Transfers Arms amount
|
||||||
|
else if(goodsNum == 2 && deposit <= getArmsHeld()){
|
||||||
|
setArmsHeld(getPlayer().getArmsHeld()-deposit);
|
||||||
|
setwArms(getPlayer().getwArms()+deposit);
|
||||||
|
return "Successful deposit";
|
||||||
|
}
|
||||||
|
//Transfers Silk amount
|
||||||
|
else if(goodsNum == 3 && deposit <= getSilkHeld()){
|
||||||
|
setSilkHeld(getPlayer().getSilkHeld()-deposit);
|
||||||
|
setwSilk(getPlayer().getwSilk()+deposit);
|
||||||
|
return "Successful deposit";
|
||||||
|
}
|
||||||
|
//Transfers Opium amount
|
||||||
|
else if(goodsNum == 4 && deposit <= getOpiumHeld()){
|
||||||
|
setOpiumHeld(getPlayer().getOpiumHeld()-deposit);
|
||||||
|
setwOpium(getPlayer().getwOpium()+deposit);
|
||||||
|
return "Successful deposit";
|
||||||
|
}
|
||||||
|
//Checks if the correct value is entered
|
||||||
|
else{
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that transfers cargo from your warehouse onto your ship.
|
||||||
|
* Has error handling to prevent incorrect inputs
|
||||||
|
* @return returns the string which is to be said to the player
|
||||||
|
*/
|
||||||
|
public String withdraw(String str, int goodsNum) {
|
||||||
|
try {
|
||||||
|
int withdraw = Integer.parseInt(str);
|
||||||
|
if(withdraw <= 0){
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
//Transfers general amount
|
||||||
|
else if(goodsNum == 1 && withdraw <= getwGeneral()){
|
||||||
|
setGeneralHeld(getPlayer().getGeneralHeld()+withdraw);
|
||||||
|
setwGeneral(getPlayer().getwGeneral()-withdraw);
|
||||||
|
return "Successful withdraw";
|
||||||
|
}
|
||||||
|
//Transfers Arms amount
|
||||||
|
else if(goodsNum == 2 && withdraw <= getwArms()){
|
||||||
|
setArmsHeld(getPlayer().getArmsHeld()+withdraw);
|
||||||
|
setwArms(getPlayer().getwArms()-withdraw);
|
||||||
|
return "Successful withdraw";
|
||||||
|
}
|
||||||
|
//Transfers Silk Amount
|
||||||
|
else if(goodsNum == 3 && withdraw <= getwSilk()){
|
||||||
|
setSilkHeld(getPlayer().getSilkHeld()+withdraw);
|
||||||
|
setwSilk(getPlayer().getwSilk()-withdraw);
|
||||||
|
return "Successful withdraw";
|
||||||
|
}
|
||||||
|
//Transfers Opium amount
|
||||||
|
else if(goodsNum == 4 && withdraw <= getwOpium()) {
|
||||||
|
setOpiumHeld(getPlayer().getOpiumHeld() + withdraw);
|
||||||
|
setwOpium(getPlayer().getwOpium() - withdraw);
|
||||||
|
return "Successful withdraw";
|
||||||
|
}
|
||||||
|
// Ensures a valid value is entered
|
||||||
|
else{
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return "Please enter a valid value";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -1,6 +1,9 @@
|
|||||||
|
package tests;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import logic.Player;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@@ -21,7 +24,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getCargoSpace() {
|
public void getCargoSpace() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 60, player.getCargoSpace());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 60, player.getCargoSpace());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +34,7 @@ public class PlayerTest {
|
|||||||
public void setCargoSpace() {
|
public void setCargoSpace() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setCargoSpace(10);
|
player.setCargoSpace(10);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 10, player.getCargoSpace());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 10, player.getCargoSpace());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +43,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getAttackingShips() {
|
public void getAttackingShips() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", true, player.getAttackingShips());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", true, player.getAttackingShips());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +53,7 @@ public class PlayerTest {
|
|||||||
public void setAttackingShips() {
|
public void setAttackingShips() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setAttackingShips(false);
|
player.setAttackingShips(false);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", false, player.getAttackingShips());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", false, player.getAttackingShips());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,7 +62,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getRetire() {
|
public void getRetire() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", false, player.getRetire());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", false, player.getRetire());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +72,7 @@ public class PlayerTest {
|
|||||||
public void setRetire() {
|
public void setRetire() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setRetire(true);
|
player.setRetire(true);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", true, player.getRetire());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", true, player.getRetire());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +81,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getName() {
|
public void getName() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", "Taipan", player.getName());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", "Taipan", player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,7 +91,7 @@ public class PlayerTest {
|
|||||||
public void setName() {
|
public void setName() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setName("a");
|
player.setName("a");
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", "a", player.getName());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", "a", player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +100,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getHP() {
|
public void getHP() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 100, player.getHP());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 100, player.getHP());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,7 +110,7 @@ public class PlayerTest {
|
|||||||
public void setHP() {
|
public void setHP() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setHP(1);
|
player.setHP(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getHP());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getHP());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,7 +119,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getBank() {
|
public void getBank() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getBank());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getBank());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +129,7 @@ public class PlayerTest {
|
|||||||
public void setBank() {
|
public void setBank() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setBank(1);
|
player.setBank(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getBank());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getBank());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,7 +138,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getMoney() {
|
public void getMoney() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getMoney());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getMoney());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,7 +148,7 @@ public class PlayerTest {
|
|||||||
public void setMoney() {
|
public void setMoney() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setMoney(1);
|
player.setMoney(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getMoney());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getMoney());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,7 +157,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getOpiumHeld() {
|
public void getOpiumHeld() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getOpiumHeld());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getOpiumHeld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,7 +167,7 @@ public class PlayerTest {
|
|||||||
public void setOpiumHeld() {
|
public void setOpiumHeld() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setOpiumHeld(1);
|
player.setOpiumHeld(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getOpiumHeld());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getOpiumHeld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,7 +176,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getSilkHeld() {
|
public void getSilkHeld() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getSilkHeld());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getSilkHeld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,7 +186,7 @@ public class PlayerTest {
|
|||||||
public void setSilkHeld() {
|
public void setSilkHeld() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setSilkHeld(1);
|
player.setSilkHeld(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getSilkHeld());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getSilkHeld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,7 +195,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getGeneralHeld() {
|
public void getGeneralHeld() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getGeneralHeld());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getGeneralHeld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,7 +205,7 @@ public class PlayerTest {
|
|||||||
public void setGeneralHeld() {
|
public void setGeneralHeld() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setGeneralHeld(1);
|
player.setGeneralHeld(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getGeneralHeld());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getGeneralHeld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,7 +214,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getArmsHeld() {
|
public void getArmsHeld() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getArmsHeld());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getArmsHeld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -221,7 +224,7 @@ public class PlayerTest {
|
|||||||
public void setArmsHeld() {
|
public void setArmsHeld() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setArmsHeld(1);
|
player.setArmsHeld(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getArmsHeld());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getArmsHeld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -230,7 +233,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getLocation() {
|
public void getLocation() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getLocation());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -240,7 +243,7 @@ public class PlayerTest {
|
|||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setLocation(2);
|
player.setLocation(2);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 2, player.getLocation());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 2, player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -249,7 +252,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getGuns() {
|
public void getGuns() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 5, player.getGuns());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 5, player.getGuns());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -259,7 +262,7 @@ public class PlayerTest {
|
|||||||
public void setGuns() {
|
public void setGuns() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setGuns(1);
|
player.setGuns(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getGuns());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getGuns());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -268,7 +271,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDebt() {
|
public void getDebt() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getDebt());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getDebt());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -278,7 +281,7 @@ public class PlayerTest {
|
|||||||
public void setDebt() {
|
public void setDebt() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setDebt(1);
|
player.setDebt(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getDebt());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getDebt());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -287,7 +290,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getwOpium() {
|
public void getwOpium() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getwOpium());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getwOpium());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -297,7 +300,7 @@ public class PlayerTest {
|
|||||||
public void setwOpium() {
|
public void setwOpium() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setwOpium(1);
|
player.setwOpium(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getwOpium());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getwOpium());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -306,7 +309,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getwSilk() {
|
public void getwSilk() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getwSilk());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getwSilk());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,7 +319,7 @@ public class PlayerTest {
|
|||||||
public void setwSilk() {
|
public void setwSilk() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setwSilk(1);
|
player.setwSilk(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getwSilk());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getwSilk());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -325,7 +328,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getwGeneral() {
|
public void getwGeneral() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getwGeneral());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getwGeneral());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -335,7 +338,7 @@ public class PlayerTest {
|
|||||||
public void setwGeneral() {
|
public void setwGeneral() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setwGeneral(1);
|
player.setwGeneral(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getwGeneral());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getwGeneral());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -344,7 +347,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getwArms() {
|
public void getwArms() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getwArms());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getwArms());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -354,7 +357,7 @@ public class PlayerTest {
|
|||||||
public void setwArms() {
|
public void setwArms() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setwArms(1);
|
player.setwArms(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getwArms());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getwArms());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -363,7 +366,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getOpiumPrice() {
|
public void getOpiumPrice() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 16000, player.getOpiumPrice());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 16000, player.getOpiumPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -373,7 +376,7 @@ public class PlayerTest {
|
|||||||
public void setOpiumPrice() {
|
public void setOpiumPrice() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setOpiumPrice(1);
|
player.setOpiumPrice(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getOpiumPrice());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getOpiumPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -382,7 +385,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getSilkPrice() {
|
public void getSilkPrice() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1600, player.getSilkPrice());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1600, player.getSilkPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -392,7 +395,7 @@ public class PlayerTest {
|
|||||||
public void setSilkPrice() {
|
public void setSilkPrice() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setSilkPrice(1);
|
player.setSilkPrice(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getSilkPrice());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getSilkPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -401,7 +404,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getArmsPrice() {
|
public void getArmsPrice() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 160, player.getArmsPrice());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 160, player.getArmsPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -411,7 +414,7 @@ public class PlayerTest {
|
|||||||
public void setArmsPrice() {
|
public void setArmsPrice() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setArmsPrice(1);
|
player.setArmsPrice(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getArmsPrice());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getArmsPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -420,7 +423,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getGeneralPrice() {
|
public void getGeneralPrice() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 8, player.getGeneralPrice());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 8, player.getGeneralPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -430,7 +433,7 @@ public class PlayerTest {
|
|||||||
public void setGeneralPrice() {
|
public void setGeneralPrice() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setGeneralPrice(1);
|
player.setGeneralPrice(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getGeneralPrice());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getGeneralPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -439,7 +442,7 @@ public class PlayerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getIsPriceChanged() {
|
public void getIsPriceChanged() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getIsPriceChanged());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 0, player.getIsPriceChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -449,6 +452,6 @@ public class PlayerTest {
|
|||||||
public void setIsPriceChanged() {
|
public void setIsPriceChanged() {
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.setIsPriceChanged(1);
|
player.setIsPriceChanged(1);
|
||||||
assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getIsPriceChanged());
|
Assert.assertEquals("The instance variable for the object does not line up with the rest of the class", 1, player.getIsPriceChanged());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
118
src/text/BankText.java
Normal file
118
src/text/BankText.java
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import logic.BankLogic;
|
||||||
|
import logic.Player;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class BankText extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public BankText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to withdraw or deposit money into the bank account
|
||||||
|
* by prompting the user if they would like to withdraw or deposit. Followed
|
||||||
|
* by prompting them to enter an amount to transfer. This method also uses the
|
||||||
|
* player class to see if the transfer can be made,and if it can it changes the
|
||||||
|
* values accordingly
|
||||||
|
*/
|
||||||
|
public void bank(){
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
boolean notDone = true;
|
||||||
|
int check = 0;
|
||||||
|
while(notDone){
|
||||||
|
//Prompt the user if they want to withdraw or deposit
|
||||||
|
System.out.println("Would you like to Withdraw or Deposit?");
|
||||||
|
String response = input.nextLine();
|
||||||
|
//If user chose withdraw then subtract the amount from bank account and add it to cash
|
||||||
|
if(response.equalsIgnoreCase("W")){
|
||||||
|
check = withdraw(input, check);
|
||||||
|
}
|
||||||
|
//If the user chooses to deposit the continue to this code
|
||||||
|
else if(response.equalsIgnoreCase("D")){
|
||||||
|
check = deposit(input, check);
|
||||||
|
}
|
||||||
|
if(check == 1){
|
||||||
|
notDone = notContinue(input, notDone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks the user if they want to continue staying in Bank
|
||||||
|
* @param input The Scanner object which is used for asking user questions
|
||||||
|
* @param notDone Boolean statement which if is false stops the loop in the Bank method
|
||||||
|
* @return a boolean value which can turn off the original while loop this method is inside
|
||||||
|
*/
|
||||||
|
public boolean notContinue(Scanner input, boolean notDone) {
|
||||||
|
String response;
|
||||||
|
boolean notDone3 = true;
|
||||||
|
// Asks user if they would like to continue in bank or not
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return notDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks the user how much they want to deposit
|
||||||
|
* @param input The Scanner object which is used for asking user questions
|
||||||
|
* @param check an integer value which changes depending on the stages of the bank class
|
||||||
|
* @return a boolean value which can turn off the original while loop this method is inside
|
||||||
|
*/
|
||||||
|
public int deposit(Scanner input, int check) {
|
||||||
|
boolean notDone2 = true;
|
||||||
|
while(notDone2){
|
||||||
|
//Prompt the user for the amount they would like to deposit and ensure suffiecent funds
|
||||||
|
System.out.println("How much do you wish to Deposit?");
|
||||||
|
int deposit = input.nextInt();
|
||||||
|
if(deposit <= getMoney()){
|
||||||
|
BankLogic bankLogic = new BankLogic(getPlayer());
|
||||||
|
bankLogic.depositing(deposit);
|
||||||
|
setPlayer(bankLogic.getPlayer());
|
||||||
|
notDone2 = false;
|
||||||
|
check = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks the user how much they want to withdrawe
|
||||||
|
* @param input The Scanner object which is used for asking user questions
|
||||||
|
* @param check an integer value which changes depending on the stages of the bank class
|
||||||
|
* @return a boolean value which can turn off the original while loop this method is inside
|
||||||
|
*/
|
||||||
|
public int withdraw(Scanner input, int check) {
|
||||||
|
boolean notDone2 = true;
|
||||||
|
while(notDone2){
|
||||||
|
System.out.println("How much do you wish to Withdraw?");
|
||||||
|
int withdraw = input.nextInt();
|
||||||
|
//Prompt the user for the amount and check if the bank has sufficient funds
|
||||||
|
if(withdraw <= getBank()){
|
||||||
|
BankLogic bankLogic = new BankLogic(getPlayer());
|
||||||
|
bankLogic.withdrawing(withdraw);
|
||||||
|
setPlayer(bankLogic.getPlayer());
|
||||||
|
notDone2 = false;
|
||||||
|
check = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
34
src/text/GameEndText.java
Normal file
34
src/text/GameEndText.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import logic.GameEndLogic;
|
||||||
|
import logic.Player;
|
||||||
|
|
||||||
|
public class GameEndText extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public GameEndText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* At the end of the game, the end game stats appear the Firm's name, the number of guns held by the player and the networth of the player
|
||||||
|
*/
|
||||||
|
public void gameEnd(){
|
||||||
|
//Calculating the netWorth of the Player
|
||||||
|
GameEndLogic gameEndLogic = new GameEndLogic(getPlayer());
|
||||||
|
int netWorthInt = gameEndLogic.getNetWorth();
|
||||||
|
|
||||||
|
String[] strings = gameEndLogic.endGameStats(netWorthInt);
|
||||||
|
//Updating the endgame stats of the player
|
||||||
|
System.out.println(strings[0]);
|
||||||
|
System.out.println(strings[1]);
|
||||||
|
System.out.println(strings[2]);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
86
src/text/LoanSharkText.java
Normal file
86
src/text/LoanSharkText.java
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import logic.LoanSharkLogic;
|
||||||
|
import logic.Player;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class LoanSharkText extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public LoanSharkText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Either give the player a loan or it allows the player to pay a debt
|
||||||
|
*/
|
||||||
|
public void loanMoney() {
|
||||||
|
System.out.println("Debt: " + getDebt());
|
||||||
|
System.out.println("Cash: " + getMoney());
|
||||||
|
System.out.println("Would you like you get a (l)oan or (p)ay a debt?");
|
||||||
|
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
String response = keyboard.nextLine();
|
||||||
|
//Pay off loan
|
||||||
|
if (response.equalsIgnoreCase("p")) {
|
||||||
|
try {
|
||||||
|
System.out.println("How much of your debt would you like to pay?");
|
||||||
|
int returnAsk = Integer.parseInt(keyboard.nextLine());
|
||||||
|
//If the player enters a invalid number
|
||||||
|
if (returnAsk > getDebt()) {
|
||||||
|
System.out.println("You do not need to return that much.");
|
||||||
|
}
|
||||||
|
//If the player enters a valid number
|
||||||
|
else if (returnAsk <= getDebt() && returnAsk >= 0 && getMoney() >= returnAsk) {
|
||||||
|
LoanSharkLogic loanSharkLogic = new LoanSharkLogic(getPlayer());
|
||||||
|
loanSharkLogic.changeLoan(getDebt() - returnAsk, getMoney() - returnAsk);
|
||||||
|
setPlayer(loanSharkLogic.getPlayer());
|
||||||
|
}
|
||||||
|
//If the player enters a invalid number
|
||||||
|
else if (getMoney() < returnAsk) {
|
||||||
|
System.out.println("Look " + getName() + ", you are being cheap!");
|
||||||
|
}
|
||||||
|
//If the player enters a negative number
|
||||||
|
else {
|
||||||
|
System.out.println("Sorry, you can not return a negative amount!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Only runs if the user gives an invalid input
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("Please enter a valid value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Ask for Loan
|
||||||
|
if (response.equalsIgnoreCase("l")) {
|
||||||
|
try {
|
||||||
|
System.out.println("How big of a loan would you like?");
|
||||||
|
int loanAsk = Integer.parseInt(keyboard.nextLine());
|
||||||
|
//If the player enters a valid number
|
||||||
|
if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) {
|
||||||
|
LoanSharkLogic loanSharkLogic = new LoanSharkLogic(getPlayer());
|
||||||
|
loanSharkLogic.changeLoan(getDebt() + loanAsk, getMoney() + loanAsk);
|
||||||
|
setPlayer(loanSharkLogic.getPlayer());
|
||||||
|
System.out.println("Cash: " + getMoney());
|
||||||
|
}
|
||||||
|
//If the player enters a negative number
|
||||||
|
else if (loanAsk < 0) {
|
||||||
|
System.out.println("Sorry you cannot enter negative numbers");
|
||||||
|
}
|
||||||
|
//If the player enters a invalid number
|
||||||
|
else {
|
||||||
|
System.out.println("Sorry you cannot get the loan requested");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Only runs if the user gives an invalid input
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("Please enter a valid value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/text/MainText.java
Normal file
19
src/text/MainText.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import logic.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
public class MainText extends Player {
|
||||||
|
public MainText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
StartText startText = new StartText(new Player());
|
||||||
|
startText.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
104
src/text/RandomEventText.java
Normal file
104
src/text/RandomEventText.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import gui.TaipanShopGUI;
|
||||||
|
import logic.Player;
|
||||||
|
import logic.RandomEventLogic;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class RandomEventText extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public RandomEventText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Picks a random number and based off that number the player is put into a random event
|
||||||
|
* The random event can be anything from ship repair to paying bribes to the enemy fleet
|
||||||
|
*/
|
||||||
|
public void randomEvent(){
|
||||||
|
/*Pick a random number dictating the events that could happen.
|
||||||
|
* 1: New gun for player
|
||||||
|
* 2: Paying Liu Yuen
|
||||||
|
* 3: Repairing the Ship
|
||||||
|
*/
|
||||||
|
RandomEventLogic randomEventLogic = new RandomEventLogic(getPlayer());
|
||||||
|
int[] randEvent = randomEventLogic.randEvent();
|
||||||
|
int eventNumber = randEvent[0];
|
||||||
|
int itemPrice = randEvent[1];
|
||||||
|
|
||||||
|
if(eventNumber == 1){
|
||||||
|
System.out.println("\nA vendor is selling a gun for $" + itemPrice + " for a gun?");
|
||||||
|
}
|
||||||
|
if(eventNumber == 2){
|
||||||
|
System.out.println("\nLiu Yuen asks $" + itemPrice + " in donation to the temple of Tin Hau, the Sea Goddess");
|
||||||
|
}
|
||||||
|
if(eventNumber == 3){
|
||||||
|
System.out.println("\nMc Henry from the Hong Kong shipyard has arrived,\nwould be willing to repair your ship for $" + itemPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Only runs if the player doesn't have enough space and is given a gun
|
||||||
|
if((eventNumber == 1 && getCargoSpace() < 10)){
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
//Only runs if the player has 100 or greater HP and they got the ship repair man
|
||||||
|
if((eventNumber == 3 && getPlayer().getHP() >= 100)){
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Runs for as long as the player doesn't decide if they want to pay
|
||||||
|
while(true){
|
||||||
|
System.out.println("Would you like to pay? (Y)es or (N)o");
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
String input = keyboard.next();
|
||||||
|
if (input.equalsIgnoreCase("Y") && getPlayer().getMoney() > itemPrice) {
|
||||||
|
//Buy Guns
|
||||||
|
if (eventNumber == 1 && (getCargoSpace() >= 10)) {
|
||||||
|
setGuns(getPlayer().getGuns() + 1);
|
||||||
|
setMoney(getPlayer().getMoney() - itemPrice);
|
||||||
|
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Liu Yuen
|
||||||
|
if (eventNumber == 2) {
|
||||||
|
setAttackingShips(false);
|
||||||
|
setMoney(getPlayer().getMoney() - itemPrice);
|
||||||
|
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ship Repair
|
||||||
|
if (eventNumber == 3 && getPlayer().getHP() != 100) {
|
||||||
|
setHP(100);
|
||||||
|
setMoney(getPlayer().getMoney() - itemPrice);
|
||||||
|
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Sorry you don't have enough money");
|
||||||
|
}
|
||||||
|
//If the player decides to leave then it will send them back to TaipanShop
|
||||||
|
if(input.equalsIgnoreCase("N")){
|
||||||
|
System.out.println("Aye aye Taipan, we'll send them off!\n");
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
280
src/text/ShipWarfareText.java
Normal file
280
src/text/ShipWarfareText.java
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import logic.Player;
|
||||||
|
import logic.ShipWarfareLogic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2019-04-07
|
||||||
|
* Author: Haris Muhammad
|
||||||
|
* ShipWarfareText class, Based on logic class for ShipWarfare, text-based version which allwos for ship warfare
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public class ShipWarfareText extends Player {
|
||||||
|
|
||||||
|
ShipWarfareLogic logic = new ShipWarfareLogic(getPlayer());
|
||||||
|
|
||||||
|
private boolean userAttacks = true;
|
||||||
|
private int howMuchRun = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public ShipWarfareText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
|
||||||
|
*
|
||||||
|
* @throws Exception in case of errors due to the delay
|
||||||
|
*/
|
||||||
|
public void peasantFleetAttack() throws Exception {
|
||||||
|
Scanner userResponse = new Scanner(System.in);
|
||||||
|
logic.setNumOfShips(logic.numOfShips());
|
||||||
|
|
||||||
|
System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", getMoney(), logic.getNumOfShips(), getHP());
|
||||||
|
|
||||||
|
fightOrRunMessage();
|
||||||
|
while (true) {
|
||||||
|
String response = userResponse.nextLine();
|
||||||
|
if (response.equalsIgnoreCase("f")) {
|
||||||
|
userAttacks = true;
|
||||||
|
System.out.println("Ohh, fight ehh?");
|
||||||
|
delayForSeconds(1);
|
||||||
|
boolean winOrLose = destroyPeasantShipsOrEscape();
|
||||||
|
if (winOrLose == true) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else if (response.equalsIgnoreCase("r")) {
|
||||||
|
userAttacks = false;
|
||||||
|
boolean runSuccess = logic.runFromShips();
|
||||||
|
if (runSuccess == false) {
|
||||||
|
System.out.println("Couldn't run away!");
|
||||||
|
if (destroyPeasantShipsOrEscape())
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
System.out.println("Phew! Got away safely");
|
||||||
|
delayForSeconds(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid response, please try again");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks user if they would like to fight or run against ships
|
||||||
|
*/
|
||||||
|
public void fightOrRunMessage() {
|
||||||
|
System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)\n", getGuns());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delays for a specific amount of seconds, takes an integer as an argument
|
||||||
|
*
|
||||||
|
* @param num the seconds to delay
|
||||||
|
* @throws Exception in case of errors due to the delay
|
||||||
|
*/
|
||||||
|
public void delayForSeconds(int num) throws Exception {
|
||||||
|
TimeUnit.SECONDS.sleep(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ships either land a hit or do not
|
||||||
|
*
|
||||||
|
* @param random random object is used
|
||||||
|
* @param exitValue exit in order to know if user wins, loses, or flees
|
||||||
|
* @return exitValue
|
||||||
|
* @throws Exception in case error is caused due to the delay
|
||||||
|
*/
|
||||||
|
public int attackOrNot(Random random, int exitValue) throws Exception {
|
||||||
|
if (userAttacks == true) {
|
||||||
|
int hitOrMiss = random.nextInt(2) + 1;
|
||||||
|
if (hitOrMiss == 2) {
|
||||||
|
logic.setNumOfShips(logic.getNumOfShips() - 1);
|
||||||
|
if (logic.getNumOfShips() <= 0) {
|
||||||
|
return exitValue = 1;
|
||||||
|
}
|
||||||
|
System.out.println("Got eem");
|
||||||
|
delayForSeconds(1);
|
||||||
|
} else {
|
||||||
|
System.out.printf("ARRG! We missed %s\n", getName());
|
||||||
|
delayForSeconds(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
exitValue = 0;
|
||||||
|
return exitValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ships either run away or we escape
|
||||||
|
*/
|
||||||
|
public void shipsRunOrWeEscape() {
|
||||||
|
if (howMuchRun != 0 && howMuchRun < logic.getNumOfShips()) {
|
||||||
|
logic.setNumOfShips(logic.getNumOfShips() - howMuchRun);
|
||||||
|
if (userAttacks == true) {
|
||||||
|
System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, getName());
|
||||||
|
} else {
|
||||||
|
System.out.printf("Escaped %d of them!\n", howMuchRun);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user attempts to flee
|
||||||
|
*
|
||||||
|
* @param userInput takes the user input
|
||||||
|
* @param exitValue to determine if the ship fled successfully or not
|
||||||
|
* @return value tod etermine if ship ran successfully
|
||||||
|
* @throws Exception in case an error occurs due to the delay
|
||||||
|
*/
|
||||||
|
public int tryToRun(Scanner userInput, int exitValue) throws Exception {
|
||||||
|
if (getHP() > 0) {
|
||||||
|
String userResponse = displayQuery(userInput);
|
||||||
|
if (userResponse.equalsIgnoreCase("r")) {
|
||||||
|
userAttacks = false;
|
||||||
|
if (logic.runFromShips() == false) {
|
||||||
|
System.out.println("Couldn't run away");
|
||||||
|
} else {
|
||||||
|
exitValue = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
GameEndText gameEndText = new GameEndText(getPlayer());
|
||||||
|
gameEndText.gameEnd();
|
||||||
|
setPlayer(gameEndText.getPlayer());
|
||||||
|
exitValue = 2;
|
||||||
|
}
|
||||||
|
return exitValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() 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) {
|
||||||
|
if (getGuns() > 0) {
|
||||||
|
for (int j = 0; j < getGuns(); j++) {
|
||||||
|
attackOrNot(randomValue, exitValue);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (exitValue == 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
System.out.printf("%s! We don't have any GUNS!!!!\n", getName());
|
||||||
|
delayForSeconds(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (logic.getNumOfShips() <= 0) {
|
||||||
|
exitValue = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (getGuns() > 0) {
|
||||||
|
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
||||||
|
if (chanceOfEnemyRun == 2) {
|
||||||
|
howMuchRun = randomValue.nextInt(15) + 1;
|
||||||
|
shipsRunOrWeEscape();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.printf("%d ships remaining\n", logic.getNumOfShips());
|
||||||
|
delayForSeconds(1);
|
||||||
|
System.out.println("Oh no, they are taking the offensive!");
|
||||||
|
delayForSeconds(1);
|
||||||
|
//Computer volley
|
||||||
|
int takeGunChance = randomValue.nextInt(4) + 1;
|
||||||
|
if (takeGunChance == 1 && getGuns() > 0) {
|
||||||
|
setGuns(getGuns() - 1);
|
||||||
|
System.out.println("Dang it! They destroyed one of our guns");
|
||||||
|
} else {
|
||||||
|
setHP(getHP() - (1 + randomValue.nextInt(10)));
|
||||||
|
}
|
||||||
|
exitValue = tryToRun(userInput, exitValue);
|
||||||
|
if (exitValue == 1 || exitValue == 2) {
|
||||||
|
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", getHP());
|
||||||
|
delayForSeconds(1);
|
||||||
|
calculateLoot = logic.calculateLoot();
|
||||||
|
setMoney(calculateLoot+ getPlayer().getMoney());
|
||||||
|
System.out.printf("We got $%,d!", calculateLoot);
|
||||||
|
delayForSeconds(2);
|
||||||
|
return true;
|
||||||
|
} else if (exitValue == 2) {
|
||||||
|
gameOver();
|
||||||
|
return true;
|
||||||
|
} else if (exitValue == 3) {
|
||||||
|
System.out.printf("We made it out at %d%% ship status!\n", getHP());
|
||||||
|
delayForSeconds(2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask the user to input either "f" or "r"
|
||||||
|
*
|
||||||
|
* @param userInput scanner object which is used to ask for user input
|
||||||
|
* @return user input which is the users response
|
||||||
|
* @throws Exception in case the delay afects this piece of code
|
||||||
|
*/
|
||||||
|
public String displayQuery(Scanner userInput) throws Exception {
|
||||||
|
System.out.printf("EEK, our current ship status is %d%% \n", getHP());
|
||||||
|
delayForSeconds(1);
|
||||||
|
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", getGuns());
|
||||||
|
|
||||||
|
String response = userInput.nextLine();
|
||||||
|
while (!(response.equalsIgnoreCase("f") || response.equalsIgnoreCase("r"))) {
|
||||||
|
System.out.println("Invalid response, try again");
|
||||||
|
response = userInput.nextLine();
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
90
src/text/StartText.java
Normal file
90
src/text/StartText.java
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import gui.TaipanShopGUI;
|
||||||
|
import logic.FileSaving;
|
||||||
|
import logic.Player;
|
||||||
|
import logic.StartLogic;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class StartText extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public StartText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the game by asking for your name and if you would like to start with either: 1) money and a debt or
|
||||||
|
* 2) guns and no cash/debt.
|
||||||
|
*/
|
||||||
|
public void start() {
|
||||||
|
try{
|
||||||
|
Scanner userInput = new Scanner(System.in);
|
||||||
|
|
||||||
|
//See if the player wants to load up a previous save
|
||||||
|
System.out.println("Taipan, do you want to...\n\t1) load a save file?\n\t\t\t>> or <<\n\t2) make a new save file?");
|
||||||
|
while (true) {
|
||||||
|
int input = userInput.nextInt();
|
||||||
|
//Will attempt to load the save if it's not empty
|
||||||
|
if (input == 1) {
|
||||||
|
FileSaving saving = new FileSaving();
|
||||||
|
if (saving.loadFile() != null) {
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(saving.loadFile());
|
||||||
|
taipanShopText.shop();
|
||||||
|
} else {
|
||||||
|
System.out.println("There are no previous saves!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Just makes a new save
|
||||||
|
else if (input == 2) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid input, please try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Asks the player about their firm name and what kind of start they want
|
||||||
|
System.out.println("Taipan, \nWhat will you name your firm:");
|
||||||
|
setName(userInput.nextLine());
|
||||||
|
setName(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 ");
|
||||||
|
while (true) {
|
||||||
|
int input = userInput.nextInt();
|
||||||
|
StartLogic startLogic = new StartLogic(getPlayer());
|
||||||
|
//If the player wants the money and debt starting
|
||||||
|
if (input == 1) {
|
||||||
|
startLogic.money_and_debt();
|
||||||
|
setPlayer(startLogic.getPlayer());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//If the player wants the gun start
|
||||||
|
else if (input == 2) {
|
||||||
|
startLogic.guns();
|
||||||
|
setPlayer(startLogic.getPlayer());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Invalid input, please try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// purely for testing purposes.
|
||||||
|
StartLogic startLogic = new StartLogic(getPlayer());
|
||||||
|
if (getName().equalsIgnoreCase("Vikram")) {
|
||||||
|
startLogic.cheat();
|
||||||
|
setPlayer(startLogic.getPlayer());
|
||||||
|
}
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(startLogic.getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
StartText startText = new StartText(getPlayer());
|
||||||
|
startText.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
322
src/text/TaipanShopText.java
Normal file
322
src/text/TaipanShopText.java
Normal file
@@ -0,0 +1,322 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import javafx.scene.layout.FlowPane;
|
||||||
|
import logic.FileSaving;
|
||||||
|
import logic.Player;
|
||||||
|
import logic.TaipanShopLogic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TaipanShopText deals with the text based version of the shop.
|
||||||
|
*
|
||||||
|
* Author: Vikram Bawa
|
||||||
|
*/
|
||||||
|
public class TaipanShopText extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public TaipanShopText(Player player){
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is evoked if the user is eligible to win, and chooses to end the game (by winning).
|
||||||
|
*/
|
||||||
|
public void retire(){
|
||||||
|
setRetire(true);
|
||||||
|
System.out.println("You win!");
|
||||||
|
GameEndText gameEndText = new GameEndText(getPlayer());
|
||||||
|
gameEndText.gameEnd();
|
||||||
|
setPlayer(gameEndText.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method is evoked if the user has decided to travel elsewhere.
|
||||||
|
*/
|
||||||
|
public void travel(){
|
||||||
|
setIsPriceChanged(1);
|
||||||
|
TravelText travel = new TravelText(getPlayer());
|
||||||
|
travel.travelTo();
|
||||||
|
setPlayer(travel.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method is evoked if the user wants to use the warehouse to store items or take items out.
|
||||||
|
*/
|
||||||
|
public void warehouse(){
|
||||||
|
WarehouseText warehouse = new WarehouseText(getPlayer());
|
||||||
|
warehouse.changeWarehouse();
|
||||||
|
setPlayer(warehouse.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method is evoked if the user wants to use the bank to deposit or withdraw money.
|
||||||
|
*/
|
||||||
|
public void bank(){
|
||||||
|
BankText bank = new BankText(getPlayer());
|
||||||
|
bank.bank();
|
||||||
|
setPlayer(bank.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method is evoked if the user wants to use get a loan or pay a loan off.
|
||||||
|
*/
|
||||||
|
public void loan(){
|
||||||
|
LoanSharkText loan = new LoanSharkText(getPlayer());
|
||||||
|
loan.loanMoney();
|
||||||
|
setPlayer(loan.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this method prints the shop UI and the player's inventory and status.
|
||||||
|
*/
|
||||||
|
public void printShop(){
|
||||||
|
int currentCargo = getOpiumHeld()+getGuns()*10+getSilkHeld()+getArmsHeld()+getGeneralHeld();
|
||||||
|
if(getCargoSpace() - currentCargo < 0){
|
||||||
|
System.out.println("Hold: Overloaded" + " Guns: " + getGuns() + " HP: " + getHP() +"%");
|
||||||
|
}else{
|
||||||
|
System.out.println("Hold: " + (getCargoSpace()-currentCargo) + " Guns: " + getGuns() + " HP: " + getHP() +"%");
|
||||||
|
}
|
||||||
|
System.out.println("-------------------------------------------------------------");
|
||||||
|
System.out.println(" Opium: " + getOpiumHeld() + " Silk: " + getSilkHeld());
|
||||||
|
System.out.println(" Arms: " + getArmsHeld() + " General: " + getGeneralHeld());
|
||||||
|
System.out.println("-------------------------------------------------------------");
|
||||||
|
System.out.println("Cash: " + getMoney() + " Bank: " + getBank()+ " Debt: " + getDebt()+"\n");
|
||||||
|
System.out.println(getName() + ", present prices per unit here are:");
|
||||||
|
System.out.println(" Opium: " + getOpiumPrice() + " Silk: " + getSilkPrice());
|
||||||
|
System.out.println(" Arms: " + getArmsPrice() + " General: " + getGeneralPrice());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is the shop method. Activates the shopping screen.
|
||||||
|
*/
|
||||||
|
public void shop(){
|
||||||
|
|
||||||
|
//Saves the game when loading into the shop
|
||||||
|
FileSaving saving = new FileSaving();
|
||||||
|
saving.saveFile(getPlayer());
|
||||||
|
FlowPane flowPane = new FlowPane();
|
||||||
|
|
||||||
|
TaipanShopLogic logic = new TaipanShopLogic(getPlayer());
|
||||||
|
System.out.println(logic.updatePrices());
|
||||||
|
setPlayer(logic.getPlayer());
|
||||||
|
|
||||||
|
boolean notDone = true;
|
||||||
|
int caseNum = 1;
|
||||||
|
String optionText = "";
|
||||||
|
|
||||||
|
// first case is triggered if the user is at location one, and has less than $1 million net worth
|
||||||
|
if (getLocation() == 1 && getBank()+getMoney()-getDebt() < 1000000) {
|
||||||
|
caseNum = 1;
|
||||||
|
optionText = " (V)isit Bank, (T)ransfer Cargo, (G)et Loans,";
|
||||||
|
} // the second case is triggered if the user is at a location other than location one.
|
||||||
|
else if(getLocation() != 1) {
|
||||||
|
caseNum = 2;
|
||||||
|
optionText = "";
|
||||||
|
} // the last case is triggered when the other conditions are not met; it is triggered when the user has a net
|
||||||
|
// worth that is greater than or equal to $1 million and is at location one.
|
||||||
|
else{
|
||||||
|
caseNum = 3;
|
||||||
|
optionText = " (V)isit Bank, (T)ransfer Cargo, (G)et Loans, (R)etire,";
|
||||||
|
}
|
||||||
|
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
try {
|
||||||
|
runShop(notDone, caseNum, optionText, input);
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually runs the shop program so that the user can both buy and sell things.
|
||||||
|
* @param notDone,caseNum both parameters govern the inner logic of the class and whether it allows for the player to run the shop
|
||||||
|
* @param optionText Text which is printed along with the rest of the shop
|
||||||
|
* @param input The scanner object that allows the program to respond to they user's inputs
|
||||||
|
*/
|
||||||
|
public void runShop(boolean notDone, int caseNum, String optionText, Scanner input) {
|
||||||
|
// as long as the user does not enter a valid input, the code will run in a loop forever.
|
||||||
|
while(notDone){
|
||||||
|
printShop();
|
||||||
|
System.out.printf("\nShall I (B)uy, (S)ell,%s or (Q)uit Trading?\n", optionText);
|
||||||
|
String response = input.next();
|
||||||
|
if (response.equalsIgnoreCase("B")) {
|
||||||
|
boolean notDone2 = true;
|
||||||
|
System.out.println("What do you wish me to buy, " + getName() + "?");
|
||||||
|
|
||||||
|
// when buying an item, the user must have the right amount of money, and buy non-negative amounts.
|
||||||
|
buying(input, notDone2);
|
||||||
|
|
||||||
|
} // when selling, the user must enter a non-negative amount of items, and not more than what they have.
|
||||||
|
else if (response.equalsIgnoreCase("S")) {
|
||||||
|
boolean notDone2 = true;
|
||||||
|
System.out.println("What do you wish me to sell, " + getName() + "?");
|
||||||
|
selling(input, notDone2);
|
||||||
|
|
||||||
|
} else if (response.equalsIgnoreCase("V") && (caseNum == 1 || caseNum == 3)) {
|
||||||
|
bank();
|
||||||
|
} else if (response.equalsIgnoreCase("T") && (caseNum == 1 || caseNum == 3)) {
|
||||||
|
warehouse();
|
||||||
|
} else if ((response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) && (caseNum == 1 || caseNum == 3)) {
|
||||||
|
loan();
|
||||||
|
} // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop.
|
||||||
|
else if (response.equalsIgnoreCase("Q") ) {
|
||||||
|
setIsPriceChanged(1);
|
||||||
|
travel();
|
||||||
|
notDone = false;
|
||||||
|
} // if the user wishes to retire and win the game, they may do so. Doing this breaks them out of the loop.
|
||||||
|
else if (response.equalsIgnoreCase("R") && caseNum == 3) {
|
||||||
|
retire();
|
||||||
|
notDone = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For all the buying inside the text-based shop
|
||||||
|
* @param input Takes the input Scanner and uses it to respond the user's inputs
|
||||||
|
* @param notDone2 Boolean which rules each while loop, if it turns false then the while loops stop
|
||||||
|
*/
|
||||||
|
public void buying(Scanner input, boolean notDone2) {
|
||||||
|
String response;
|
||||||
|
while (notDone2) {
|
||||||
|
response = input.nextLine();
|
||||||
|
if (response.equalsIgnoreCase("O")) {
|
||||||
|
System.out.println("\nHow much Opium shall I buy, " + getName() + "? (You can afford " + getMoney() / getOpiumPrice() + ")");
|
||||||
|
while (notDone2) {
|
||||||
|
int num = input.nextInt();
|
||||||
|
if (num <= getMoney() /getOpiumPrice() && num >= 0) {
|
||||||
|
setOpiumHeld(getOpiumHeld()+num);
|
||||||
|
setMoney(getMoney()-num *getOpiumPrice());
|
||||||
|
notDone2 = false;
|
||||||
|
} else if (num >= 0) {
|
||||||
|
System.out.println(getName() + ", you can't afford that!");
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (response.equalsIgnoreCase("S")) {
|
||||||
|
System.out.println("\nHow much Silk shall I buy, " + getName() + "? (You can afford " + getMoney() /getSilkPrice() + ")");
|
||||||
|
while (notDone2) {
|
||||||
|
int num = input.nextInt();
|
||||||
|
if (num <= getMoney() /getSilkPrice() && num >= 0) {
|
||||||
|
setSilkHeld(getSilkHeld()+num);
|
||||||
|
setMoney(getMoney()-num *getSilkPrice());
|
||||||
|
notDone2 = false;
|
||||||
|
} else if (num >= 0) {
|
||||||
|
System.out.println(getName() + ", you can't afford that!");
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (response.equalsIgnoreCase("A")) {
|
||||||
|
System.out.println("\nHow many Arms shall I buy, " + getName() + "? (You can afford " + getMoney() /getArmsPrice() + ")");
|
||||||
|
while (notDone2) {
|
||||||
|
int num = input.nextInt();
|
||||||
|
if (num <= getMoney() /getArmsPrice() && num >= 0) {
|
||||||
|
setArmsHeld(getArmsHeld()+num);
|
||||||
|
setMoney(getMoney() - num*getArmsPrice());
|
||||||
|
notDone2 = false;
|
||||||
|
} else if (num >= 0) {
|
||||||
|
System.out.println(getName() + ", you can't afford that!");
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (response.equalsIgnoreCase("G")) {
|
||||||
|
System.out.println("\nHow much General Cargo shall I buy, " + getName() + "? (You can afford " + getMoney() /getGeneralPrice() + ")");
|
||||||
|
while (notDone2) {
|
||||||
|
int num = input.nextInt();
|
||||||
|
if (num <= getMoney() /getGeneralPrice() && num >= 0) {
|
||||||
|
setGeneralHeld(getGeneralHeld()+num);
|
||||||
|
setMoney(getMoney() - num*getGeneralPrice());
|
||||||
|
notDone2 = false;
|
||||||
|
} else if (num >= 0) {
|
||||||
|
System.out.println(getName() + ", you can't afford that!");
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For all the selling inside the text-based shop
|
||||||
|
* @param input Takes the input Scanner and uses it to respond the user's inputs
|
||||||
|
* @param notDone2 Boolean which rules each while loop, if it turns false then the while loops stop
|
||||||
|
*/
|
||||||
|
public void selling(Scanner input, boolean notDone2) {
|
||||||
|
String response;
|
||||||
|
while (notDone2) {
|
||||||
|
response = input.nextLine();
|
||||||
|
if (response.equalsIgnoreCase("O")) {
|
||||||
|
System.out.println("\nHow much Opium shall I sell, " + getName() + "? (You have " + getOpiumHeld() + ")");
|
||||||
|
while (notDone2) {
|
||||||
|
int num = input.nextInt();
|
||||||
|
if (num <= getOpiumHeld() && num >= 0) {
|
||||||
|
setOpiumHeld(getOpiumHeld()-num);
|
||||||
|
setMoney(getMoney() + num*getOpiumPrice());
|
||||||
|
notDone2 = false;
|
||||||
|
} else if (num >= 0) {
|
||||||
|
System.out.println(getName() + ", you don't have that many to sell!");
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (response.equalsIgnoreCase("S")) {
|
||||||
|
System.out.println("\nHow much Silk shall I sell, " + getName() + "? (You have " + getSilkHeld() + ")");
|
||||||
|
while (notDone2) {
|
||||||
|
int num = input.nextInt();
|
||||||
|
if (num <= getSilkHeld() && num >= 0) {
|
||||||
|
setSilkHeld(getSilkHeld()-num);
|
||||||
|
setMoney(getMoney() + num*getSilkPrice());
|
||||||
|
notDone2 = false;
|
||||||
|
} else if (num >= 0) {
|
||||||
|
System.out.println(getName() + ", you don't have that many to sell!");
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (response.equalsIgnoreCase("A")) {
|
||||||
|
System.out.println("\nHow many Arms shall I sell, " + getName() + "? (You have " + getArmsHeld() + ")");
|
||||||
|
while (notDone2) {
|
||||||
|
int num = input.nextInt();
|
||||||
|
if (num <= getArmsHeld() && num >= 0) {
|
||||||
|
setArmsHeld(getArmsHeld()-num);
|
||||||
|
setMoney(getMoney() + num*getArmsPrice());
|
||||||
|
notDone2 = false;
|
||||||
|
} else if (num >= 0) {
|
||||||
|
System.out.println(getName() + ", you don't have that many to sell!");
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (response.equalsIgnoreCase("G")) {
|
||||||
|
System.out.println("\nHow much General Cargo shall I sell, " + getName() + "? (You have " + getGeneralHeld() + ")");
|
||||||
|
while (notDone2) {
|
||||||
|
int num = input.nextInt();
|
||||||
|
if (num <= getGeneralHeld() && num >= 0) {
|
||||||
|
setGeneralHeld(getGeneralHeld()-num);
|
||||||
|
setMoney(getMoney() + num*getGeneralPrice());
|
||||||
|
notDone2 = false;
|
||||||
|
} else if (num >= 0) {
|
||||||
|
System.out.println(getName() + ", you don't have that many to sell!");
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
125
src/text/TravelText.java
Normal file
125
src/text/TravelText.java
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import logic.Player;
|
||||||
|
import logic.TravelLogic;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TravelText extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
|
||||||
|
*
|
||||||
|
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
|
||||||
|
*/
|
||||||
|
public TravelText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) throws Exception {
|
||||||
|
Random rand = new Random();
|
||||||
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
if (randGenNum == 1) {
|
||||||
|
ShipWarfareText shipWarfareText = new ShipWarfareText(getPlayer());
|
||||||
|
shipWarfareText.peasantFleetAttack();
|
||||||
|
setPlayer(shipWarfareText.getPlayer());
|
||||||
|
} else if (randGenNum == 2) {
|
||||||
|
TravelLogic travelLogic = new TravelLogic(getPlayer());
|
||||||
|
travelLogic.disaster(locationOfTravel);
|
||||||
|
setPlayer(travelLogic.getPlayer());
|
||||||
|
|
||||||
|
System.out.println("We made it!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to travel between different areas inside of the game world.
|
||||||
|
* If the player's inventory is too full it won't run.
|
||||||
|
* Also calculates loan and bank interest between the jumps between islands.
|
||||||
|
**/
|
||||||
|
public void travelTo() {
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
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 (getCargoSpace() >= (getOpiumHeld() + (getGuns() * 10) + getSilkHeld() + getArmsHeld() + getGeneralHeld())) {
|
||||||
|
traveling(keyboard, hasTraveled);
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + " the cargo is too heavy! We can't set sail!");
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
setPlayer(taipanShopText.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The traveling method, it changes the location of the player and increments their interest and debt everytime the player travels
|
||||||
|
* Also allows for the player to be attacked by enemy ships and to be hit by random encounters.
|
||||||
|
* @param keyboard The Scanner object which allows for the program to respond to the user
|
||||||
|
* @param hasTraveled Checks whether the user has traveled or not
|
||||||
|
*/
|
||||||
|
public void traveling(Scanner keyboard, boolean hasTraveled) {
|
||||||
|
String response;
|
||||||
|
int tempInt;
|
||||||
|
while (true) {
|
||||||
|
System.out.println("\n" + 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();
|
||||||
|
//Sends the player back to shop if they want to quit
|
||||||
|
//if(response.equalsIgnoreCase("Q")){
|
||||||
|
// TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
// taipanShopText.shop();
|
||||||
|
//}
|
||||||
|
//Just in case the player types something that was not intended. It will refresh the question and ask it again
|
||||||
|
try {
|
||||||
|
tempInt = Integer.parseInt(response);
|
||||||
|
//Makes sure you can't travel to your own location.
|
||||||
|
if (tempInt != getLocation()) {
|
||||||
|
randomEventSea(tempInt);
|
||||||
|
|
||||||
|
//Checks the seaAtlas to see if the player can go to their location
|
||||||
|
TravelLogic travelLogic = new TravelLogic(getPlayer());
|
||||||
|
travelLogic.seaAtlas(tempInt);
|
||||||
|
setPlayer(travelLogic.getPlayer());
|
||||||
|
|
||||||
|
hasTraveled = true;
|
||||||
|
setBank((int) (getBank() * 1.01));
|
||||||
|
setDebt((int) (getDebt() * 1.01));
|
||||||
|
setIsPriceChanged(2);
|
||||||
|
|
||||||
|
} else System.out.println("\nYou're already here " + getName() + ".");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.print("\nSorry, " + getName() + " could you say that again?");
|
||||||
|
}
|
||||||
|
//If they've traveled then it randomly selects whether the player should go to the shop or a random event
|
||||||
|
if (hasTraveled) {
|
||||||
|
|
||||||
|
Random rand = new Random();
|
||||||
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
|
//Chance of going to shop
|
||||||
|
if(randGenNum >= 2) {
|
||||||
|
TaipanShopText taipanShopText = new TaipanShopText(getPlayer());
|
||||||
|
taipanShopText.shop();
|
||||||
|
}
|
||||||
|
//Chance of reaching a random event
|
||||||
|
else {
|
||||||
|
RandomEventText randomEventText = new RandomEventText(getPlayer());
|
||||||
|
randomEventText.randomEvent();
|
||||||
|
setPlayer(randomEventText.getPlayer());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
136
src/text/WarehouseText.java
Normal file
136
src/text/WarehouseText.java
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
package text;
|
||||||
|
|
||||||
|
import logic.Player;
|
||||||
|
import logic.WarehouseLogic;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class WarehouseText extends Player {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Constructor that takes in a type player as a parameter
|
||||||
|
*
|
||||||
|
* @param player object of the class Player
|
||||||
|
*/
|
||||||
|
public WarehouseText(Player player) {
|
||||||
|
Player playerDummy = new Player(player);
|
||||||
|
setPlayer(playerDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method adds an amount of a certain good
|
||||||
|
* the user is prompted to enter the amount they would like to
|
||||||
|
* add followed by the good they would like to add to the warehouse.
|
||||||
|
* the method checks if the player has sufficient goods to transfer, and if the player does
|
||||||
|
* then the method executes the transfer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void addAmount() {
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.println("Please enter the amount of the good you would like to deposit.");
|
||||||
|
String amount = keyboard.nextLine();
|
||||||
|
//Asks the user for the amount of the good they would like to add
|
||||||
|
/*The try function ensures that the program does not crash
|
||||||
|
due to any errors while giving the program an incorrect input*/
|
||||||
|
System.out.println("Please enter a good to transfer O, S, A, G :");
|
||||||
|
String good = keyboard.nextLine();
|
||||||
|
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||||
|
if(good.equalsIgnoreCase("g")){
|
||||||
|
System.out.println(warehouseLogic.deposit(amount,1));
|
||||||
|
}
|
||||||
|
else if(good.equalsIgnoreCase("a")){
|
||||||
|
System.out.println(warehouseLogic.deposit(amount,2));
|
||||||
|
}
|
||||||
|
else if(good.equalsIgnoreCase("s")){
|
||||||
|
System.out.println(warehouseLogic.deposit(amount,3));
|
||||||
|
}
|
||||||
|
else if(good.equalsIgnoreCase("o")){
|
||||||
|
System.out.println(warehouseLogic.deposit(amount,4));
|
||||||
|
}
|
||||||
|
setPlayer(warehouseLogic.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method removes an amount of a certain good
|
||||||
|
* the user is prompted to enter the amount they would like to
|
||||||
|
* remove followed by the good they would like to remove from the warehouse.
|
||||||
|
* the method checks if the player has sufficient goods to transfer, and if the player does
|
||||||
|
* then the method executes the transfer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void removeAmount() {
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
System.out.println("Please enter the amount of the good you would like to withdraw.");
|
||||||
|
String amount = keyboard.nextLine();
|
||||||
|
//Asks the user for the amount of the good they would like to withdraw
|
||||||
|
/*The try function ensures that the program does not crash
|
||||||
|
due to any errors while giving the program an incorrect input*/
|
||||||
|
System.out.println("Please enter a good to withdraw (O)pium, (S)ilk, (A)rms, (G)eneral:");
|
||||||
|
String good = keyboard.nextLine();
|
||||||
|
WarehouseLogic warehouseLogic = new WarehouseLogic(getPlayer());
|
||||||
|
if(good.equalsIgnoreCase("g")){
|
||||||
|
System.out.println(warehouseLogic.withdraw(amount,1));
|
||||||
|
}
|
||||||
|
else if(good.equalsIgnoreCase("a")){
|
||||||
|
System.out.println(warehouseLogic.withdraw(amount,2));
|
||||||
|
}
|
||||||
|
else if(good.equalsIgnoreCase("s")){
|
||||||
|
System.out.println(warehouseLogic.withdraw(amount,3));
|
||||||
|
}
|
||||||
|
else if(good.equalsIgnoreCase("o")){
|
||||||
|
System.out.println(warehouseLogic.withdraw(amount,4));
|
||||||
|
}
|
||||||
|
setPlayer(warehouseLogic.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method prints the stock that is in the warehouse currently using the get and set
|
||||||
|
* methods from the player class. This is to allow the user to be able to know how much they have
|
||||||
|
* stored in the warehouse
|
||||||
|
*/
|
||||||
|
public void showWarehouse() {
|
||||||
|
System.out.println("--------------------\nWarehouse\n--------------------");
|
||||||
|
System.out.println("Opium : " + getwOpium());
|
||||||
|
System.out.println("Silk : " + getwSilk());
|
||||||
|
System.out.println("General : " + getwGeneral());
|
||||||
|
System.out.println("Arms : " + getwArms());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method combines the add and remove methods and prompts the user to
|
||||||
|
* enter what they would like to do. Add or remove and accordingly invokes
|
||||||
|
* the required methods
|
||||||
|
*/
|
||||||
|
public void changeWarehouse() {
|
||||||
|
boolean keepGoing = true;
|
||||||
|
while (keepGoing) {
|
||||||
|
this.showWarehouse();
|
||||||
|
System.out.println("Would you like to (D)eposit or (W)ithdraw resources? ");
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
String input = keyboard.next();
|
||||||
|
if (input.equalsIgnoreCase("D")) {
|
||||||
|
this.addAmount();
|
||||||
|
this.showWarehouse();
|
||||||
|
} else if (input.equalsIgnoreCase("W")) {
|
||||||
|
this.removeAmount();
|
||||||
|
this.showWarehouse();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
System.out.println("Don't waste the warehouse's time, try again later with a valid input");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check to see if the player wants to continue in the warehouse or they are done
|
||||||
|
System.out.println("Would you like to do any other business? Y / N?");
|
||||||
|
String check = keyboard.nextLine();
|
||||||
|
check = keyboard.nextLine();
|
||||||
|
|
||||||
|
if (check.equalsIgnoreCase("Y")) {
|
||||||
|
keepGoing = true;
|
||||||
|
} else if (check.equalsIgnoreCase("N")) {
|
||||||
|
keepGoing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user