Super broken but fight button is in progress for shipwarfare

This commit is contained in:
KahootChampion
2019-03-09 22:32:45 -07:00
parent 80102eabee
commit 1bb00d0d01
3 changed files with 175 additions and 174 deletions

95
.idea/workspace.xml generated
View File

@@ -3,6 +3,8 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3114a2b9-4919-4fdf-8fd9-d03b60109ce4" name="Default Changelist" comment=""> <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$/.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/ShipWarfareGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ShipWarfareGUI.java" afterDir="false" />
</list> </list>
<ignored path="$PROJECT_DIR$/out/" /> <ignored path="$PROJECT_DIR$/out/" />
<ignored path="C:\Users\Harkamal Randhawa\IdeaProjects\TaipanClone\.idea\shelf/" /> <ignored path="C:\Users\Harkamal Randhawa\IdeaProjects\TaipanClone\.idea\shelf/" />
@@ -27,21 +29,21 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java"> <entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2580"> <state relative-caret-position="135">
<caret line="172" column="5" selection-start-line="172" selection-start-column="5" selection-end-line="172" selection-end-column="5" /> <caret line="399" column="97" selection-start-line="399" selection-start-column="92" selection-end-line="399" selection-end-column="97" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#1150#1151#0" expanded="true" /> <element signature="e#1208#1209#0" expanded="true" />
<element signature="e#1178#1179#0" expanded="true" /> <element signature="e#1236#1237#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main.java"> <entry file="file://$PROJECT_DIR$/src/main.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135"> <state relative-caret-position="135">
@@ -84,10 +86,6 @@
</component> </component>
<component name="FindInProjectRecents"> <component name="FindInProjectRecents">
<findStrings> <findStrings>
<find>GetGuns</find>
<find>set</find>
<find>TaipanShop</find>
<find>shop()</find>
<find>shop</find> <find>shop</find>
<find>being</find> <find>being</find>
<find>label0</find> <find>label0</find>
@@ -100,7 +98,6 @@
<find>setNumOfP</find> <find>setNumOfP</find>
<find>setUs</find> <find>setUs</find>
<find>starting</find> <find>starting</find>
<find>destro</find>
<find>numOfpeasantShips</find> <find>numOfpeasantShips</find>
<find>startingPeasantShips</find> <find>startingPeasantShips</find>
<find>startingLittyShips</find> <find>startingLittyShips</find>
@@ -114,6 +111,11 @@
<find>numOfLittyShips</find> <find>numOfLittyShips</find>
<find>delay</find> <find>delay</find>
<find>Hp</find> <find>Hp</find>
<find>shipwarfare</find>
<find>destroyPeasa</find>
<find>destr</find>
<find>destro</find>
<find>hitco</find>
</findStrings> </findStrings>
<replaceStrings> <replaceStrings>
<replace>HP</replace> <replace>HP</replace>
@@ -137,9 +139,9 @@
<option value="$PROJECT_DIR$/src/TaipanShop.java" /> <option value="$PROJECT_DIR$/src/TaipanShop.java" />
<option value="$PROJECT_DIR$/src/main.java" /> <option value="$PROJECT_DIR$/src/main.java" />
<option value="$PROJECT_DIR$/src/Travel.java" /> <option value="$PROJECT_DIR$/src/Travel.java" />
<option value="$PROJECT_DIR$/src/ShipWarfareGUI.java" />
<option value="$PROJECT_DIR$/src/Player.java" /> <option value="$PROJECT_DIR$/src/Player.java" />
<option value="$PROJECT_DIR$/src/ShipWarfare.java" /> <option value="$PROJECT_DIR$/src/ShipWarfare.java" />
<option value="$PROJECT_DIR$/src/ShipWarfareGUI.java" />
</list> </list>
</option> </option>
</component> </component>
@@ -155,7 +157,6 @@
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes>
<pane id="Scope" />
<pane id="ProjectPane"> <pane id="ProjectPane">
<subPane> <subPane>
<expand> <expand>
@@ -172,6 +173,7 @@
<select /> <select />
</subPane> </subPane>
</pane> </pane>
<pane id="Scope" />
<pane id="PackagesPane" /> <pane id="PackagesPane" />
</panes> </panes>
</component> </component>
@@ -179,7 +181,7 @@
<property name="ChangesTree.GroupingKeys" value="" /> <property name="ChangesTree.GroupingKeys" value="" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" /> <property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1552182988336" /> <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1552187991754" />
<property name="extract.method.default.visibility" value="private" /> <property name="extract.method.default.visibility" value="private" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../GitHub/Cpsc233" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/../GitHub/Cpsc233" />
<property name="project.structure.last.edited" value="Project" /> <property name="project.structure.last.edited" value="Project" />
@@ -199,7 +201,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="RunManager" selected="Application.main"> <component name="RunManager" selected="Application.ShipWarfareGUI">
<configuration name="Game" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="Game" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Game" /> <option name="MAIN_CLASS_NAME" value="Game" />
<module name="TaipanClone" /> <module name="TaipanClone" />
@@ -244,8 +246,8 @@
</list> </list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Application.main" />
<item itemvalue="Application.ShipWarfareGUI" /> <item itemvalue="Application.ShipWarfareGUI" />
<item itemvalue="Application.main" />
<item itemvalue="Application.TaipanShop" /> <item itemvalue="Application.TaipanShop" />
<item itemvalue="Application.Game" /> <item itemvalue="Application.Game" />
<item itemvalue="Application.ShipWarfare" /> <item itemvalue="Application.ShipWarfare" />
@@ -279,6 +281,8 @@
<workItem from="1552183247090" duration="42000" /> <workItem from="1552183247090" duration="42000" />
<workItem from="1552183350012" duration="132000" /> <workItem from="1552183350012" duration="132000" />
<workItem from="1552183501892" duration="5000" /> <workItem from="1552183501892" duration="5000" />
<workItem from="1552187010251" duration="1043000" />
<workItem from="1552195875453" duration="55000" />
</task> </task>
<task id="LOCAL-00001" summary="This should fix the ShipWarfare file and bring it up to date with the rest of the file."> <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> <created>1550458470138</created>
@@ -399,17 +403,24 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1552181667376</updated> <updated>1552181667376</updated>
</task> </task>
<option name="localTasksCounter" value="18" /> <task id="LOCAL-00018" summary="Please find error">
<created>1552187032139</created>
<option name="number" value="00018" />
<option name="presentableId" value="LOCAL-00018" />
<option name="project" value="LOCAL" />
<updated>1552187032139</updated>
</task>
<option name="localTasksCounter" value="19" />
<servers /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="57306000" /> <option name="totallyTimeSpent" value="58404000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="48" y="23" width="1189" height="652" extended-state="0" /> <frame x="48" y="23" width="1189" height="652" extended-state="0" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.21621622" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.22319093" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Image Layers" order="2" /> <window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" /> <window_info id="Designer" order="3" />
@@ -418,7 +429,7 @@
<window_info id="Favorites" order="6" side_tool="true" /> <window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32922733" /> <window_info anchor="bottom" id="Find" order="1" weight="0.32922733" />
<window_info anchor="bottom" id="Run" order="2" weight="0.4482143" /> <window_info anchor="bottom" id="Run" order="2" weight="0.9357143" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" /> <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="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -524,7 +535,8 @@
<MESSAGE value="Made ShipWarfare easier to access by ShipWarfareGUI" /> <MESSAGE value="Made ShipWarfare easier to access by ShipWarfareGUI" />
<MESSAGE value="Missed one statement that I needed to encapsulate" /> <MESSAGE value="Missed one statement that I needed to encapsulate" />
<MESSAGE value="Messed up player by setting money to 1000" /> <MESSAGE value="Messed up player by setting money to 1000" />
<option name="LAST_COMMIT_MESSAGE" value="Messed up player by setting money to 1000" /> <MESSAGE value="Please find error" />
<option name="LAST_COMMIT_MESSAGE" value="Please find error" />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="uml://JAVA/ShipWarfare"> <entry file="uml://JAVA/ShipWarfare">
@@ -579,6 +591,13 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="jar:///Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/javafx-src.zip!/com/sun/glass/ui/InvokeLaterDispatcher.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="140">
<caret line="110" column="19" selection-start-line="110" selection-start-column="19" selection-end-line="110" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfare.java"> <entry file="file://$PROJECT_DIR$/src/ShipWarfare.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="5025"> <state relative-caret-position="5025">
@@ -589,15 +608,17 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java"> <entry file="file://$PROJECT_DIR$/src/main.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2580"> <state relative-caret-position="135">
<caret line="172" column="5" selection-start-line="172" selection-start-column="5" selection-end-line="172" selection-end-column="5" /> <caret line="9" column="4" selection-end-line="55" />
<folding> </state>
<element signature="imports" expanded="true" /> </provider>
<element signature="e#1150#1151#0" expanded="true" /> </entry>
<element signature="e#1178#1179#0" expanded="true" /> <entry file="file://$PROJECT_DIR$/src/Start.java">
</folding> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="1" column="13" selection-start-line="1" selection-start-column="13" selection-end-line="1" selection-end-column="13" />
</state> </state>
</provider> </provider>
</entry> </entry>
@@ -611,17 +632,15 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/Start.java"> <entry file="file://$PROJECT_DIR$/src/ShipWarfareGUI.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="1" column="13" selection-start-line="1" selection-start-column="13" selection-end-line="1" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135"> <state relative-caret-position="135">
<caret line="9" column="4" selection-end-line="55" /> <caret line="399" column="97" selection-start-line="399" selection-start-column="92" selection-end-line="399" selection-end-column="97" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1208#1209#0" expanded="true" />
<element signature="e#1236#1237#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>

