From a07d633ff99fc6778f99d5b7a1b81d4561d970d4 Mon Sep 17 00:00:00 2001
From: KahootChampion
Date: Sun, 10 Mar 2019 11:26:54 -0600
Subject: [PATCH] Basic functionality of buttons completed, think all I have to
do now is to find a way to break the code when the user wins, loses or runs
away.
---
.idea/workspace.xml | 72 ++++++++++++++++++++++++++-------------
src/ShipWarfareGUI.java | 75 ++++++++++++++++++++++++++++++-----------
2 files changed, 105 insertions(+), 42 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index cf4458d..1ce512f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,9 @@
-
+
+
+
@@ -16,8 +18,20 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -46,8 +60,8 @@
-
-
+
+
@@ -116,9 +130,9 @@
-
+
@@ -134,6 +148,7 @@
+
@@ -151,7 +166,6 @@
-
@@ -267,6 +281,8 @@
+
+
1550458470138
@@ -429,17 +445,31 @@
1552205678080
-
+
+ 1552207442784
+
+
+
+ 1552207442785
+
+
+ 1552210228514
+
+
+
+ 1552210228514
+
+
-
+
-
+
@@ -536,7 +566,6 @@
-
@@ -560,7 +589,9 @@
-
+
+
+
@@ -639,30 +670,25 @@
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
+
+
diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java
index 6f32a61..e88cc60 100644
--- a/src/ShipWarfareGUI.java
+++ b/src/ShipWarfareGUI.java
@@ -1,3 +1,5 @@
+//Remember you deleted userAttacks = true, you might need it later
+
import javafx.animation.PathTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
@@ -368,6 +370,17 @@ public class ShipWarfareGUI extends Application {
continueToFight.setVisible(false);
+ }
+ public void completeWipe() {
+ title.setVisible(false);
+ chooseFightOrRun.setVisible(false);
+ runAwayOrLeft.setVisible(false);
+ shipsRemaining.setVisible(false);
+ HPLeft.setVisible(false);
+ gunsLeftOrTaken.setVisible(false);
+ continueToFight.setVisible(false);
+
+
}
/**
@@ -382,11 +395,19 @@ public class ShipWarfareGUI extends Application {
int chanceOfEnemyRun = 0;
int hitCounter = 0;
int missCounter = 0;
- boolean gunFrustration = false;
- //runAwayOrLeft.setVisible(false);
+ boolean gunFrustration = true;
+
+ title.setVisible(true);
+ chooseFightOrRun.setVisible(true);
+ report.setVisible(true);
+ runAwayOrLeft.setVisible(true);
+ shipsRemaining.setVisible(true);
+ HPLeft.setVisible(true);
+ gunsLeftOrTaken.setVisible(true);
+ continueToFight.setVisible(true);
+
runAwayOrLeft.setText("No ships ran away");
- Scanner userInput = new Scanner(System.in);
Random randomValue = new Random();
int exitValue = 0;
@@ -412,8 +433,9 @@ public class ShipWarfareGUI extends Application {
} else {
//continue;
}
+ }if(userAttacks==true) {
+ report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
}
- report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
} else {
report.setText("We don't have any guns!!!");
@@ -432,11 +454,18 @@ public class ShipWarfareGUI extends Application {
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
- if (howMuchRun > 0) {
- runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, player.getName()));
- //runAwayOrLeft.setVisible(true);
+ if (userAttacks == true) {
+ if (howMuchRun > 0) {
+ runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, player.getName()));
+ //runAwayOrLeft.setVisible(true);
+ }
+ else{
+ runAwayOrLeft.setText(String.format("Escaped %d of them %s! ", howMuchRun, player.getName()));
+
+ }
+
} else {
- runAwayOrLeft.setText("None chose to flee!");
+ report.setText((String.format("Escaped %d of them %s!", howMuchRun,player.getName())));
}
}
@@ -490,10 +519,10 @@ public class ShipWarfareGUI extends Application {
if (exitValue == 1) {
wipe();
- chooseFightOrRun.setText(String.format("Ayy We won! We survived at %d%% ship status!", player.getHP()));
+ chooseFightOrRun.setText(String.format("Ayy! We won and survived at %d%% ship status!", player.getHP()));
calculateLoot = (startingPeasantShips *100) + randomValue.nextInt(startingPeasantShips) *200;
player.setMoney(player.getMoney() + calculateLoot);
- report.setText(String.format("We got $%,d! ", calculateLoot));
+ report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
return true;
} else if (exitValue == 2) {
player.gameOver();
@@ -638,19 +667,27 @@ public class ShipWarfareGUI extends Application {
runButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
+ chooseFightOrRun.setText("Ayy captain we will try to run!");
counter++;
- if (counter == 1) {
- chooseFightOrRun.setText("Ohh, Run ehh?");
+
+ if (runFromShips() == false) {
+ title.setVisible(false);
+ chooseFightOrRun.setVisible(false);
+ report.setText(("Couldn't run away"));
+ try {
+ destroyPeasantShipsOrEscape();
+ } catch (Exception e) {
+ }
+ } else {
+ completeWipe();
+ report.setText("Phew! Got away safely");
}
- if (counter == 2) {
- System.out.println("You pressed the button twice.");
- fightButton.setVisible(false);
- runButton.setVisible(false);
- fightButton.setDisable(true);
- runButton.setDisable(true);
- }
+
+
+
+
}
});