diff --git a/README.md b/README.md index faf928c..0d87859 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,15 @@ Computer Science 233 project, Winter 2019 How to run: -If you are using intellij, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder in intellij. Also set up the SDK. Then, run MainGUI.java. +If you are using intellij, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder in intellij. Also set up the SDK. + +Place jfxt.jar, hamcrest-core-1.3.jar and junit-4.12.jar into the src folder +Then, run MainGUI.java. If you are using the command line, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder. Open your terminal and change its directory to the "src" folder within "TaipanClone-master" folder. Then, type in "javac *.java", this compiles all the necessary files. Now, run MainGUI.java using "java MainGUI". +To run the test file PlayerTest.java, type in "javac *.java", this compiles all the necessary files. Now, run PlayerTest.java using "java PlayerTest". + 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. diff --git a/src/BankGUI.java b/src/BankGUI.java index 8218d0f..4195662 100644 --- a/src/BankGUI.java +++ b/src/BankGUI.java @@ -47,9 +47,9 @@ public class BankGUI extends Player{ VBox vbx1 = new VBox(30); Label l1 = new Label("Player: " + getName()); - Label l2 = new Label("Current Balance: " + getBank()); + Label l2 = new Label("Balance: " + getBank()); Label l3 = new Label("Enter Amount: "); - Label l4 = new Label("Current cash: " + getMoney()); + Label l4 = new Label("Cash: " + getMoney()); Label l5 = new Label(" "); Button b1 = new Button("Withdraw"); @@ -100,20 +100,20 @@ public class BankGUI extends Player{ try { int withdraw = Integer.parseInt(txtField1.getText()); if(withdraw < 0){ - l5.setText("Come on " + getName() + " are you trying to fool me??? \n No negative Numbers Please"); + 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 cannot withdraw that much"); + l5.setText("Sorry, you can not withdraw that much."); } - l2.setText("Current Balance: " + getBank()); - l4.setText("Current cash: " + getMoney()); + l2.setText("Balance: " + getBank()); + l4.setText("Cash: " + getMoney()); } catch (Exception e) { - l5.setText("Please enter a valid value"); + l5.setText("Please enter a valid response."); } } } @@ -130,20 +130,20 @@ public class BankGUI extends Player{ try { int deposit = Integer.parseInt(txtField1.getText()); if(deposit < 0){ - l5.setText("Nice Try!!! No negative Numbers Please"); + 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 cannot deposit that much.$"); + l5.setText("Sorry, you can not deposit that much."); } - l2.setText("Current Balance: " + getBank()); - l4.setText("Current cash: " + getMoney()); + l2.setText("Balance: " + getBank()); + l4.setText("Cash: " + getMoney()); } catch (Exception e) { - l5.setText("Please enter a valid value"); + l5.setText("Please enter a valid response."); } } } diff --git a/src/FileSaving.java b/src/FileSaving.java index b5143de..60055f8 100644 --- a/src/FileSaving.java +++ b/src/FileSaving.java @@ -13,6 +13,7 @@ public class FileSaving extends Player implements Serializable { * @return player */ public Player loadFile() { + try { InputStream in = new FileInputStream(new File("src/saves/playerSave.txt")); ObjectInputStream inObject = new ObjectInputStream(in); @@ -22,7 +23,17 @@ public class FileSaving extends Player implements Serializable { return player; } catch (Exception e) { - return null; + 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; + } } } @@ -39,7 +50,18 @@ public class FileSaving extends Player implements Serializable { return true; } catch (Exception e) { - return false; + 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; + } } } diff --git a/src/LoanSharkGUI.java b/src/LoanSharkGUI.java index 059fa81..ad67eb4 100644 --- a/src/LoanSharkGUI.java +++ b/src/LoanSharkGUI.java @@ -50,8 +50,8 @@ public class LoanSharkGUI extends Player { //Declaring all Variables Label l1 = new Label("Player: " + getName()); - Label l2 = new Label("Current Debt " + getDebt()); - Label l4 = new Label("Current cash: " + getMoney()); + Label l2 = new Label("Debt " + getDebt()); + Label l4 = new Label("Cash: " + getMoney()); Label l3 = new Label("Enter Amount: "); Label l5 = new Label(" "); @@ -98,7 +98,7 @@ public class LoanSharkGUI extends Player { if (loanAsk <= 2 * (getMoney() - getDebt()) && loanAsk >= 0) { setDebt(getDebt() + loanAsk); setMoney(getMoney() + loanAsk); - l4.setText("Current cash: " + getMoney()); + l4.setText("Cash: " + getMoney()); } else if (loanAsk < 0) { l5.setText("Sorry you cannot enter negative numbers"); } @@ -126,18 +126,18 @@ public class LoanSharkGUI extends Player { int returnAsk = Integer.parseInt(txtField1.getText()); if (returnAsk > getDebt()) { - l5.setText("You dont need to return that much"); + 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("Current cash: " + getMoney()); + l4.setText("Cash: " + getMoney()); } else if(getMoney() < returnAsk) { l5.setText("Look " + getName() + ", you are being cheap!"); } else { - l5.setText("Sorry you cannot return a negative amount"); + l5.setText("Sorry, you can not return a negative amount!"); } l2.setText("Debt: " + getDebt()); } diff --git a/src/TaipanShopGUI.java b/src/TaipanShopGUI.java index f2cc978..6f88c22 100644 --- a/src/TaipanShopGUI.java +++ b/src/TaipanShopGUI.java @@ -492,6 +492,7 @@ public class TaipanShopGUI extends Player{ */ @Override public void handle(ActionEvent event) { + saving.saveFile(getPlayer()); setIsPriceChanged(1); TravelGUI travelGUI = new TravelGUI(getPlayer()); travelGUI.initializeTravel(stage);