Sloppy but completed ShipWarfare class

This commit is contained in:
KahootChampion
2019-02-21 23:44:30 -07:00
parent 3bd9f58fb1
commit f9435e7309
4 changed files with 394 additions and 328 deletions

124
.idea/workspace.xml generated
View File

@@ -3,9 +3,9 @@
<component name="ChangeListManager">
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment="">
<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/Player.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Player.java" 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" />
@@ -33,8 +33,8 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="99">
<caret line="7" column="33" selection-start-line="7" selection-start-column="33" selection-end-line="7" selection-end-column="33" />
<state relative-caret-position="-1419">
<caret line="12" column="30" selection-start-line="12" selection-start-column="30" selection-end-line="12" selection-end-column="30" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -42,10 +42,19 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Travel.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="265">
<caret line="66" column="1" lean-forward="true" selection-start-line="66" selection-start-column="1" selection-end-line="66" selection-end-column="1" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Bank.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="23">
<state relative-caret-position="30">
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
</state>
</provider>
@@ -54,29 +63,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="31">
<caret line="4" column="24" lean-forward="true" selection-start-line="4" selection-start-column="24" selection-end-line="4" selection-end-column="24" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-4123">
<caret line="111" column="85" selection-start-line="111" selection-start-column="81" selection-end-line="111" selection-end-column="85" />
<folding>
<element signature="e#333#334#0" expanded="true" />
<element signature="e#366#367#0" expanded="true" />
<element signature="e#535#536#0" expanded="true" />
<element signature="e#568#569#0" expanded="true" />
<element signature="e#736#737#0" expanded="true" />
<element signature="e#768#769#0" expanded="true" />
<element signature="e#931#932#0" expanded="true" />
<element signature="e#963#964#0" expanded="true" />
<element signature="e#1129#1130#0" expanded="true" />
<element signature="e#1164#1165#0" expanded="true" />
</folding>
<state relative-caret-position="148">
<caret line="10" column="24" selection-start-line="10" selection-start-column="24" selection-end-line="10" selection-end-column="24" />
</state>
</provider>
</entry>
@@ -92,9 +80,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>couldn</find>
<find>could</find>
<find>runFromShips</find>
<find>name</find>
<find>bank</find>
<find>player.getMoney() += num *</find>
@@ -115,6 +100,16 @@
<find>eek</find>
<find>setg</find>
<find>guns</find>
<find>duplic</find>
<find>chanceOfRun</find>
<find>chance</find>
<find>get</find>
<find>set</find>
<find>Peasant</find>
<find>d</find>
<find>captain</find>
<find>printf</find>
<find>setNum</find>
</findStrings>
<replaceStrings>
<replace>player.getName()</replace>
@@ -123,6 +118,11 @@
<replace>player.getOpiumHeld()</replace>
<replace>numOfPeasantShips</replace>
<replace>typeOfShip</replace>
<replace>chanceOfRun</replace>
<replace>litty</replace>
<replace>Liitty</replace>
<replace>Litty</replace>
<replace>%s</replace>
</replaceStrings>
</component>
<component name="Git.Settings">
@@ -132,8 +132,8 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/TaipanShop.java" />
<option value="$PROJECT_DIR$/src/Test.java" />
<option value="$PROJECT_DIR$/src/TaipanShop.java" />
<option value="$PROJECT_DIR$/src/Player.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" />
</list>
@@ -173,7 +173,8 @@
<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="1550810315089" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1550817767263" />
<property name="extract.method.default.visibility" value="public" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="project.structure.last.edited" value="Project" />
<property name="project.structure.proportion" value="0.15" />
@@ -263,7 +264,7 @@
<workItem from="1550550806467" duration="577000" />
<workItem from="1550552635138" duration="118000" />
<workItem from="1550553016386" duration="7671000" />
<workItem from="1550672213804" duration="20865000" />
<workItem from="1550672213804" duration="27182000" />
</task>
<task id="LOCAL-00001" summary="Added troll comments">
<created>1550458807806</created>
@@ -328,15 +329,21 @@
<option name="project" value="LOCAL" />
<updated>1550704064692</updated>
</task>
<option name="localTasksCounter" value="10" />
<task id="LOCAL-00010" summary="Added loot. Still need to have ships escape sometimes and Liu yen">
<created>1550810365166</created>
<option name="number" value="00010" />
<option name="presentableId" value="LOCAL-00010" />
<option name="project" value="LOCAL" />
<updated>1550810365166</updated>
</task>
<option name="localTasksCounter" value="11" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="29690000" />
<option name="totallyTimeSpent" value="36007000" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="23" width="1280" height="709" extended-state="0" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.2819063" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
@@ -347,7 +354,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.3273906" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.3273906" />
<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" />
@@ -384,7 +391,8 @@
<MESSAGE value="I think I got the basic battling system down. Would appreciate i some of you guys beta tested it though and let me know the errors if there are any." />
<MESSAGE value="Perhaps done basic ship warfare?" />
<MESSAGE value="Perhaps done basic ship warfare? (still must add Liu yen difficulty, ships running away, and Loot)" />
<option name="LAST_COMMIT_MESSAGE" value="Perhaps done basic ship warfare? (still must add Liu yen difficulty, ships running away, and Loot)" />
<MESSAGE value="Added loot. Still need to have ships escape sometimes and Liu yen" />
<option name="LAST_COMMIT_MESSAGE" value="Added loot. Still need to have ships escape sometimes and Liu yen" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/TaipanClone.iml">
@@ -393,13 +401,6 @@
<entry file="file://$PROJECT_DIR$/.idea/misc.xml">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/Travel.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" lean-forward="true" selection-start-line="2" selection-end-line="2" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Test.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
@@ -407,10 +408,24 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Bank.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Travel.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="265">
<caret line="66" column="1" lean-forward="true" selection-start-line="66" selection-start-column="1" selection-end-line="66" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-4123">
<caret line="111" column="85" selection-start-line="111" selection-start-column="81" selection-end-line="111" selection-end-column="85" />
<state relative-caret-position="173">
<caret line="137" lean-forward="true" selection-start-line="137" selection-end-line="137" />
<folding>
<element signature="e#333#334#0" expanded="true" />
<element signature="e#366#367#0" expanded="true" />
@@ -426,24 +441,17 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Bank.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="23">
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="31">
<caret line="4" column="24" lean-forward="true" selection-start-line="4" selection-start-column="24" selection-end-line="4" selection-end-column="24" />
<state relative-caret-position="148">
<caret line="10" column="24" selection-start-line="10" selection-start-column="24" selection-end-line="10" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="99">
<caret line="7" column="33" selection-start-line="7" selection-start-column="33" selection-end-line="7" selection-end-column="33" />
<state relative-caret-position="-1419">
<caret line="12" column="30" selection-start-line="12" selection-start-column="30" selection-end-line="12" selection-end-column="30" />
<folding>
<element signature="imports" expanded="true" />
</folding>

