WIP ShipWarFareLogic GUI made it so that I can start form scratch at combining logic with GUI

This commit is contained in:
KahootChampion
2019-04-06 22:28:23 -06:00
parent b11db35eb0
commit 8786e5d3c6
2 changed files with 15 additions and 32 deletions

View File

@@ -14,6 +14,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Duration; import javafx.util.Duration;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@@ -42,15 +43,10 @@ public class ShipWarfareGUI extends Player {
private Label shipsRemaining; private Label shipsRemaining;
private Label report; 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 boolean userAttacks = true;
private int startingLittyShips = 0;
private int howMuchRun = 0; private int howMuchRun = 0;
private int counter = 0; private int counter = 0;
private String pirateName = "Liu Yen"; 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 * 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 * 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 * @return true if the user wins, loses, or flees, it returns false otherwise
*/ */
public boolean destroyLittyShipsOrEscape(Stage stage) throws Exception { public boolean destroyLittyShipsOrEscape(Stage stage) throws Exception {
ShipWarfareGUILogic logic = new ShipWarfareGUILogic (getPlayer());
cannon.setLayoutX(beginningX); cannon.setLayoutX(beginningX);
cannon.setLayoutY(beginningY); cannon.setLayoutY(beginningY);
int calculateLoot = 0; int calculateLoot = 0;
@@ -122,9 +112,6 @@ public class ShipWarfareGUI extends Player {
boolean gunFrustration = false; boolean gunFrustration = false;
runAwayOrLeft.setText("No ships ran away"); runAwayOrLeft.setText("No ships ran away");
Random randomValue = new Random(); Random randomValue = new Random();
int exitValue = 0; int exitValue = 0;
@@ -151,7 +138,6 @@ public class ShipWarfareGUI extends Player {
} }
} else { } else {
//continue; //continue;
} }
@@ -176,7 +162,6 @@ public class ShipWarfareGUI extends Player {
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) { if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
setNumOfLittyShips(numOfLittyShips - howMuchRun); setNumOfLittyShips(numOfLittyShips - howMuchRun);
if (userAttacks == true) { if (userAttacks == true) {
if (howMuchRun > 0) { if (howMuchRun > 0) {
@@ -213,7 +198,7 @@ public class ShipWarfareGUI extends Player {
} }
if (gunFrustration == true) { if (gunFrustration == true) {
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", getGuns())); gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", getGuns()));
playerShoots(getGuns()+1); playerShoots(getGuns() + 1);
} else { } else {
gunsLeftOrTaken.setText(String.format("We still have %d guns left", getGuns())); 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 * Player attacks enemy ships in an animation
*/ */
public void playerShoots(int amountOfShots) { public void playerShoots(int amountOfShots) {
userAttacks=true; userAttacks = true;
shotsFired.setFromX(0); shotsFired.setFromX(0);
shotsFired.setFromY(0); shotsFired.setFromY(0);
shotsFired.setToX(endX); shotsFired.setToX(endX);
shotsFired.setToY(endY); shotsFired.setToY(endY);
shotsFired.setDuration(Duration.seconds(0.5)); shotsFired.setDuration(Duration.seconds(0.5));
if(getGuns()>0) { if (getGuns() > 0) {
shotsFired.setCycleCount(amountOfShots); shotsFired.setCycleCount(amountOfShots);
} } else {
else{
shotsFired.setCycleCount(0); shotsFired.setCycleCount(0);
shotsFired.stop(); shotsFired.stop();
cannon.setVisible(false); cannon.setVisible(false);
@@ -280,7 +264,7 @@ public class ShipWarfareGUI extends Player {
* Ships attack player ship back in an animation * Ships attack player ship back in an animation
*/ */
public void shipsRetaliate(){ public void shipsRetaliate() {
cannon.setVisible(true); cannon.setVisible(true);
enemyShots.setFromX(270); enemyShots.setFromX(270);
enemyShots.setFromY(0); enemyShots.setFromY(0);
@@ -317,6 +301,7 @@ public class ShipWarfareGUI extends Player {
/** /**
* Generaties ships and deploys logic for the shipwarfare * Generaties ships and deploys logic for the shipwarfare
*
* @param primaryStage sets up the stage to whcih the GUI may be based around * @param primaryStage sets up the stage to whcih the GUI may be based around
* @throws Exception in case of interruptions withing the graphical interface * @throws Exception in case of interruptions withing the graphical interface
*/ */
@@ -334,7 +319,6 @@ public class ShipWarfareGUI extends Player {
this.cannon = cannon; this.cannon = cannon;
cannon.setVisible(false); cannon.setVisible(false);
buttonBox = new VBox(); buttonBox = new VBox();
@@ -401,7 +385,7 @@ public class ShipWarfareGUI extends Player {
ourShip = new Image(new FileInputStream("src/images/ourShip.png")); ourShip = new Image(new FileInputStream("src/images/ourShip.png"));
enemyShip = new Image(new FileInputStream("src/images/enemyShip.png")); enemyShip = new Image(new FileInputStream("src/images/enemyShip.png"));
}catch(Exception e){ } catch (Exception e) {
ourShip = new Image(new FileInputStream("images/ourShip.png")); ourShip = new Image(new FileInputStream("images/ourShip.png"));
enemyShip = new Image(new FileInputStream("images/enemyShip.png")); enemyShip = new Image(new FileInputStream("images/enemyShip.png"));
} }
@@ -509,11 +493,11 @@ public class ShipWarfareGUI extends Player {
if (runFromShips(userAttacks) == false) { if (runFromShips(userAttacks) == false) {
report.setText(("Couldn't run away")); report.setText(("Couldn't run away"));
try { try {
winOrLose= destroyLittyShipsOrEscape(primaryStage); winOrLose = destroyLittyShipsOrEscape(primaryStage);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if(winOrLose==true){ if (winOrLose == true) {
report.setVisible(true); report.setVisible(true);
title.setVisible(true); title.setVisible(true);
shipsRemaining.setVisible(true); shipsRemaining.setVisible(true);
@@ -549,7 +533,7 @@ public class ShipWarfareGUI extends Player {
runButton.setVisible(false); runButton.setVisible(false);
try { try {
winOrLose= destroyLittyShipsOrEscape(primaryStage); winOrLose = destroyLittyShipsOrEscape(primaryStage);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -575,10 +559,9 @@ public class ShipWarfareGUI extends Player {
*/ */
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
shotsFired.stop(); shotsFired.stop();
if(!winOrLose) { if (!winOrLose) {
shipsRetaliate(); shipsRetaliate();
} } else {
else{
report.setVisible(true); report.setVisible(true);
continueButton.setVisible(true); continueButton.setVisible(true);
usAgainstEnemyDivisor.setVisible(false); usAgainstEnemyDivisor.setVisible(false);
@@ -603,7 +586,7 @@ public class ShipWarfareGUI extends Player {
HPLeft.setVisible(true); HPLeft.setVisible(true);
gunsLeftOrTaken.setVisible(true); gunsLeftOrTaken.setVisible(true);
if(winOrLose==true){ if (winOrLose == true) {
usAgainstEnemyDivisor.setVisible(false); usAgainstEnemyDivisor.setVisible(false);
} }

Binary file not shown.