View File

@@ -29,16 +29,22 @@ import static javafx.application.Application.launch;
public class ShipWarfareGUI extends Application { public class ShipWarfareGUI extends Application {
private Player player = new Player(); private Player player = new Player();
private ShipWarfare shipWarfare = new ShipWarfare(player); private ShipWarfare shipWarfare = new ShipWarfare(player);
private HBox hBox; private HBox hBox;
private Button button1; private Button fightButton;
private Button button2; private Button runButton;
private VBox vBox; private VBox vBox;
private Label label1; private Label title;
private Label label; private Label chooseFightOrRun;
private VBox vBox0; private Label report;
private Label label0; private Label runAwayOrLeft;
private Label shipsRemaining;
private Label HPLeft;
private Label gunsLeftOrTaken;
private Label continueToFight;
public static void main(String args[]) { public static void main(String args[]) {
@@ -53,14 +59,6 @@ public class ShipWarfareGUI extends Application {
private int howMuchRun = 0; private int howMuchRun = 0;
private String pirateName = "Liu Yen"; private String pirateName = "Liu Yen";
/**
* Class Constructor that takes in a type player as a parameter
* @param player object of the class Player
*/
public ShipWarfareGUI(Player player) {
Player playerDummy = new Player(player);
this.player = playerDummy;
}
/** /**
* setter method for player * setter method for player
@@ -88,15 +86,13 @@ public class ShipWarfareGUI extends Application {
Scanner userResponse = new Scanner(System.in); Scanner userResponse = new Scanner(System.in);
setNumOfPeasantShips(numOfShips()); setNumOfPeasantShips(numOfShips());
System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfPeasantShips, player.getHP()); title.setText(String.format("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfPeasantShips, player.getHP()));
fightOrRunMessage(); fightOrRunMessage();
while (true) { while (true) {
String response = userResponse.nextLine(); String response = userResponse.nextLine();
if (response.equalsIgnoreCase("f")) { if (response.equalsIgnoreCase("f")) {
userAttacks = true; userAttacks = true;
System.out.println("Ohh, fight ehh?"); System.out.println("Ohh, fight ehh?");
delayForSeconds(1);
boolean winOrLose = destroyPeasantShipsOrEscape(); boolean winOrLose = destroyPeasantShipsOrEscape();
if (winOrLose == true) { if (winOrLose == true) {
break; break;
@@ -147,7 +143,6 @@ public class ShipWarfareGUI extends Application {
break; break;
} else { } else {
System.out.println("Phew! Got away safely"); System.out.println("Phew! Got away safely");
delayForSeconds(2);
break; break;
} }
@@ -263,13 +258,10 @@ public class ShipWarfareGUI extends Application {
break; break;
} }
System.out.println("Got eem"); System.out.println("Got eem");
delayForSeconds(1);
} else if (hitOrMiss == 2) { } else if (hitOrMiss == 2) {
System.out.printf("ARRG! We missed %s\n", player.getName()); System.out.printf("ARRG! We missed %s\n", player.getName());
delayForSeconds(1);
} else { } else {
System.out.println("Darn! Their fleet tanked our attack"); System.out.println("Darn! Their fleet tanked our attack");
delayForSeconds(1);
} }
@@ -279,7 +271,6 @@ public class ShipWarfareGUI extends Application {
} }
} else { } else {
System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName()); System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName());
delayForSeconds(1);
} }
@@ -306,7 +297,6 @@ public class ShipWarfareGUI extends Application {
System.out.printf("%d ships remaining\n", numOfLittyShips); System.out.printf("%d ships remaining\n", numOfLittyShips);
System.out.println("Oh no, they are taking the offensive!"); System.out.println("Oh no, they are taking the offensive!");
delayForSeconds(1);
//Computer volley //Computer volley
int takeGunChance = randomValue.nextInt(4) + 1; int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && player.getGuns() > 0) { if (takeGunChance == 1 && player.getGuns() > 0) {
@@ -320,7 +310,6 @@ public class ShipWarfareGUI extends Application {
break; break;
} }
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
delayForSeconds(1);
if (userAttacks == false) { if (userAttacks == false) {
userAttacks = true; userAttacks = true;
} }
@@ -331,10 +320,8 @@ public class ShipWarfareGUI extends Application {
if (response.equalsIgnoreCase("r")) { if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) { if (runFromShips() == false) {
System.out.println("Couldn't run away"); System.out.println("Couldn't run away");
delayForSeconds(1);
} else { } else {
System.out.println("Phew! Got away safely"); System.out.println("Phew! Got away safely");
delayForSeconds(2);
break; break;
} }
} }
@@ -345,11 +332,9 @@ public class ShipWarfareGUI extends Application {
if (exitValue == 1) { 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", player.getHP()); System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
delayForSeconds(1);
calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300; calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300;
player.setMoney(player.getMoney() + calculateLoot); player.setMoney(player.getMoney() + calculateLoot);
System.out.printf("We got $%,d!\n", calculateLoot); System.out.printf("We got $%,d!\n", calculateLoot);
delayForSeconds(2);
return true; return true;
} else if (exitValue == 2) { } else if (exitValue == 2) {
player.gameOver(); player.gameOver();
@@ -357,7 +342,6 @@ public class ShipWarfareGUI extends Application {
return true; return true;
} else if (exitValue == 3) { } else if (exitValue == 3) {
System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
delayForSeconds(2);
return true; return true;
} }
return false; return false;
@@ -371,11 +355,23 @@ public class ShipWarfareGUI extends Application {
* @throws Exception in case of errors due to the delay * @throws Exception in case of errors due to the delay
*/ */
public void wipe(){
title.setVisible(false);
runAwayOrLeft.setVisible(false);
shipsRemaining.setVisible(false);
HPLeft.setVisible(false);
gunsLeftOrTaken.setVisible(false);
continueToFight.setVisible(false);
}
public boolean destroyPeasantShipsOrEscape() throws Exception { public boolean destroyPeasantShipsOrEscape() throws Exception {
int calculateLoot = 0; int calculateLoot = 0;
int chanceOfEnemyRun = 0; int chanceOfEnemyRun = 0;
int hitCounter=0; int hitCounter=0;
int missCounter=0; int missCounter=0;
boolean gunFrustration= false;
Scanner userInput = new Scanner(System.in); Scanner userInput = new Scanner(System.in);
@@ -396,10 +392,8 @@ public class ShipWarfareGUI extends Application {
break; break;
} }
hitCounter++; hitCounter++;
delayForSeconds(1);
} else { } else {
missCounter++;
delayForSeconds(1);
} }
@@ -407,11 +401,10 @@ public class ShipWarfareGUI extends Application {
continue; continue;
} }
} }
label1.setText(String.format("Report:\nShips we hit: %d\nShots missed: %d", hitCounter,missCounter)); report.setText(String.format("Report: Ships we hit: %d Shots missed: %d", hitCounter,missCounter));
} }
else{ else{
label1.setText("We don't have any guns!!!"); report.setText("We don't have any guns!!!");
delayForSeconds(1);
} }
@@ -429,23 +422,20 @@ public class ShipWarfareGUI extends Application {
setNumOfPeasantShips(numOfPeasantShips - howMuchRun); setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
if (userAttacks == true) { if (userAttacks == true) {
System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, player.getName()); runAwayOrLeft.setText(String.format("Ahhh, %d ships ran away %s!\n", howMuchRun, player.getName()));
} else { } else {
System.out.printf("Escaped %d of them!\n", howMuchRun); runAwayOrLeft.setText(String.format("Escaped %d of them!\n", howMuchRun));
} }
} }
} }
} }
System.out.printf("%d ships remaining\n", numOfPeasantShips); shipsRemaining.setText(String.format("%d ships remaining and they look angry!\n", numOfPeasantShips));
delayForSeconds(1);
System.out.println("Oh no, they are taking the offensive!");
delayForSeconds(1);
//Computer volley //Computer volley
int takeGunChance = randomValue.nextInt(4) + 1; int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && player.getGuns() > 0) { if (takeGunChance == 1 && player.getGuns() > 0) {
player.setGuns(player.getGuns() - 1); player.setGuns(player.getGuns() - 1);
System.out.println("Dang it! They destroyed one of our guns"); gunFrustration=true;
} else { } else {
player.setHP(player.getHP() - (1 + randomValue.nextInt(10))); player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
} }
@@ -453,42 +443,53 @@ public class ShipWarfareGUI extends Application {
exitValue = 2; exitValue = 2;
break; break;
} }
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); if(gunFrustration==true){
delayForSeconds(1); gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", player.getGuns()));
}
else{
gunsLeftOrTaken.setText(String.format("We still have %d guns left", player.getGuns()));
}
HPLeft.setText(String.format("EEK, our current ship status is %d%% \n", player.getHP()));
if (userAttacks == false) { if (userAttacks == false) {
userAttacks = true; 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", player.getGuns()); continueToFight.setText(String.format("Shall we continue to fight? (Click the fight button or the run button)\n", player.getGuns()));
if (runButton.isPressed()) {
String response = userInput.nextLine();
if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) { if (runFromShips() == false) {
System.out.println("Couldn't run away"); wipe();
chooseFightOrRun.setText("Couldn't run away");
} else { } else {
exitValue = 3; exitValue = 3;
break; break;
} }
} }
else if(fightButton.isPressed()){
title.setText("AYYYYYYYYYYY");
}
else{
}
} }
if (exitValue == 1) { 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", player.getHP()); System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
delayForSeconds(1);
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100; calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
player.setMoney(player.getMoney() + calculateLoot); player.setMoney(player.getMoney() + calculateLoot);
System.out.printf("We got $%,d!", calculateLoot); System.out.printf("We got $%,d!", calculateLoot);
delayForSeconds(2);
return true; return true;
} else if (exitValue == 2) { } else if (exitValue == 2) {
player.gameOver(); player.gameOver();
return true; return true;
} else if (exitValue == 3) { } else if (exitValue == 3) {
System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
delayForSeconds(2);
return true; return true;
} }
return false; return false;
@@ -521,7 +522,7 @@ public class ShipWarfareGUI extends Application {
public void setLabel1(String sysOut) { public void setLabel1(String sysOut) {
label1.setText(sysOut); report.setText(sysOut);
} }
/* /*
@@ -533,7 +534,7 @@ public class ShipWarfareGUI extends Application {
*/ */
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
shipWarfare.setNumOfPeasantShips(shipWarfare.numOfShips()); setNumOfPeasantShips(numOfShips());
BorderPane BorderPane = new BorderPane(); BorderPane BorderPane = new BorderPane();
@@ -543,13 +544,19 @@ public class ShipWarfareGUI extends Application {
gridPane.setVgap(5.0); gridPane.setVgap(5.0);
hBox = new HBox(); hBox = new HBox();
button1 = new Button(); fightButton = new Button();
button2 = new Button(); runButton = new Button();
vBox = new VBox(); vBox = new VBox();
label1 = new Label(); title = new Label();
label = new Label(); chooseFightOrRun = new Label();
vBox0 = new VBox(); report = new Label();
label0 = new Label(); runAwayOrLeft = new Label();
shipsRemaining = new Label();
HPLeft = new Label();
gunsLeftOrTaken = new Label();
continueToFight = new Label();
BorderPane.setPrefHeight(400.0); BorderPane.setPrefHeight(400.0);
BorderPane.setPrefWidth(600.0); BorderPane.setPrefWidth(600.0);
@@ -558,16 +565,22 @@ public class ShipWarfareGUI extends Application {
hBox.setPrefWidth(200.0); hBox.setPrefWidth(200.0);
hBox.setSpacing(10.0); hBox.setSpacing(10.0);
button1.setAlignment(javafx.geometry.Pos.CENTER); title.setAlignment(javafx.geometry.Pos.TOP_CENTER);
button1.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER); title.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
button1.setId("Button1"); title.setId("Label1");
button1.setMnemonicParsing(false); title.setText(String.format("%d ships attacking. Would you like to Fight or Run?",numOfPeasantShips));
button1.setText("Fight"); title.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
button2.setAlignment(javafx.geometry.Pos.CENTER); fightButton.setAlignment(javafx.geometry.Pos.CENTER);
button2.setId("Button2"); fightButton.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
button2.setMnemonicParsing(false); fightButton.setId("Button1");
button2.setText("Run"); fightButton.setMnemonicParsing(false);
fightButton.setText("Fight");
runButton.setAlignment(javafx.geometry.Pos.CENTER);
runButton.setId("Button2");
runButton.setMnemonicParsing(false);
runButton.setText("Run");
BorderPane.setBottom(hBox); BorderPane.setBottom(hBox);
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER); BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
@@ -576,76 +589,45 @@ public class ShipWarfareGUI extends Application {
vBox.setPrefWidth(100.0); vBox.setPrefWidth(100.0);
vBox.setSpacing(20.0); vBox.setSpacing(20.0);
label1.setAlignment(javafx.geometry.Pos.TOP_CENTER); report.setAlignment(javafx.geometry.Pos.TOP_CENTER);
label1.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER); report.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
label1.setId("Label1"); report.setId("Label1");
label1.setPadding(new Insets(6.0, 0.0, 0.0, 0.0)); report.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
vBox.setPadding(new Insets(0.0, 0.0, 10.0, 0.0)); vBox.setPadding(new Insets(0.0, 0.0, 10.0, 0.0));
BorderPane.setTop(vBox); BorderPane.setTop(vBox);
BorderPane.setPadding(new Insets(6.0, 0.0, 0.0, 0.0)); BorderPane.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
vBox0.setAlignment(javafx.geometry.Pos.TOP_CENTER);
vBox0.setPrefHeight(200.0);
vBox0.setPrefWidth(100.0);
vBox0.setSpacing(5.0);
hBox.getChildren().add(button1); hBox.getChildren().add(fightButton);
hBox.getChildren().add(button2); hBox.getChildren().add(runButton);
vBox.getChildren().add(label1); vBox.getChildren().add(title);
vBox.getChildren().add(label); vBox.getChildren().add(chooseFightOrRun);
vBox0.getChildren().add(label0); vBox.getChildren().add(report);
vBox.getChildren().add(vBox0); vBox.getChildren().add(runAwayOrLeft);
int calculateLoot = 0; vBox.getChildren().add(shipsRemaining);
int chanceOfEnemyRun = 0; vBox.getChildren().add(HPLeft);
vBox.getChildren().add(gunsLeftOrTaken);
vBox.getChildren().add(continueToFight);
//label1.setText(String.format("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), shipWarfare.getNumOfPeasantShips(), player.getHP()));
label.setText("What would you like to do?");
//report.setText(String.format("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), shipWarfare.getNumOfPeasantShips(), player.getHP()));
//Fight //Fight
button1.setOnAction(new EventHandler<ActionEvent>() { fightButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
counter++; counter++;
if (counter == 1) { if (counter == 1) {
label.setText("Ohh, Fight ehh?"); chooseFightOrRun.setText("Ohh, Fight ehh?");
try {
destroyPeasantShipsOrEscape();
}
catch(Exception e){
int hitCounter=0;
int missCounter=0;
Random randomValue = new Random();
int exitValue = 0;
while (exitValue == 0) {
if (player.getGuns() > 0) {
for (int j = 0; j < player.getGuns(); j++) {
if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(2) + 1;
if (hitOrMiss == 2) {
numOfPeasantShips--;
if (numOfPeasantShips <= 0) {
exitValue = 1;
break;
}
hitCounter++;
delayForSeconds(1);
} else {
missCounter++;
delayForSeconds(1);
}
} else {
continue;
}
}
label1.setText(String.format("Report:\nShips we hit: %d\nShots missed: %d", hitCounter, missCounter));
} else {
label1.setText("We don't have any guns!!!");
delayForSeconds(1);
}
} }
@@ -653,30 +635,30 @@ public class ShipWarfareGUI extends Application {
} }
if (counter == 2) { if (counter == 2) {
System.out.println("You pressed the button twice."); System.out.println("You pressed the button twice.");
button1.setVisible(false); fightButton.setVisible(false);
button2.setVisible(false); runButton.setVisible(false);
button1.setDisable(true); fightButton.setDisable(true);
button2.setDisable(true); runButton.setDisable(true);
} }
} }
}); });
//Flee //Flee
button2.setOnAction(new EventHandler<ActionEvent>() { runButton.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
counter++; counter++;
if (counter == 1) { if (counter == 1) {
label1.setText("Ohh, Run ehh?"); chooseFightOrRun.setText("Ohh, Run ehh?");
} }
if (counter == 2) { if (counter == 2) {
System.out.println("You pressed the button twice."); System.out.println("You pressed the button twice.");
button1.setVisible(false); fightButton.setVisible(false);
button2.setVisible(false); runButton.setVisible(false);
button1.setDisable(true); fightButton.setDisable(true);
button2.setDisable(true); runButton.setDisable(true);
} }
} }
}); });