View File

@@ -8,7 +8,7 @@ public class Player {
private int generalHeld = 0;
private int armsHeld = 0;
private int location = 1;
private int guns = 1000;
private int guns = 3;
private int HP = 100;

View File

@@ -7,20 +7,25 @@ public class ShipWarfare extends Player {
private int numOfPeasantShips = 0;
private int numOfLittyShips = 0;
private boolean userAttacks = true;
private int startingShips=0;
private int startingPeasantShips = 0;
private int startingLittyShips =0;
private int howMuchRun = 0;
private String pirateName = "Liu Yen";
public void peasantFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in);
setNumOfPeasantShips(numOfShips());
System.out.printf("By Golly! We have $%,d and are being attacked by %d ships\nCurrently our ship status is %d%%\n", getMoney(), getNumOfPeasantShips(),getHP());
System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", getMoney(), numOfLittyShips, getHP());
fightOrRunMessage();
while (true) {
String response = userResponse.nextLine();
if (response.equalsIgnoreCase("f")) {
userAttacks = true;
System.out.println("Ohh, fight ehh?");
boolean winOrLose = destroyShipsOrEscape(getNumOfPeasantShips());
boolean winOrLose = destroyPeasantShipsOrEscape();
if (winOrLose == true) {
break;
}
@@ -29,7 +34,40 @@ public class ShipWarfare extends Player {
} else if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away!");
if(destroyShipsOrEscape(getNumOfPeasantShips()))
if (destroyPeasantShipsOrEscape())
break;
} else {
System.out.println("Phew! Got away safely");
break;
}
}
}
}
public void littyFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in);
setNumOfLittyShips(numOfShips());
System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", getMoney(), numOfLittyShips, pirateName, getHP());
fightOrRunMessage();
while (true) {
String response = userResponse.nextLine();
if (response.equalsIgnoreCase("f")) {
userAttacks = true;
System.out.println("Ohh, fight ehh?");
boolean winOrLose = destroyLittyShipsOrEscape();
if (winOrLose == true) {
break;
}
} else if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away!");
if (destroyLittyShipsOrEscape())
break;
} else {
System.out.println("Phew! Got away safely");
@@ -49,14 +87,20 @@ public class ShipWarfare extends Player {
}
public int getNumOfPeasantShips() {
public int numOfPeasantShips() {
return numOfPeasantShips;
}
public void setNumOfLittyShips(int numOfLittyShips) {
this.numOfLittyShips = numOfLittyShips;
startingLittyShips = numOfLittyShips;
}
public void setNumOfPeasantShips(int numOfPeasantShips) {
this.numOfPeasantShips = numOfPeasantShips;
startingShips = numOfPeasantShips;
startingPeasantShips = numOfPeasantShips;
}
@@ -100,12 +144,125 @@ public class ShipWarfare extends Player {
return false;
}
public boolean destroyShipsOrEscape(int typeOfShip) throws Exception {
public boolean destroyLittyShipsOrEscape() throws Exception {
int calculateLoot = 0;
int chanceOfEnemyRun = 0;
Scanner userInput = new Scanner(System.in);
Random randomValue = new Random();
int exitValue = 0;
//Player volley
while (exitValue == 0) {
for (int j = 0; j < getGuns(); j++) {
if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(3) + 1;
if (hitOrMiss == 1) {
numOfLittyShips--;
if (numOfLittyShips <= 0) {
exitValue = 1;
break;
}
System.out.println("Got eem");
delayForASecond();
} else if (hitOrMiss == 2) {
System.out.printf("ARRG! We missed %s\n", getName());
delayForASecond();
} else {
System.out.println("Darn! Their fleet tanked our attack");
delayForASecond();
}
} else {
continue;
}
}
if (numOfLittyShips <= 0) {
exitValue = 1;
break;
}
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
if (chanceOfEnemyRun == 2) {
howMuchRun = randomValue.nextInt(10) + 1;
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
setNumOfLittyShips(numOfLittyShips - howMuchRun);
if (userAttacks == true) {
System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, getName());
} else {
System.out.printf("Escaped %d of them!\n", howMuchRun);
}
}
}
System.out.printf("%d ships remaining\n", numOfLittyShips);
System.out.println("Oh no, they are taking the offensive!");
delayForASecond();
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && getGuns() > 0) {
setGuns(getGuns() - 1);
System.out.println("Dang it! They destroyed one of our guns");
} else {
setHP(getHP() - (1 + randomValue.nextInt(15)));
}
if (getHP() <= 0) {
exitValue = 2;
break;
}
System.out.printf("EEK, our current ship status is %d%% \n", getHP());
delayForASecond();
if (userAttacks == false) {
userAttacks = true;
}
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", getGuns());
String response = userInput.nextLine();
if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away");
} else {
exitValue = 3;
break;
}
}
}
if (exitValue == 1) {
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", getHP());
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
setMoney(getMoney() + calculateLoot);
System.out.printf("We got $%,d!\n", calculateLoot);
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());
return true;
}
return false;
}
public boolean destroyPeasantShipsOrEscape() throws Exception {
int calculateLoot = 0;
int chanceOfEnemyRun = 0;
Scanner userInput = new Scanner(System.in);
Random randomValue = new Random();
numOfPeasantShips = typeOfShip;
int exitValue = 0;
//Player volley
@@ -122,7 +279,7 @@ public class ShipWarfare extends Player {
System.out.println("Got eem");
delayForASecond();
} else {
System.out.println("ARRG! We missed captain");
System.out.printf("ARRG! We missed %s\n", getName());
delayForASecond();
}
@@ -137,8 +294,22 @@ public class ShipWarfare extends Player {
exitValue = 1;
break;
}
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
if (chanceOfEnemyRun == 2) {
howMuchRun = randomValue.nextInt(15) + 1;
if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) {
System.out.printf("%d ships remaining\n", getNumOfPeasantShips());
setNumOfPeasantShips(numOfPeasantShips - 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);
}
}
}
System.out.printf("%d ships remaining\n", numOfPeasantShips);
System.out.println("Oh no, they are taking the offensive!");
delayForASecond();
//Computer volley
@@ -159,7 +330,7 @@ public class ShipWarfare extends Player {
userAttacks = true;
}
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)", getGuns());
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();
if (response.equalsIgnoreCase("r")) {
@@ -177,7 +348,7 @@ public class ShipWarfare extends Player {
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());
calculateLoot= (randomValue.nextInt(startingShips) + startingShips) *100;
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
setMoney(getMoney() + calculateLoot);
System.out.printf("We got $%,d!", calculateLoot);
return true;
@@ -192,12 +363,11 @@ public class ShipWarfare extends Player {
}
//Type of ship implied to be Liu Yen fleet
public static void main(String[] args) throws Exception {
ShipWarfare littyObject = new ShipWarfare();
littyObject.peasantFleetAttack();
littyObject.littyFleetAttack();
}
}

