the shop now uses the player class as a parent class.

This commit is contained in:
Vikram
2019-02-18 19:47:42 -07:00
parent 534b8728a5
commit a5cc88e5ec
3 changed files with 170 additions and 162 deletions

2
.idea/misc.xml generated
View File

@@ -3,7 +3,7 @@
<component name="ProjectKey">
<option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_141" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_191" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SvnBranchConfigurationManager">

96
.idea/workspace.xml generated
View File

@@ -2,9 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/TaipanClone/ShipWarfare.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/TaipanClone/ShipWarfare.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ShipWarfare.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ShipWarfare.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/TaipanShop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TaipanShop.java" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -15,30 +15,23 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="10" lean-forward="true" selection-start-line="10" selection-end-line="10" />
<state relative-caret-position="190">
<caret line="10" selection-start-line="10" selection-end-line="10" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1230#1231#0" expanded="true" />
<element signature="e#1285#1286#0" expanded="true" />
<element signature="e#1336#1337#0" expanded="true" />
<element signature="e#1417#1418#0" expanded="true" />
<element signature="e#1552#1553#0" expanded="true" />
<element signature="e#1621#1622#0" expanded="true" />
<element signature="e#1742#1743#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4221">
<caret line="283" column="29" selection-start-line="283" selection-start-column="29" selection-end-line="283" selection-end-column="29" />
<state relative-caret-position="228">
<caret line="147" lean-forward="true" selection-start-line="147" selection-end-line="147" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -47,8 +40,12 @@
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/TaipanClone.iml">
<provider selected="true" editor-type-id="text-editor" />
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="13" selection-start-column="13" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
</leaf>
@@ -65,7 +62,17 @@
<find>couldn</find>
<find>could</find>
<find>runFromShips</find>
<find>name</find>
<find>bank</find>
<find>player.getMoney() += num *</find>
<find>opiumHeld</find>
</findStrings>
<replaceStrings>
<replace>player.getName()</replace>
<replace>player.getBank()</replace>
<replace>player.setMoney(player.getMoney() + num*)</replace>
<replace>player.getOpiumHeld()</replace>
</replaceStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@@ -73,12 +80,12 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/TaipanShop.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" />
<option value="$PROJECT_DIR$/src/TaipanShop.java" />
</list>
</option>
</component>
<component name="ProjectFrameBounds">
<component name="ProjectFrameBounds" extendedState="6">
<option name="y" value="23" />
<option name="width" value="1280" />
<option name="height" value="709" />
@@ -89,6 +96,8 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="PackagesPane" />
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@@ -105,14 +114,12 @@
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1550458702863" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1550544262278" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="project.structure.last.edited" value="SDKs" />
<property name="project.structure.proportion" value="0.0" />
@@ -131,7 +138,7 @@
</list>
</option>
</component>
<component name="RunManager" selected="Application.ShipWarfare">
<component name="RunManager" selected="Application.TaipanShop">
<configuration name="Main" type="Application" factoryName="Application" temporary="true">
<option name="MAIN_CLASS_NAME" value="Main" />
<module name="TaipanClone" />
@@ -149,12 +156,21 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaipanShop" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="TaipanShop" />
<module name="TaipanClone" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="Application.Main" />
<item itemvalue="Application.ShipWarfare" />
<item itemvalue="Application.TaipanShop" />
</list>
<recent_temporary>
<list>
<item itemvalue="Application.TaipanShop" />
<item itemvalue="Application.ShipWarfare" />
<item itemvalue="Application.Main" />
</list>
@@ -187,10 +203,10 @@
<option name="totallyTimeSpent" value="459000" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="23" width="1280" height="709" extended-state="0" />
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25767368" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.1705757" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
@@ -199,7 +215,7 @@
<window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32901135" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32827735" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -207,7 +223,7 @@
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Terminal" order="10" />
<window_info anchor="bottom" id="Terminal" order="10" weight="0.32936078" />
<window_info anchor="bottom" id="Event Log" order="11" side_tool="true" />
<window_info anchor="bottom" id="Messages" order="12" weight="0.32901135" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
@@ -236,29 +252,29 @@
<entry file="file://$PROJECT_DIR$/TaipanClone.iml">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4221">
<caret line="283" column="29" selection-start-line="283" selection-start-column="29" selection-end-line="283" selection-end-column="29" />
<state>
<caret column="13" selection-start-column="13" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="190">
<caret line="10" selection-start-line="10" selection-end-line="10" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="10" lean-forward="true" selection-start-line="10" selection-end-line="10" />
<state relative-caret-position="228">
<caret line="147" lean-forward="true" selection-start-line="147" selection-end-line="147" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1230#1231#0" expanded="true" />
<element signature="e#1285#1286#0" expanded="true" />
<element signature="e#1336#1337#0" expanded="true" />
<element signature="e#1417#1418#0" expanded="true" />
<element signature="e#1552#1553#0" expanded="true" />
<element signature="e#1621#1622#0" expanded="true" />
<element signature="e#1742#1743#0" expanded="true" />
</folding>
</state>
</provider>

