Added retreat option (not perfected)

This commit is contained in:
KahootChampion
2019-02-18 18:32:56 -07:00
parent 1a06ba4c0e
commit 5c41bf5b7c
3 changed files with 145 additions and 268 deletions

263
.idea/workspace.xml generated
View File

@@ -3,7 +3,8 @@
<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$/src/Player.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Player.java" 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" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -14,31 +15,20 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<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="204">
<caret line="12" lean-forward="true" selection-start-line="12" selection-end-line="12" />
<state relative-caret-position="88">
<caret line="10" lean-forward="true" selection-start-line="10" selection-end-line="10" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1497#1498#0" expanded="true" />
<element signature="e#1525#1526#0" expanded="true" />
<element signature="e#1553#1554#0" expanded="true" />
<element signature="e#1580#1581#0" expanded="true" />
<element signature="e#1606#1607#0" expanded="true" />
<element signature="e#1631#1632#0" expanded="true" />
<element signature="e#1672#1673#0" expanded="true" />
<element signature="e#1712#1713#0" expanded="true" />
<element signature="e#1813#1814#0" expanded="true" />
<element signature="e#1847#1848#0" expanded="true" />
<element signature="e#1884#1885#0" expanded="true" />
<element signature="e#1916#1917#0" expanded="true" />
<element signature="e#1979#1980#0" expanded="true" />
<element signature="e#2037#2038#0" expanded="true" />
<element signature="method#gameOver#0;class#ShipWarfare#0" />
<element signature="method#numOfShips#0;class#ShipWarfare#0" />
<element signature="method#fightShips#0;class#ShipWarfare#0" />
<element signature="method#main#0;class#ShipWarfare#0" />
<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>
@@ -47,8 +37,8 @@
<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="306">
<caret line="18" column="25" selection-start-line="18" selection-start-column="25" selection-end-line="18" selection-end-column="25" />
<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" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -56,64 +46,9 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="194">
<caret line="78" column="24" lean-forward="true" selection-start-line="78" selection-start-column="24" selection-end-line="78" selection-end-column="24" />
<folding>
<element signature="e#321#322#0" expanded="true" />
<element signature="e#348#349#0" expanded="true" />
<element signature="e#388#389#0" expanded="true" />
<element signature="e#420#421#0" expanded="true" />
<element signature="e#343#344#0" expanded="true" />
<element signature="e#368#369#0" expanded="true" />
<element signature="e#401#402#0" expanded="true" />
<element signature="e#424#425#0" expanded="true" />
<element signature="e#448#449#0" expanded="true" />
<element signature="e#475#476#0" expanded="true" />
<element signature="e#512#513#0" expanded="true" />
<element signature="e#544#545#0" expanded="true" />
<element signature="e#573#574#0" expanded="true" />
<element signature="e#601#602#0" expanded="true" />
<element signature="e#640#641#0" expanded="true" />
<element signature="e#674#675#0" expanded="true" />
<element signature="e#707#708#0" expanded="true" />
<element signature="e#739#740#0" expanded="true" />
<element signature="e#786#787#0" expanded="true" />
<element signature="e#828#829#0" expanded="true" />
<element signature="e#860#861#0" expanded="true" />
<element signature="e#891#892#0" expanded="true" />
<element signature="e#936#937#0" expanded="true" />
<element signature="e#976#977#0" expanded="true" />
<element signature="e#1011#1012#0" expanded="true" />
<element signature="e#1045#1046#0" expanded="true" />
<element signature="e#1096#1097#0" expanded="true" />
<element signature="e#1142#1143#0" expanded="true" />
<element signature="e#1174#1175#0" expanded="true" />
<element signature="e#1205#1206#0" expanded="true" />
<element signature="e#1250#1251#0" expanded="true" />
<element signature="e#1290#1291#0" expanded="true" />
<element signature="e#1322#1323#0" expanded="true" />
<element signature="e#1353#1354#0" expanded="true" />
<element signature="e#1398#1399#0" expanded="true" />
<element signature="e#1438#1439#0" expanded="true" />
<element signature="e#1466#1467#0" expanded="true" />
<element signature="e#1493#1494#0" expanded="true" />
<element signature="e#1530#1531#0" expanded="true" />
<element signature="e#1562#1563#0" expanded="true" />
</folding>
</state>
</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>
<caret column="21" selection-start-column="21" selection-end-column="21" />
</state>
</provider>
<entry file="file://$PROJECT_DIR$/TaipanClone.iml">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
</leaf>
@@ -127,7 +62,9 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>Hp</find>
<find>couldn</find>
<find>could</find>
<find>runFromShips</find>
</findStrings>
</component>
<component name="Git.Settings">
@@ -137,27 +74,21 @@
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/TaipanShop.java" />
<option value="$PROJECT_DIR$/src/Core.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" />
<option value="$PROJECT_DIR$/src/Player.java" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-7" />
<option name="width" value="854" />
<option name="height" value="1017" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
<component name="ProjectFrameBounds">
<option name="y" value="23" />
<option name="width" value="1280" />
<option name="height" value="709" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="PackagesPane" />
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@@ -174,15 +105,15 @@
<select />
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="ChangesTree.GroupingKeys" value="" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1550541286814" />
<property name="extract.method.default.visibility" value="private" />
<property name="last_opened_file_path" value="$USER_HOME$/Documents/GitHub/Cpsc233" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1550458702863" />
<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" />
<property name="project.structure.side.proportion" value="0.2" />
@@ -230,7 +161,7 @@
</recent_temporary>
</component>
<component name="SvnConfiguration" cleanupOnStartRun="true">
<configuration>C:\Users\Harkamal Randhawa\AppData\Roaming\Subversion</configuration>
<configuration>$USER_HOME$/.subversion</configuration>
<supportedVersion>125</supportedVersion>
</component>
<component name="TaskManager">
@@ -241,43 +172,25 @@
<option name="presentableId" value="Default" />
<updated>1550454898506</updated>
<workItem from="1550454902781" duration="459000" />
<workItem from="1550458230268" duration="571000" />
<workItem from="1550459021117" duration="128000" />
<workItem from="1550459458251" duration="1743000" />
<workItem from="1550538713935" duration="2576000" />
</task>
<task id="LOCAL-00001" summary="This should fix the ShipWarfare file and bring it up to date with the rest of the file.">
<created>1550458470138</created>
<task id="LOCAL-00001" summary="Added troll comments">
<created>1550458807806</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1550458470138</updated>
<updated>1550458807807</updated>
</task>
<task id="LOCAL-00002" summary="Created Core class">
<created>1550540282400</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1550540282400</updated>
</task>
<task id="LOCAL-00003" summary="Created Player class">
<created>1550540820542</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1550540820542</updated>
</task>
<option name="localTasksCounter" value="4" />
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="5477000" />
<option name="totallyTimeSpent" value="459000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1696" height="1026" extended-state="6" />
<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.15770172" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25767368" />
<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" />
@@ -286,17 +199,17 @@
<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.32922733" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32901135" />
<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" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info active="true" anchor="bottom" id="Version Control" order="8" sideWeight="0.49938875" visible="true" weight="0.32922733" />
<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="Event Log" order="11" sideWeight="0.50061125" side_tool="true" visible="true" weight="0.32922733" />
<window_info anchor="bottom" id="Messages" order="12" />
<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" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@@ -316,23 +229,17 @@
<path value="$PROJECT_DIR$" />
</ignored-roots>
<MESSAGE value="This should fix the project repository once and for all." />
<MESSAGE value="This should fix the ShipWarfare file and bring it up to date with the rest of the file." />
<MESSAGE value="Created Core class" />
<MESSAGE value="Created Player class" />
<option name="LAST_COMMIT_MESSAGE" value="Created Player class" />
<MESSAGE value="Added troll comments" />
<option name="LAST_COMMIT_MESSAGE" value="Added troll comments" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/Travel.java">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="21" selection-start-column="21" selection-end-column="21" />
</state>
</provider>
<entry file="file://$PROJECT_DIR$/TaipanClone.iml">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/TaipanShop.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="18" column="25" selection-start-line="18" selection-start-column="25" selection-end-line="18" selection-end-column="25" />
<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" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -341,77 +248,17 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="12" lean-forward="true" selection-start-line="12" selection-end-line="12" />
<state relative-caret-position="88">
<caret line="10" lean-forward="true" selection-start-line="10" selection-end-line="10" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1497#1498#0" expanded="true" />
<element signature="e#1525#1526#0" expanded="true" />
<element signature="e#1553#1554#0" expanded="true" />
<element signature="e#1580#1581#0" expanded="true" />
<element signature="e#1606#1607#0" expanded="true" />
<element signature="e#1631#1632#0" expanded="true" />
<element signature="e#1672#1673#0" expanded="true" />
<element signature="e#1712#1713#0" expanded="true" />
<element signature="e#1813#1814#0" expanded="true" />
<element signature="e#1847#1848#0" expanded="true" />
<element signature="e#1884#1885#0" expanded="true" />
<element signature="e#1916#1917#0" expanded="true" />
<element signature="e#1979#1980#0" expanded="true" />
<element signature="e#2037#2038#0" expanded="true" />
<element signature="method#gameOver#0;class#ShipWarfare#0" />
<element signature="method#numOfShips#0;class#ShipWarfare#0" />
<element signature="method#fightShips#0;class#ShipWarfare#0" />
<element signature="method#main#0;class#ShipWarfare#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Player.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="194">
<caret line="78" column="24" lean-forward="true" selection-start-line="78" selection-start-column="24" selection-end-line="78" selection-end-column="24" />
<folding>
<element signature="e#321#322#0" expanded="true" />
<element signature="e#348#349#0" expanded="true" />
<element signature="e#388#389#0" expanded="true" />
<element signature="e#420#421#0" expanded="true" />
<element signature="e#343#344#0" expanded="true" />
<element signature="e#368#369#0" expanded="true" />
<element signature="e#401#402#0" expanded="true" />
<element signature="e#424#425#0" expanded="true" />
<element signature="e#448#449#0" expanded="true" />
<element signature="e#475#476#0" expanded="true" />
<element signature="e#512#513#0" expanded="true" />
<element signature="e#544#545#0" expanded="true" />
<element signature="e#573#574#0" expanded="true" />
<element signature="e#601#602#0" expanded="true" />
<element signature="e#640#641#0" expanded="true" />
<element signature="e#674#675#0" expanded="true" />
<element signature="e#707#708#0" expanded="true" />
<element signature="e#739#740#0" expanded="true" />
<element signature="e#786#787#0" expanded="true" />
<element signature="e#828#829#0" expanded="true" />
<element signature="e#860#861#0" expanded="true" />
<element signature="e#891#892#0" expanded="true" />
<element signature="e#936#937#0" expanded="true" />
<element signature="e#976#977#0" expanded="true" />
<element signature="e#1011#1012#0" expanded="true" />
<element signature="e#1045#1046#0" expanded="true" />
<element signature="e#1096#1097#0" expanded="true" />
<element signature="e#1142#1143#0" expanded="true" />
<element signature="e#1174#1175#0" expanded="true" />
<element signature="e#1205#1206#0" expanded="true" />
<element signature="e#1250#1251#0" expanded="true" />
<element signature="e#1290#1291#0" expanded="true" />
<element signature="e#1322#1323#0" expanded="true" />
<element signature="e#1353#1354#0" expanded="true" />
<element signature="e#1398#1399#0" expanded="true" />
<element signature="e#1438#1439#0" expanded="true" />
<element signature="e#1466#1467#0" expanded="true" />
<element signature="e#1493#1494#0" expanded="true" />
<element signature="e#1530#1531#0" expanded="true" />
<element signature="e#1562#1563#0" 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>