View File

@@ -131,134 +131,10 @@ public class TaipanShop extends Player {
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, " + getName() + "?");
while (notDone2) {
response = input.nextLine();
if (response.equalsIgnoreCase("O")) {
System.out.println("\nHow much Opium shall I buy, " + getName() + "? (You can afford " + getMoney() / opiumPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() / opiumPrice && num >= 0) {
setOpiumHeld(getOpiumHeld()+num);
setMoney(getMoney()-num * opiumPrice);
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() / silkPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() / silkPrice && num >= 0) {
setSilkHeld(getSilkHeld()+num);
setMoney(getMoney()-num * silkPrice);
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() / armsPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() / armsPrice && num >= 0) {
setArmsHeld(getArmsHeld()+num);
setMoney(getMoney() - num*armsPrice);
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() / generalPrice + ")");
while (notDone2) {
int num = input.nextInt();
if (num <= getMoney() / generalPrice && num >= 0) {
setGeneralHeld(getGeneralHeld()+num);
setMoney(getMoney() - num*generalPrice);
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?");
}
}
}
}
ayyy(input);
} else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + getName() + "?");
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*opiumPrice);
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*silkPrice);
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*armsPrice);
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*generalPrice);
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?");
}
}
}
}
duplicateLittiness(input);
} else if (response.equalsIgnoreCase("V")) {
System.out.println("\n*** PLACEHOLDER FOR BANK ***\n");
@@ -275,6 +151,88 @@ public class TaipanShop extends Player {
System.out.println("\nShall I Buy, Sell, or Quit Trading?");
String response = input.next();
if (response.equalsIgnoreCase("B")) {
ayyy(input);
} else if (response.equalsIgnoreCase("S")) {
duplicateLittiness(input);
} else if (response.equalsIgnoreCase("Q")) {
System.out.println("\n*** PLACEHOLDER FOR TRAVEL ***\n");
notDone = false;
}
}
}
}
public void duplicateLittiness(Scanner input) {
String response;
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + getName() + "?");
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*opiumPrice);
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*silkPrice);
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*armsPrice);
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*generalPrice);
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?");
}
}
}
}
}
public void ayyy(Scanner input) {
String response;
boolean notDone2 = true;
System.out.println("What do you wish me to buy, " + getName() + "?");
while (notDone2) {
@@ -338,78 +296,8 @@ public class TaipanShop extends Player {
}
}
} else if (response.equalsIgnoreCase("S")) {
boolean notDone2 = true;
System.out.println("What do you wish me to sell, " + getName() + "?");
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*opiumPrice);
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*silkPrice);
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*armsPrice);
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*generalPrice);
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?");
}
}
}
}
} else if (response.equalsIgnoreCase("Q")) {
System.out.println("\n*** PLACEHOLDER FOR TRAVEL ***\n");
notDone = false;
}
}
}
}
public static void main(String[] args){
TaipanShop shop = new TaipanShop();
shop.shop();