From 8786e5d3c6916d28e06cd061bca37f09e2856e18 Mon Sep 17 00:00:00 2001 From: KahootChampion Date: Sat, 6 Apr 2019 22:28:23 -0600 Subject: [PATCH] WIP ShipWarFareLogic GUI made it so that I can start form scratch at combining logic with GUI --- src/ShipWarfareGUI.java | 47 +++++++++++++-------------------------- src/saves/playerSave.txt | Bin 383 -> 383 bytes 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java index c990308..8dfd718 100644 --- a/src/ShipWarfareGUI.java +++ b/src/ShipWarfareGUI.java @@ -14,6 +14,7 @@ import javafx.scene.layout.VBox; import javafx.scene.shape.Circle; import javafx.stage.Stage; import javafx.util.Duration; + import java.io.FileInputStream; import java.util.Random; import java.util.concurrent.ExecutionException; @@ -42,15 +43,10 @@ public class ShipWarfareGUI extends Player { private Label shipsRemaining; private Label report; - private boolean winOrLose= false; + private boolean winOrLose = false; - private int counter1; - private int timeCounter; - - private int numOfLittyShips = 0; private boolean userAttacks = true; - private int startingLittyShips = 0; private int howMuchRun = 0; private int counter = 0; private String pirateName = "Liu Yen"; @@ -75,8 +71,6 @@ public class ShipWarfareGUI extends Player { } - - /** * Sets most of the labels invisible except for the "fight or run" label */ @@ -103,16 +97,12 @@ public class ShipWarfareGUI extends Player { } - - /** * The user faces off against the litty ships and either prevails, dies, or runs away * * @return true if the user wins, loses, or flees, it returns false otherwise */ public boolean destroyLittyShipsOrEscape(Stage stage) throws Exception { - ShipWarfareGUILogic logic = new ShipWarfareGUILogic (getPlayer()); - cannon.setLayoutX(beginningX); cannon.setLayoutY(beginningY); int calculateLoot = 0; @@ -122,9 +112,6 @@ public class ShipWarfareGUI extends Player { boolean gunFrustration = false; - - - runAwayOrLeft.setText("No ships ran away"); Random randomValue = new Random(); int exitValue = 0; @@ -151,7 +138,6 @@ public class ShipWarfareGUI extends Player { } - } else { //continue; } @@ -176,7 +162,6 @@ public class ShipWarfareGUI extends Player { if (howMuchRun != 0 && howMuchRun < numOfLittyShips) { - setNumOfLittyShips(numOfLittyShips - howMuchRun); if (userAttacks == true) { if (howMuchRun > 0) { @@ -213,7 +198,7 @@ public class ShipWarfareGUI extends Player { } if (gunFrustration == true) { gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", getGuns())); - playerShoots(getGuns()+1); + playerShoots(getGuns() + 1); } else { gunsLeftOrTaken.setText(String.format("We still have %d guns left", getGuns())); @@ -258,16 +243,15 @@ public class ShipWarfareGUI extends Player { * Player attacks enemy ships in an animation */ public void playerShoots(int amountOfShots) { - userAttacks=true; + userAttacks = true; shotsFired.setFromX(0); shotsFired.setFromY(0); shotsFired.setToX(endX); shotsFired.setToY(endY); shotsFired.setDuration(Duration.seconds(0.5)); - if(getGuns()>0) { + if (getGuns() > 0) { shotsFired.setCycleCount(amountOfShots); - } - else{ + } else { shotsFired.setCycleCount(0); shotsFired.stop(); cannon.setVisible(false); @@ -280,7 +264,7 @@ public class ShipWarfareGUI extends Player { * Ships attack player ship back in an animation */ - public void shipsRetaliate(){ + public void shipsRetaliate() { cannon.setVisible(true); enemyShots.setFromX(270); enemyShots.setFromY(0); @@ -317,6 +301,7 @@ public class ShipWarfareGUI extends Player { /** * Generaties ships and deploys logic for the shipwarfare + * * @param primaryStage sets up the stage to whcih the GUI may be based around * @throws Exception in case of interruptions withing the graphical interface */ @@ -334,7 +319,6 @@ public class ShipWarfareGUI extends Player { this.cannon = cannon; - cannon.setVisible(false); buttonBox = new VBox(); @@ -401,7 +385,7 @@ public class ShipWarfareGUI extends Player { ourShip = new Image(new FileInputStream("src/images/ourShip.png")); enemyShip = new Image(new FileInputStream("src/images/enemyShip.png")); - }catch(Exception e){ + } catch (Exception e) { ourShip = new Image(new FileInputStream("images/ourShip.png")); enemyShip = new Image(new FileInputStream("images/enemyShip.png")); } @@ -509,11 +493,11 @@ public class ShipWarfareGUI extends Player { if (runFromShips(userAttacks) == false) { report.setText(("Couldn't run away")); try { - winOrLose= destroyLittyShipsOrEscape(primaryStage); + winOrLose = destroyLittyShipsOrEscape(primaryStage); } catch (Exception e) { e.printStackTrace(); } - if(winOrLose==true){ + if (winOrLose == true) { report.setVisible(true); title.setVisible(true); shipsRemaining.setVisible(true); @@ -549,7 +533,7 @@ public class ShipWarfareGUI extends Player { runButton.setVisible(false); try { - winOrLose= destroyLittyShipsOrEscape(primaryStage); + winOrLose = destroyLittyShipsOrEscape(primaryStage); } catch (Exception e) { e.printStackTrace(); } @@ -575,10 +559,9 @@ public class ShipWarfareGUI extends Player { */ public void handle(ActionEvent event) { shotsFired.stop(); - if(!winOrLose) { + if (!winOrLose) { shipsRetaliate(); - } - else{ + } else { report.setVisible(true); continueButton.setVisible(true); usAgainstEnemyDivisor.setVisible(false); @@ -603,7 +586,7 @@ public class ShipWarfareGUI extends Player { HPLeft.setVisible(true); gunsLeftOrTaken.setVisible(true); - if(winOrLose==true){ + if (winOrLose == true) { usAgainstEnemyDivisor.setVisible(false); } diff --git a/src/saves/playerSave.txt b/src/saves/playerSave.txt index 2d1ed894e98b2b1cfb4d760ebba9ae25b6de1b7b..53f0be612acd6db0b0afa8aecfb9f7fb186cf9c6 100644 GIT binary patch delta 73 zcmey*^q*;iJ|p9T$p(xf)*K8B46Hy50*nv}MA|h#*=!C_2AnEkU<*miEJ(})0BQ~h AfB*mh delta 73 zcmey*^q*;iJ|p9n$p(xf)|?Cs46Hy50*nv}MC!Xh*&N#tf)G{-16xR9We0C7JE A!T