Added some content to the textgame files and added some stuff to the logic files. Also fixed formating in TravelGUI
This commit is contained in:
1516
.idea/workspace.xml
generated
1516
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -100,21 +100,7 @@ public class BankGUI extends Player {
|
|||||||
b1.setOnAction(new EventHandler<ActionEvent>() {
|
b1.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
try {
|
withdraw(txtField1, l5, l2, l4);
|
||||||
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -127,22 +113,7 @@ public class BankGUI extends Player {
|
|||||||
b2.setOnAction(new EventHandler<ActionEvent>() {
|
b2.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
try {
|
deposits(txtField1, l5, l2, l4);
|
||||||
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -172,6 +143,43 @@ public class BankGUI extends Player {
|
|||||||
return primaryStage;
|
return primaryStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets scene and runs stage
|
* sets scene and runs stage
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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.Player;
|
||||||
|
import logic.GameEndLogic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2019-03-10
|
* 2019-03-10
|
||||||
@@ -72,28 +73,15 @@ 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();
|
||||||
|
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());
|
||||||
/**
|
|
||||||
* 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("Firm Name: " + getName());
|
||||||
|
|||||||
@@ -704,7 +704,7 @@ public class TaipanShopGUI extends Player {
|
|||||||
textOut.setContentDisplay(javafx.scene.control.ContentDisplay.TOP);
|
textOut.setContentDisplay(javafx.scene.control.ContentDisplay.TOP);
|
||||||
textOut.setPrefHeight(163.0);
|
textOut.setPrefHeight(163.0);
|
||||||
textOut.setPrefWidth(583.0);
|
textOut.setPrefWidth(583.0);
|
||||||
//defaultTextOut();
|
defaultTextOut();
|
||||||
textOut.setFont(size14);
|
textOut.setFont(size14);
|
||||||
|
|
||||||
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);
|
anchorPane.getChildren().addAll(dialogueRectangle, inventoryRectangle, warehouseRectangle);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gui; /**
|
package gui;
|
||||||
|
|
||||||
|
/**
|
||||||
* TravelGUI is the class in which takes the player from location to location
|
* TravelGUI is the class in which takes the player from location to location
|
||||||
*
|
|
||||||
* Author: Harkamal Randhawa
|
* Author: Harkamal Randhawa
|
||||||
*/
|
*/
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
@@ -36,10 +37,8 @@ public class TravelGUI extends Player {
|
|||||||
private TextField numberInput = new TextField();
|
private TextField numberInput = new TextField();
|
||||||
|
|
||||||
private Boolean peasantShipScene = false;
|
private Boolean peasantShipScene = false;
|
||||||
private Boolean littyShipScene = false;
|
|
||||||
private Boolean shopScene = false;
|
private Boolean shopScene = false;
|
||||||
private Boolean stormScene = false;
|
private Boolean stormScene = false;
|
||||||
private Boolean sceneContinue = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
@@ -126,25 +125,24 @@ public class TravelGUI extends Player {
|
|||||||
//Makes sure you can't travel to your own location.
|
//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)){
|
if (response != getLocation() && response > 0 && 8 > response && event.getCode().equals(KeyCode.ENTER)||event.getCode().equals(KeyCode.Z)){
|
||||||
hasTraveled = seaAtlas(response);
|
hasTraveled = seaAtlas(response);
|
||||||
randomEventSea(response,stage);
|
randomEventSea(response);
|
||||||
setBank((int) (getBank() * 1.01));
|
setBank((int) (getBank() * 1.01));
|
||||||
setDebt((int) (getDebt() * 1.01));
|
setDebt((int) (getDebt() * 1.01));
|
||||||
setIsPriceChanged(2);
|
setIsPriceChanged(2);
|
||||||
//shopScene = false;
|
stormScene = false;
|
||||||
//stormScene = false;
|
|
||||||
|
|
||||||
} else{
|
} else{
|
||||||
if(response == getLocation()){
|
if(response == getLocation()){
|
||||||
textOut.setText(" " + "You're already here " + getName() + "\n");
|
textOut.setText("\tYou're already here " + getName() + "\n");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
textOut.setText(" " + getName() + "; Sorry but could you say that again?");
|
textOut.setText("\t" + 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?");
|
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?");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
textOut.setText(" " + "Sorry, " + getName() + " could you say that again?");
|
textOut.setText("\tSorry, " + getName() + " could you say that again?");
|
||||||
}
|
}
|
||||||
if (hasTraveled) {
|
if (hasTraveled) {
|
||||||
continueButton.setVisible(true);
|
continueButton.setVisible(true);
|
||||||
@@ -170,7 +168,7 @@ public class TravelGUI extends Player {
|
|||||||
root.getStylesheets().add("styleguide.css");
|
root.getStylesheets().add("styleguide.css");
|
||||||
//Updates the stage for the first-time you read it
|
//Updates the stage for the first-time you read it
|
||||||
shop.updateStage(firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText);
|
shop.updateStage(firm,wItemsText,wItemSpaceText,locationText,gunsText,inventoryText,inventoryHeldText,shipStatusText,cashText,bankText);
|
||||||
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.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.setTitle("Travel");
|
||||||
stage.setResizable(false);
|
stage.setResizable(false);
|
||||||
stage.setScene(root);
|
stage.setScene(root);
|
||||||
@@ -186,35 +184,35 @@ public class TravelGUI extends Player {
|
|||||||
private Boolean seaAtlas(int locationOfTravel) {
|
private Boolean seaAtlas(int locationOfTravel) {
|
||||||
switch (locationOfTravel) {
|
switch (locationOfTravel) {
|
||||||
case 1:
|
case 1:
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Hong Kong");
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Hong Kong");
|
||||||
setLocation(1);
|
setLocation(1);
|
||||||
return true;
|
return true;
|
||||||
case 2:
|
case 2:
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Shanghai");
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Shanghai");
|
||||||
setLocation(2);
|
setLocation(2);
|
||||||
return true;
|
return true;
|
||||||
case 3:
|
case 3:
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Nagasaki");
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Nagasaki");
|
||||||
setLocation(3);
|
setLocation(3);
|
||||||
return true;
|
return true;
|
||||||
case 4:
|
case 4:
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Saigon");
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Saigon");
|
||||||
setLocation(4);
|
setLocation(4);
|
||||||
return true;
|
return true;
|
||||||
case 5:
|
case 5:
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Manila");
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Manila");
|
||||||
setLocation(5);
|
setLocation(5);
|
||||||
return true;
|
return true;
|
||||||
case 6:
|
case 6:
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Singapore");
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Singapore");
|
||||||
setLocation(6);
|
setLocation(6);
|
||||||
return true;
|
return true;
|
||||||
case 7:
|
case 7:
|
||||||
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n " + "Arriving at Batavia");
|
if(!peasantShipScene && !stormScene) textOut.setText( textOut.getText() + "\n\tArriving at Batavia");
|
||||||
setLocation(7);
|
setLocation(7);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
textOut.setText(" " + "Sorry but could you say that again " + getName() + "?");
|
textOut.setText("\tSorry but could you say that again " + getName() + "?");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,7 +223,7 @@ public class TravelGUI extends Player {
|
|||||||
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
|
* @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed
|
||||||
* by a typhoon.
|
* by a typhoon.
|
||||||
**/
|
**/
|
||||||
private void randomEventSea(int locationOfTravel, Stage stage) {
|
private void randomEventSea(int locationOfTravel) {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
int randGenNum = rand.nextInt(3) + 1;
|
int randGenNum = rand.nextInt(3) + 1;
|
||||||
if (randGenNum == 1) {
|
if (randGenNum == 1) {
|
||||||
@@ -233,7 +231,7 @@ public class TravelGUI extends Player {
|
|||||||
continueButton.setDefaultButton(true);
|
continueButton.setDefaultButton(true);
|
||||||
quitButton.setVisible(false);
|
quitButton.setVisible(false);
|
||||||
numberInput.setVisible(false);
|
numberInput.setVisible(false);
|
||||||
textOut.setText(" We see a ship on the horizon " + getName() + "; Prepare for combat!");
|
textOut.setText("\tWe see a ship on the horizon " + getName() + "; Prepare for combat!");
|
||||||
peasantShipScene = true;
|
peasantShipScene = true;
|
||||||
}else if (randGenNum == 2) {
|
}else if (randGenNum == 2) {
|
||||||
disaster(locationOfTravel);
|
disaster(locationOfTravel);
|
||||||
@@ -250,66 +248,22 @@ public class TravelGUI extends Player {
|
|||||||
**/
|
**/
|
||||||
private void disaster(int locationOfTravel) {
|
private void disaster(int locationOfTravel) {
|
||||||
//Tells player that there is a storm approaching.
|
//Tells player that there is a storm approaching.
|
||||||
textOut.setText(" " + "Storm " + getName() + "! ");
|
textOut.setText("\tStorm " + getName() + "! ");
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
int randGenNum = rand.nextInt(5) + 1;
|
int randGenNum = rand.nextInt(5) + 1;
|
||||||
|
|
||||||
//If the player lands within this range, nothing happens to them
|
//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).
|
//Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel).
|
||||||
if (randGenNum <= 2) {
|
if (randGenNum <= 2) {
|
||||||
textOut.setText(textOut.getText() + "\n " + "We got through the storm " + getName() + "!");
|
textOut.setText(textOut.getText() + "\n\tWe got through the storm " + getName() + "!");
|
||||||
}else {
|
}else {
|
||||||
while (randGenNum == locationOfTravel) {
|
while (randGenNum == locationOfTravel) {
|
||||||
randGenNum = rand.nextInt(7) + 1;
|
randGenNum = rand.nextInt(7) + 1;
|
||||||
if (randGenNum != locationOfTravel) {
|
if (randGenNum != locationOfTravel) {
|
||||||
textOut.setText(textOut.getText() + "\n " + "We've been blown off course!");
|
textOut.setText(textOut.getText() + "\n\tWe've been blown off course!");
|
||||||
seaAtlas(randGenNum);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,20 +18,12 @@ public class FileSaving extends Player implements Serializable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
|
InputStream in = new FileInputStream(new File("src/saves/playerSave.txt"));
|
||||||
ObjectInputStream inObject = new ObjectInputStream(in);
|
return getPlayer(in);
|
||||||
Player player = (Player) inObject.readObject();
|
|
||||||
in.close();
|
|
||||||
inObject.close();
|
|
||||||
return player;
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
InputStream in = new FileInputStream(new File("saves/playerSave.txt"));
|
InputStream in = new FileInputStream(new File("saves/playerSave.txt"));
|
||||||
ObjectInputStream inObject = new ObjectInputStream(in);
|
return getPlayer(in);
|
||||||
Player player = (Player) inObject.readObject();
|
|
||||||
in.close();
|
|
||||||
inObject.close();
|
|
||||||
return player;
|
|
||||||
}
|
}
|
||||||
catch(Exception e2){
|
catch(Exception e2){
|
||||||
return null;
|
return null;
|
||||||
@@ -39,6 +31,14 @@ public class FileSaving extends Player implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
* Saves the file of type player which contains all the player instances
|
||||||
* @param player The player object being saved
|
* @param player The player object being saved
|
||||||
|
|||||||
@@ -1,4 +1,27 @@
|
|||||||
package logic;
|
package logic;
|
||||||
|
|
||||||
public class GameEndLogic extends Player{
|
public class GameEndLogic extends Player{
|
||||||
|
/**
|
||||||
|
* Calculates the networth of the player by the end of 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!";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,42 +77,18 @@ public class TaipanShopLogic extends Player {
|
|||||||
public String shipStatusString(){
|
public String shipStatusString(){
|
||||||
String shipStatus;
|
String shipStatus;
|
||||||
switch(getHP()/10){
|
switch(getHP()/10){
|
||||||
case 10:
|
case 10: shipStatus = "Mint Condition"; break;
|
||||||
shipStatus = "Mint Condition";
|
case 9: shipStatus = "Near Perfect"; break;
|
||||||
break;
|
case 8: shipStatus = "Great"; break;
|
||||||
case 9:
|
case 7: shipStatus = "Good"; break;
|
||||||
shipStatus = "Near Perfect";
|
case 6: shipStatus = "Acceptable"; break;
|
||||||
break;
|
case 5: shipStatus = "Tolerable"; break;
|
||||||
case 8:
|
case 4: shipStatus = "Needs Repair"; break;
|
||||||
shipStatus = "Great";
|
case 3: shipStatus = "Damaged"; break;
|
||||||
break;
|
case 2: shipStatus = "Indangered"; break;
|
||||||
case 7:
|
case 1: shipStatus = "Near Sinking"; break;
|
||||||
shipStatus = "Good";
|
case 0: shipStatus = "Sinking"; break;
|
||||||
break;
|
default: shipStatus = "Invincible"; 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;
|
return shipStatus;
|
||||||
}
|
}
|
||||||
@@ -125,32 +101,17 @@ public class TaipanShopLogic extends Player {
|
|||||||
public String getStringLocation(){
|
public String getStringLocation(){
|
||||||
String location;
|
String location;
|
||||||
switch(getLocation()){
|
switch(getLocation()){
|
||||||
case 1:
|
case 1: location = "Hong Kong"; break;
|
||||||
location = "Hong Kong";
|
case 2: location = "Shanghai"; break;
|
||||||
break;
|
case 3: location = "Nagasaki"; break;
|
||||||
case 2:
|
case 4: location = "Saigon"; break;
|
||||||
location = "Shanghai";
|
case 5: location = "Manila"; break;
|
||||||
break;
|
case 6: location = "Singapore"; break;
|
||||||
case 3:
|
case 7: location = "Batavia"; break;
|
||||||
location = "Nagasaki";
|
default: location = "Error"; break;
|
||||||
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;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -2,12 +2,78 @@ package text;
|
|||||||
|
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class BankText extends Player {
|
public class BankText extends Player {
|
||||||
|
|
||||||
public BankText(Player player) {
|
public BankText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
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(){
|
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")){
|
||||||
|
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()){
|
||||||
|
setMoney(withdraw + getMoney());
|
||||||
|
setBank(getBank()-withdraw);
|
||||||
|
notDone2 = false;
|
||||||
|
check = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//If the user chooses to deposit the continue to this code
|
||||||
|
else if(response.equalsIgnoreCase("D")){
|
||||||
|
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()){
|
||||||
|
setBank(deposit + getBank());
|
||||||
|
setMoney(getMoney()-deposit);
|
||||||
|
notDone2 = false;
|
||||||
|
check = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(check == 1){
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package text;
|
|||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
public class GameEndText extends Player {
|
public class GameEndText extends Player {
|
||||||
|
|
||||||
public GameEndText(Player player) {
|
public GameEndText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
setPlayer(playerDummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,43 @@ package text;
|
|||||||
|
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class StartText extends Player {
|
public class StartText extends Player {
|
||||||
|
|
||||||
public StartText(Player player) {
|
public StartText(Player player) {
|
||||||
Player playerDummy = new Player(player);
|
Player playerDummy = new Player(player);
|
||||||
setPlayer(playerDummy);
|
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()
|
||||||
|
{
|
||||||
|
Scanner userInput = new Scanner(System.in);
|
||||||
|
System.out.println("Taipan, \nWhat will you name your firm:");
|
||||||
|
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 ");
|
||||||
|
int input = userInput.nextInt();
|
||||||
|
if (input == 1)
|
||||||
|
{
|
||||||
|
setMoney(400);
|
||||||
|
setDebt(5000);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (input == 2)
|
||||||
|
{
|
||||||
|
setGuns(5);
|
||||||
|
}
|
||||||
|
// purely for testing purposes.
|
||||||
|
if(getName().equalsIgnoreCase("Vikram")){
|
||||||
|
setMoney(999999999);
|
||||||
|
setBank(999999999);
|
||||||
|
setGuns(999);
|
||||||
|
setHP(99999999);
|
||||||
|
setCargoSpace(99999999);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package text;
|
package text;
|
||||||
|
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class TravelText extends Player {
|
public class TravelText extends Player {
|
||||||
|
|
||||||
public TravelText(Player player) {
|
public TravelText(Player player) {
|
||||||
@@ -8,6 +12,131 @@ public class TravelText extends Player {
|
|||||||
setPlayer(playerDummy);
|
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.
|
||||||
|
*/
|
||||||
|
private 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 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) {
|
||||||
|
disaster(locationOfTravel);
|
||||||
|
System.out.println("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.
|
||||||
|
System.out.print("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) {
|
||||||
|
System.out.println(" We made it through!");
|
||||||
|
} else {
|
||||||
|
while (randGenNum == locationOfTravel) {
|
||||||
|
randGenNum = rand.nextInt(7) + 1;
|
||||||
|
if (randGenNum != locationOfTravel) {
|
||||||
|
System.out.println("We've been blown off course!");
|
||||||
|
seaAtlas(randGenNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
public void travelTo() {
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
String response;
|
||||||
|
int tempInt;
|
||||||
|
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())) {
|
||||||
|
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();
|
||||||
|
//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);
|
||||||
|
seaAtlas(tempInt);
|
||||||
|
hasTraveled = true;
|
||||||
|
setBank((int) (getBank() * 1.01));
|
||||||
|
setDebt((int) (getDebt() * 1.01));
|
||||||
|
} else System.out.println("\nYou're already here " + getName() + ".");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.print("\nSorry, " + getName() + " could you say that again?");
|
||||||
|
}
|
||||||
|
if (hasTraveled) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println(getName() + " the cargo is too heavy! We can't set sail!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package text;
|
|||||||
|
|
||||||
import logic.Player;
|
import logic.Player;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class WarehouseText extends Player {
|
public class WarehouseText extends Player {
|
||||||
|
|
||||||
public WarehouseText(Player player) {
|
public WarehouseText(Player player) {
|
||||||
@@ -9,6 +11,228 @@ public class WarehouseText extends Player {
|
|||||||
setPlayer(playerDummy);
|
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() {
|
||||||
|
boolean askGood = false;
|
||||||
|
String amount;
|
||||||
|
int finalAmount = 0;
|
||||||
|
System.out.println("Please enter the amount of the good you would like to ADD.");
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
amount = keyboard.nextLine();//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*/
|
||||||
|
try {
|
||||||
|
//The if statement checks that you have enough resources to make the transfer
|
||||||
|
if (Integer.parseInt(amount) <= getOpiumHeld() || Integer.parseInt(amount) <= getSilkHeld() || Integer.parseInt(amount) <= getGeneralHeld() || Integer.parseInt(amount) <= getArmsHeld()) {
|
||||||
|
finalAmount = Integer.parseInt(amount);
|
||||||
|
askGood = true;
|
||||||
|
}
|
||||||
|
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
|
||||||
|
else {
|
||||||
|
System.out.println("Nice try but you don't have any items of that quantity!");
|
||||||
|
askGood = false;
|
||||||
|
}
|
||||||
|
//Ensures that goods are only transferred if they have the specified amount
|
||||||
|
//The user is prompted to enter which good they want to transfer
|
||||||
|
if (askGood == true) {
|
||||||
|
String good;
|
||||||
|
System.out.println("Please enter a good to transfer O, S, G, A :");
|
||||||
|
good = keyboard.nextLine();
|
||||||
|
int held = 0;
|
||||||
|
//The following set of loops check to see which good the user has selected and makes the transfer
|
||||||
|
if (Integer.parseInt(amount) > 0) {
|
||||||
|
if (good.equalsIgnoreCase("O")) {
|
||||||
|
if (getOpiumHeld() >= Integer.parseInt(amount)) {
|
||||||
|
setwOpium(getwOpium() + finalAmount);
|
||||||
|
held = getOpiumHeld();
|
||||||
|
setOpiumHeld(held - finalAmount);
|
||||||
|
System.out.println(getOpiumHeld());
|
||||||
|
} else {
|
||||||
|
System.out.println("You don't even have that much opium!");
|
||||||
|
}
|
||||||
|
} else if (good.equalsIgnoreCase("S")) {
|
||||||
|
if (getSilkHeld() >= Integer.parseInt(amount)) {
|
||||||
|
setwSilk(getwSilk() + finalAmount);
|
||||||
|
held = getSilkHeld();
|
||||||
|
setSilkHeld(held - finalAmount);
|
||||||
|
} else {
|
||||||
|
System.out.println("You don't even have that much silk!");
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (good.equalsIgnoreCase("G")) {
|
||||||
|
if (getGeneralHeld() >= Integer.parseInt(amount)) {
|
||||||
|
setwGeneral(getwGeneral() + finalAmount);
|
||||||
|
held = getGeneralHeld();
|
||||||
|
setGeneralHeld(held - finalAmount);
|
||||||
|
} else {
|
||||||
|
System.out.println("You don't even have that much general cargo!");
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (good.equalsIgnoreCase("A")) {
|
||||||
|
if (getArmsHeld() >= Integer.parseInt(amount)) {
|
||||||
|
setwArms(getwArms() + finalAmount);
|
||||||
|
held = getArmsHeld();
|
||||||
|
setArmsHeld(held - finalAmount);
|
||||||
|
} else {
|
||||||
|
System.out.println("You don't even have that much Arms!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Ensures no negative amounts are entered
|
||||||
|
else {
|
||||||
|
System.out.println("Sorry this transfer cannot be made");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Wait, that's not a valid input please try again");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
||||||
|
String amount;
|
||||||
|
boolean askGood = false;
|
||||||
|
int finalAmount = 0;
|
||||||
|
System.out.println("Please enter the amount of the good you would like to REMOVE");
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
//Prompts the user for the amount they would like to remove
|
||||||
|
amount = keyboard.nextLine();
|
||||||
|
//The if statement checks that you have enough resources to make the transfer
|
||||||
|
try {
|
||||||
|
//The if statement checks that you have enough resources to make the transfer
|
||||||
|
if (Integer.parseInt(amount) <= getwOpium() || Integer.parseInt(amount) <= getwSilk() || Integer.parseInt(amount) <= getwGeneral() || Integer.parseInt(amount) <= getwArms()) {
|
||||||
|
finalAmount = Integer.parseInt(amount);
|
||||||
|
askGood = true;
|
||||||
|
}
|
||||||
|
//Else statement lets the user know that they do not hav enough goods to make the requested transfer
|
||||||
|
else {
|
||||||
|
System.out.println("Nice try but you don't have any items of that quantity in the warehouse!");
|
||||||
|
askGood = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ensures that goods are only transferred if they have the specified amount
|
||||||
|
//The user is prompted to enter which good they want to transfer
|
||||||
|
|
||||||
|
if (askGood == true) {
|
||||||
|
String good;
|
||||||
|
System.out.println("Please enter a good to transfer O, S, G, A :");
|
||||||
|
good = keyboard.nextLine();
|
||||||
|
int held = 0;
|
||||||
|
//The following set of loops check to see which good the user has selected and makes the transfer and amount > 0
|
||||||
|
if (Integer.parseInt(amount) > 0) {
|
||||||
|
if (good.equalsIgnoreCase("O")) {
|
||||||
|
if (getwOpium() >= Integer.parseInt(amount)) {
|
||||||
|
setwOpium(getwOpium() - Integer.parseInt(amount));
|
||||||
|
held = getOpiumHeld();
|
||||||
|
setOpiumHeld(held + finalAmount);
|
||||||
|
} else {
|
||||||
|
System.out.println("You don't have that much opium stored in the warehouse!");
|
||||||
|
}
|
||||||
|
} else if (good.equalsIgnoreCase("S")) {
|
||||||
|
if (getwSilk() >= Integer.parseInt(amount)) {
|
||||||
|
setwSilk(getwSilk() - Integer.parseInt(amount));
|
||||||
|
held = getSilkHeld();
|
||||||
|
setSilkHeld(held + finalAmount);
|
||||||
|
} else {
|
||||||
|
System.out.println("You don't have that much silk stored in the warehouse!");
|
||||||
|
}
|
||||||
|
} else if (good.equalsIgnoreCase("G")) {
|
||||||
|
if (getwGeneral() >= Integer.parseInt(amount)) {
|
||||||
|
setwGeneral(getwGeneral() - Integer.parseInt(amount));
|
||||||
|
held = getGeneralHeld();
|
||||||
|
setGeneralHeld(held + finalAmount);
|
||||||
|
} else {
|
||||||
|
System.out.println("You don't have that much general cargo stored in the warehouse!");
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (good.equalsIgnoreCase("A")) {
|
||||||
|
if (getwArms() >= Integer.parseInt(amount)) {
|
||||||
|
setwArms(getwArms() - Integer.parseInt(amount));
|
||||||
|
held = getArmsHeld();
|
||||||
|
setArmsHeld(held + finalAmount);
|
||||||
|
} else {
|
||||||
|
System.out.println("You don't have that much arms stored in the warehouse!");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Ensures the value entered is positive
|
||||||
|
else {
|
||||||
|
System.out.println("Sorry this transfer cannot be made");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//If the program errors out this is the message displayed and the method is re-run, so that the game does not end.
|
||||||
|
catch (Exception e){
|
||||||
|
System.out.println("Wait, that's not a valid input please try again");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
public void changeWarehouse() {
|
||||||
|
boolean keepGoing = true;
|
||||||
|
while (keepGoing) {
|
||||||
|
this.showWarehouse();
|
||||||
|
String input = " ";
|
||||||
|
System.out.println("Would you like to add(A) or remove(R) resources? ");
|
||||||
|
Scanner keyboard = new Scanner(System.in);
|
||||||
|
input = keyboard.next();
|
||||||
|
if (input.equalsIgnoreCase("R")) {
|
||||||
|
this.removeAmount();
|
||||||
|
this.showWarehouse();
|
||||||
|
} else if (input.equalsIgnoreCase("A")) {
|
||||||
|
this.addAmount();
|
||||||
|
this.showWarehouse();
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
System.out.println("Don't waste the warehouse's time, try again later with a valid input");
|
||||||
|
}
|
||||||
|
|
||||||
|
String check;
|
||||||
|
//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?");
|
||||||
|
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