Binary file not shown.

View File

@@ -1,44 +1,45 @@
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Random;
import java.util.concurrent.TimeUnit;
public class ShipWarfare {
private int money = 100000000;
private int money = 0;
private int guns = 3;
private int hp = 100;
private int numOfPeasantShips= 0;
private int numOfPeasantShips = 0;
public void peasantFleetAttack() throws Exception{
public void peasantFleetAttack() throws Exception {
Scanner userResponse = new Scanner(System.in);
setNumOfPeasantShips(numOfShips());
System.out.printf("By Golly! We have $%,d \nwe are being attacked by %d ships\n", getMoney(), getNumOfPeasantShips());
System.out.println("What do you want to do? Press \"f\" to fight, and \"r\" to run ");
while(true) {
try {
System.out.println("What do you want to do? Enter \"f\" to fight, and \"r\" to run ");
while (true) {
String response = userResponse.nextLine();
if (response.equalsIgnoreCase("f")) {
System.out.println("Ohh, fight ehh?");
fightShips(getNumOfPeasantShips());
}
else if(response.equalsIgnoreCase("r")){
System.out.println("Harkey G is dumb boiiiiiiiii");
}
} catch (InputMismatchException e) {
String response;
System.out.println("Sorry, that is not an acceptable input please try again");
response = userResponse.nextLine();
if (response.equalsIgnoreCase("f") || response.equalsIgnoreCase("r"))
boolean winOrLose= destroyShipsOrEscape(getNumOfPeasantShips());
if(winOrLose==true){
break;
}
} else if (response.equalsIgnoreCase("r")) {
runFromShips();
if(runFromShips()==true){
break;
}
}
}
}
public int getMoney() {
return money;
}
@@ -76,32 +77,26 @@ public class ShipWarfare {
TimeUnit.SECONDS.sleep(1);
}
public void gameOver(){
public void gameOver() {
System.out.flush();
System.out.println("Game over");
}
public int numOfShips(){
public int numOfShips() {
int numOfShipsAttacking = 0;
Random randomValue = new Random();
if (getMoney() <= 100000){
if (getMoney() <= 100000) {
//Minimum one ship will attack, maximum 20
numOfShipsAttacking = randomValue.nextInt(20) + 1;
}
else if (getMoney() <= 200000){
} else if (getMoney() <= 200000) {
//Minimum 30 Ships will attack, maximum 70
numOfShipsAttacking = randomValue.nextInt(40) + 30;
}
else if (getMoney() <= 500000){
} else if (getMoney() <= 500000) {
//Minimum 50 ships will attack, maximum 140
numOfShipsAttacking = randomValue.nextInt(90) + 50;
}
else if (getMoney() > 1000000){
} else if (getMoney() > 1000000) {
//Minimum 100 ships will attack, maximum 300 ships
numOfShipsAttacking = randomValue.nextInt(3) + 100;
}
@@ -110,19 +105,29 @@ public class ShipWarfare {
}
public boolean runFromShips() {
Random randomValue = new Random();
int runSuccessChance = randomValue.nextInt(2) + 1;
if (runSuccessChance == 2) {
return true;
} else if (runSuccessChance == 1) {
System.out.println("Couldn't run away");
return false;
}
return false;
}
public void fightShips(int typeOfShip) throws Exception {
public boolean destroyShipsOrEscape(int typeOfShip) throws Exception {
Scanner userInput = new Scanner(System.in);
Random randomValue = new Random();
int shipsRemaining = typeOfShip;
int exitValue=0;
if(typeOfShip==getNumOfPeasantShips()) {
if (exitValue == 0) {
//Player volley
while (exitValue==0){
while (exitValue == 0) {
for (int i = 0; i < shipsRemaining; i++) {
if (exitValue == 0) {
for (int j = 0; j < getGuns(); j++) {
int hitOrMiss = randomValue.nextInt(2) + 1;
if (hitOrMiss == 2) {
@@ -140,6 +145,7 @@ public class ShipWarfare {
}
}
if (shipsRemaining <= 0) {
exitValue = 1;
@@ -151,28 +157,52 @@ public class ShipWarfare {
delayForASecond();
//Computer volley
setHp(getHp() - randomValue.nextInt(10));
if(getHp()<=0){
exitValue=2;
if (getHp() <= 0) {
exitValue = 2;
break;
}
System.out.printf("EEK, we have %d health left\n", getHp());
delayForASecond();
System.out.println("Shall we continue the offensive? Enter \"f\" to fight, and \"r\" to run");
String response = userInput.nextLine();
if (response.equalsIgnoreCase("r")) {
runFromShips();
if (runFromShips() == false) {
exitValue = 6;
} else {
exitValue = 3;
break;
}
}
if(exitValue==1) {
System.out.printf("Got eem!\nIt appears we have defeated the enemy fleet and made it out at %d health\n", hp);
}
else if(exitValue==2){
if (runFromShips() == true) {
break;
}
}
if (exitValue == 1) {
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d health\n", hp);
return true;
} else if (exitValue == 2) {
gameOver();
return true;
} else if (exitValue == 3) {
System.out.println("We made it");
return true;
}
return false;
}
//Type of ship implied to be Liu Yen fleet
else{
else {
}
return false;
}
public static void main(String[] args) throws Exception {