From 5a7d1e7c3403c91929b609306deb562ffc0288b6 Mon Sep 17 00:00:00 2001
From: KahootChampion
Date: Sat, 9 Mar 2019 18:33:33 -0700
Subject: [PATCH] Missed one statement that I needed to encapsulate
---
.idea/workspace.xml | 213 ++++++++++++++++++++++++++++------------
src/Player.java | 2 +-
src/ShipWarfare.java | 2 +-
src/ShipWarfareGUI.java | 179 ++++++++++++++++++++++++++-------
4 files changed, 299 insertions(+), 97 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 8a93212..ff3eb52 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,9 +1,11 @@
-
-
+
+
+
+
@@ -19,19 +21,56 @@
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -39,23 +78,14 @@
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
@@ -71,25 +101,48 @@
- Hp
travel
notDone
GetGuns
- get
set
TaipanShop
shop()
shop
+ being
+ label0
+ hBox
+ <
+ winO
+ destroy
+ get
+ user
+ setNumOfP
+ setUs
+ starting
+ destro
+ numOfpeasantShips
+ startingPeasantShips
+ startingLittyShips
+ howMuchRun
+ pirateName
+ player
+ numOfPeasantShips
+ peasant
+ litty
+ userAttacks
+ numOfLittyShips
HP
p1.get
p1.set
+ shipWarfare.getHowMuchRun()
+ shipWarfare.isUserAttacks()
+ shipWarfare.getNumOfPeasantShips()
-
-
+
@@ -97,17 +150,18 @@
-
-
+
+
+
@@ -142,7 +196,7 @@
-
+
@@ -329,17 +383,31 @@
1552172956109
-
+
+ 1552173216531
+
+
+
+ 1552173216532
+
+
+ 1552181324520
+
+
+
+ 1552181324520
+
+
-
+
-
+
-
+
@@ -348,7 +416,7 @@
-
+
@@ -358,7 +426,7 @@
-
+
@@ -450,7 +518,9 @@
-
+
+
+
@@ -513,13 +583,6 @@
-
-
-
-
-
-
-
@@ -530,13 +593,6 @@
-
-
-
-
-
-
-
@@ -547,31 +603,64 @@
-
+
-
+
+
+
-
+
+
+
+
-
-
-
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Player.java b/src/Player.java
index 32f46d8..be391c2 100644
--- a/src/Player.java
+++ b/src/Player.java
@@ -4,7 +4,7 @@ public class Player {
private String name = "Taipan";
private int bank = 0;
- private int money = 0;
+ private int money = 1000;
private int opiumHeld = 0;
private int silkHeld = 0;
private int generalHeld = 0;
diff --git a/src/ShipWarfare.java b/src/ShipWarfare.java
index f20861c..611a17e 100644
--- a/src/ShipWarfare.java
+++ b/src/ShipWarfare.java
@@ -55,7 +55,7 @@ public class ShipWarfare {
while (true) {
String response = userResponse.nextLine();
if (response.equalsIgnoreCase("f")) {
- userAttacks = true;
+ setUserAttacks(true);
System.out.println("Ohh, fight ehh?");
delayForSeconds(1);
boolean winOrLose = destroyPeasantShipsOrEscape();
diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java
index f256a99..d73ad99 100644
--- a/src/ShipWarfareGUI.java
+++ b/src/ShipWarfareGUI.java
@@ -18,6 +18,7 @@ import javafx.util.Duration;
import javafx.animation.AnimationTimer;
+import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@@ -27,6 +28,7 @@ public class ShipWarfareGUI extends Application {
private Player player = new Player();
+ private ShipWarfare shipWarfare = new ShipWarfare(player);
private HBox hBox;
private Button button1;
private Button button2;
@@ -44,6 +46,133 @@ public class ShipWarfareGUI extends Application {
private int counter = 0;
+/*
+ public boolean destroyPeasantShipsOrEscape(){
+ int calculateLoot = 0;
+ String userStrikes="";
+
+
+ int exitValue = 0;
+ int chanceOfEnemyRun = 0;
+ Random randomValue = new Random();
+
+ //Player volley
+ while (exitValue == 0) {
+ if (player.getGuns() > 0) {
+
+ for (int j = 0; j < player.getGuns(); j++) {
+ if (shipWarfare.isUserAttacks() == true) {
+ int hitOrMiss = randomValue.nextInt(2) + 1;
+ if (hitOrMiss == 2) {
+ shipWarfare.setNumOfPeasantShips(shipWarfare.getNumOfPeasantShips()-1);
+
+ if (shipWarfare.getNumOfPeasantShips() <= 0) {
+ exitValue = 1;
+ break;
+ }
+ userStrikes+= "Got eem\n";
+ System.out.println("Got eem");
+ delayForSeconds(1);
+ } else {
+ System.out.printf("ARRG! We missed %s\n", player.getName());
+ delayForSeconds(1);
+ }
+
+
+ } else {
+ continue;
+ }
+ }
+
+ label0.setText(userStrikes);
+ }
+ else{
+ System.out.printf("%s! We don't have any GUNS!!!!\n", player.getName());
+ delayForSeconds(1);
+
+ }
+
+
+ if (shipWarfare.getNumOfPeasantShips() <= 0) {
+ exitValue = 1;
+ break;
+ }
+ if (player.getGuns() > 0) {
+ chanceOfEnemyRun = randomValue.nextInt(2) + 1;
+ if (chanceOfEnemyRun == 2) {
+ shipWarfare.setHowMuchRun(randomValue.nextInt(15) + 1);
+ if (shipWarfare.getHowMuchRun() != 0 && shipWarfare.getHowMuchRun() < shipWarfare.getHowMuchRun()) {
+
+
+ shipWarfare.setNumOfPeasantShips(shipWarfare.getNumOfPeasantShips() - shipWarfare.getHowMuchRun());
+ if (shipWarfare.isUserAttacks() == true) {
+ System.out.printf("Ahhh, %d ships ran away %s!\n", shipWarfare.getHowMuchRun(), player.getName());
+ } else {
+ System.out.printf("Escaped %d of them!\n", shipWarfare.getHowMuchRun());
+ }
+ }
+ }
+ }
+
+ System.out.printf("%d ships remaining\n", shipWarfare.getNumOfPeasantShips());
+ delayForSeconds(1);
+ System.out.println("Oh no, they are taking the offensive!");
+ delayForSeconds(1);
+ //Computer volley
+ int takeGunChance = randomValue.nextInt(4) + 1;
+ if (takeGunChance == 1 && player.getGuns() > 0) {
+ player.setGuns(player.getGuns() - 1);
+ System.out.println("Dang it! They destroyed one of our guns");
+ } else {
+ player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
+ }
+ if (player.getHP() <= 0) {
+ exitValue = 2;
+ break;
+ }
+ System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
+ delayForSeconds(1);
+ if (shipWarfare.isUserAttacks() == false) {
+ shipWarfare.setUserAttacks() = 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());
+
+ if (response.equalsIgnoreCase("r")) {
+ if (shipWarfare.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", player.getHP());
+ delayForSeconds(1);
+ calculateLoot = (randomValue.nextInt(shipWarfare.getStartingPeasantShips()) + shipWarfare.getStartingPeasantShips()) * 100;
+ player.setMoney(player.getMoney() + calculateLoot);
+ System.out.printf("We got $%,d!", calculateLoot);
+ delayForSeconds(2);
+ return true;
+ } else if (exitValue == 2) {
+ player.gameOver();
+ return true;
+ } else if (exitValue == 3) {
+ System.out.printf("We made it out at %d%% ship status!\n", player.getHP());
+ delayForSeconds(2);
+ return true;
+ }
+ return false;
+
+
+ }
+ */
+
public void delayForSeconds(int num) {
@@ -54,27 +183,6 @@ public class ShipWarfareGUI extends Application {
}
}
- public int numOfShips() {
-
- int numOfShipsAttacking = 0;
- Random randomValue = new Random();
- if (player.getMoney() <= 100000) {
- //Minimum one ship will attack, maximum 20
- numOfShipsAttacking = randomValue.nextInt(20) + 1;
- } else if (player.getMoney() <= 200000) {
- //Minimum 30 Ships will attack, maximum 70
- numOfShipsAttacking = randomValue.nextInt(40) + 30;
- } else if (player.getMoney() <= 500000) {
- //Minimum 50 ships will attack, maximum 140
- numOfShipsAttacking = randomValue.nextInt(90) + 50;
- } else if (player.getMoney() > 1000000) {
- //Minimum 100 ships will attack, maximum 300 ships
- numOfShipsAttacking = randomValue.nextInt(3) + 100;
- }
-
- return numOfShipsAttacking;
-
- }
public void setPlayer(Player player) {
this.player = new Player(player);
@@ -97,6 +205,7 @@ public class ShipWarfareGUI extends Application {
*/
public void start(Stage stage) throws Exception {
+ shipWarfare.setNumOfPeasantShips(shipWarfare.numOfShips());
BorderPane BorderPane = new BorderPane();
@@ -142,21 +251,15 @@ public class ShipWarfareGUI extends Application {
label1.setAlignment(javafx.geometry.Pos.TOP_CENTER);
label1.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
label1.setId("Label1");
- label1.setText("Would you like to Fight or Run?");
label1.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
-
- label.setText("Ohh, Fight ehh?");
-
+ vBox.setPadding(new Insets(0.0, 0.0, 10.0, 0.0));
+ BorderPane.setTop(vBox);
+ 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);
- label0.setText("Got eem");
- vBox.setPadding(new Insets(0.0, 0.0, 10.0, 0.0));
- BorderPane.setTop(vBox);
- BorderPane.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
-
hBox.getChildren().add(button1);
hBox.getChildren().add(button2);
vBox.getChildren().add(label1);
@@ -166,7 +269,10 @@ public class ShipWarfareGUI extends Application {
ShipWarfareGUI ship = new ShipWarfareGUI();
- label1.setText(ship.numOfShips() + " Merchant Ships are attacking you.");
+
+ 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?");
+
//Fight
button1.setOnAction(new EventHandler() {
@@ -174,8 +280,15 @@ public class ShipWarfareGUI extends Application {
public void handle(ActionEvent event) {
counter++;
if (counter == 1) {
- label1.setText("Ohh, fight ehh?");
- label1.setText("Tis been 5 seconds");
+ int calculateLoot = 0;
+ int chanceOfEnemyRun = 0;
+ label.setText("Ohh, Fight ehh?");
+
+
+
+
+ label0.setText("Got eem");
+
}
if (counter == 2) {