View File

@@ -1,25 +1,17 @@
import java.util.Random;
import java.util.Scanner;
public class TaipanShop {
public class TaipanShop extends Player {
private String name = "Taipan";
private int bank = 0;
private int money = 1000;
private int opiumHeld = 0;
private int silkHeld = 0;
private int generalHeld = 0;
private int armsHeld = 0;
private Player player = new Player();
private int cargoSpace = 60;
private int currentCargo = 0;
private int opiumPrice = 16000;
private int silkPrice = 1600;
private int armsPrice = 160;
private int generalPrice = 8;
private int location = 1;
private int guns = 0;
public void updatePrices(){
String s = "\n" + name + ", the price of ";
private void updatePrices(){
String s = "\n" + player.getName() + ", the price of ";
double value = 80*Math.random();
Random rand = new Random();
opiumPrice = (rand.nextInt(201) + 60)*100;
@@ -63,19 +55,19 @@ public class TaipanShop {
}
}
public void printShop(){
currentCargo = opiumHeld+guns*10+silkHeld+armsHeld+generalHeld;
private void printShop(){
currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld();
if(cargoSpace - currentCargo < 0){
System.out.println("Hold: Overloaded" + " Guns: " + guns);
System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns());
}else{
System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + guns);
System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + player.getGuns());
}
System.out.println("-------------------------------------------------------------");
System.out.println(" Opium: " + opiumHeld + " Silk: " + silkHeld);
System.out.println(" Arms: " + armsHeld + " General: " + generalHeld);
System.out.println(" Opium: " + player.getOpiumHeld() + " Silk: " + player.getSilkHeld());
System.out.println(" Arms: " + player.getArmsHeld() + " General: " + player.getGeneralHeld());
System.out.println("-------------------------------------------------------------");
System.out.println("Cash: " + money + " Bank: " + bank+"\n");
System.out.println(name + ", present prices per unit here are:");
System.out.println("Cash: " + player.getMoney() + " Bank: " + player.getBank()+"\n");
System.out.println(player.getName() + ", present prices per unit here are:");
System.out.println(" Opium: " + opiumPrice + " Silk: " + silkPrice);
System.out.println(" Arms: " + armsPrice + " General: " + generalPrice);
}
@@ -84,70 +76,70 @@ public class TaipanShop {
updatePrices();
Scanner input = new Scanner(System.in);
boolean notDone = true;
if (location == 1) {
if (player.getLocation() == 1) {
while (notDone) {
printShop();
System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, or Quit Trading?");
String response = input.next();
if (response.equalsIgnoreCase("B")) {
boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + name + "?");
System.out.println("What do you wish me to buy, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + name + "? (You can afford " + money / opiumPrice + ")");
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= money / opiumPrice && num >= 0) {
opiumHeld += num;
money -= num * opiumPrice;
if (num <= player.getMoney() / opiumPrice && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()+num);
player.setMoney(player.getMoney()-num * opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you can't afford that!");
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(name + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + name + "? (You can afford " + money / silkPrice + ")");
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= money / silkPrice && num >= 0) {
silkHeld += num;
money -= num * silkPrice;
if (num <= player.getMoney() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld()+num);
player.setMoney(player.getMoney()-num * silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you can't afford that!");
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(name + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + name + "? (You can afford " + money / armsPrice + ")");
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= money / armsPrice && num >= 0) {
armsHeld += num;
money -= num * armsPrice;
if (num <= player.getMoney() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you can't afford that!");
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(name + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + name + "? (You can afford " + money / generalPrice + ")");
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= money / generalPrice && num >= 0) {
generalHeld += num;
money -= num * generalPrice;
if (num <= player.getMoney() / generalPrice && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()+num);
player.setMoney(player.getMoney() - num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you can't afford that!");
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(name + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
@@ -156,63 +148,63 @@ public class TaipanShop {
} else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + name + "?");
System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + name + "? (You have " + opiumHeld + ")");
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= opiumHeld && num >= 0) {
opiumHeld -= num;
money += num * opiumPrice;
if (num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()-num);
player.setMoney(player.getMoney() + num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you don't have that many to sell!");
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(name + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + name + "? (You have " + silkHeld + ")");
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= silkHeld && num >= 0) {
silkHeld -= num;
money += num * silkPrice;
if (num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld()-num);
player.setMoney(player.getMoney() + num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you don't have that many to sell!");
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(name + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + name + "? (You have " + armsHeld + ")");
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= armsHeld && num >= 0) {
armsHeld -= num;
money += num * armsPrice;
if (num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld()-num);
player.setMoney(player.getMoney() + num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you don't have that many to sell!");
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(name + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + name + "? (You have " + generalHeld + ")");
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= generalHeld && num >= 0) {
generalHeld -= num;
money += num * generalPrice;
if (num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()-num);
player.setMoney(player.getMoney() + num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you don't have that many to sell!");
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(name + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}
@@ -235,63 +227,63 @@ public class TaipanShop {
String response = input.next();
if (response.equalsIgnoreCase("B")) {
boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + name + "?");
System.out.println("What do you wish me to buy, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + name + "? (You can afford " + money / opiumPrice + ")");
System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= money / opiumPrice && num >= 0) {
opiumHeld += num;
money -= num * opiumPrice;
if (num <= player.getMoney() / opiumPrice && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()+num);
player.setMoney(player.getMoney() - num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you can't afford that!");
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(name + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I buy, " + name + "? (You can afford " + money / silkPrice + ")");
System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= money / silkPrice && num >= 0) {
silkHeld += num;
money -= num * silkPrice;
if (num <= player.getMoney() / silkPrice && num >= 0) {
player.setSilkHeld(player.getSilkHeld()+num);
player.setMoney(player.getMoney() - num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you can't afford that!");
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(name + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I buy, " + name + "? (You can afford " + money / armsPrice + ")");
System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= money / armsPrice && num >= 0) {
armsHeld += num;
money -= num * armsPrice;
if (num <= player.getMoney() / armsPrice && num >= 0) {
player.setArmsHeld(player.getArmsHeld()+num);
player.setMoney(player.getMoney() - num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you can't afford that!");
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(name + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I buy, " + name + "? (You can afford " + money / generalPrice + ")");
System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= money / generalPrice && num >= 0) {
generalHeld += num;
money -= num * generalPrice;
if (num <= player.getMoney() / generalPrice && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()+num);
player.setMoney(player.getMoney() - num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you can't afford that!");
System.out.println(player.getName() + ", you can't afford that!");
} else {
System.out.println(name + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?");
}
}
}
@@ -300,63 +292,63 @@ public class TaipanShop {
} else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + name + "?");
System.out.println("What do you wish me to sell, " + player.getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I sell, " + name + "? (You have " + opiumHeld + ")");
System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= opiumHeld && num >= 0) {
opiumHeld -= num;
money += num * opiumPrice;
if (num <= player.getOpiumHeld() && num >= 0) {
player.setOpiumHeld(player.getOpiumHeld()-num);
player.setMoney(player.getMoney() + num*opiumPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you don't have that many to sell!");
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(name + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?");
}
}
} else if (response.equalsIgnoreCase("S")) {
System.out.println("\nHow much Silk shall I sell, " + name + "? (You have " + silkHeld + ")");
System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= silkHeld && num >= 0) {
silkHeld -= num;
money += num * silkPrice;
if (num <= player.getSilkHeld() && num >= 0) {
player.setSilkHeld(player.getSilkHeld()-num);
player.setMoney(player.getMoney() + num*silkPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you don't have that many to sell!");
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(name + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?");
}
}
} else if (response.equalsIgnoreCase("A")) {
System.out.println("\nHow many Arms shall I sell, " + name + "? (You have " + armsHeld + ")");
System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= armsHeld && num >= 0) {
armsHeld -= num;
money += num * armsPrice;
if (num <= player.getArmsHeld() && num >= 0) {
player.setArmsHeld(player.getArmsHeld()-num);
player.setMoney(player.getMoney() + num*armsPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you don't have that many to sell!");
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(name + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?");
}
}
} else if (response.equalsIgnoreCase("G")) {
System.out.println("\nHow much General Cargo shall I sell, " + name + "? (You have " + generalHeld + ")");
System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= generalHeld && num >= 0) {
generalHeld -= num;
money += num * generalPrice;
if (num <= player.getGeneralHeld() && num >= 0) {
player.setGeneralHeld(player.getGeneralHeld()-num);
player.setMoney(player.getMoney() + num*generalPrice);
notDone2 = false;
} else if (num >= 0) {
System.out.println(name + ", you don't have that many to sell!");
System.out.println(player.getName() + ", you don't have that many to sell!");
} else {
System.out.println(name + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?");
}
}
}