Have logic and ShipWarfareGUI sufficiently separated

This commit is contained in:
KahootChampion
2019-04-06 22:50:54 -06:00
parent 8786e5d3c6
commit 233521b6a7

View File

@@ -17,7 +17,6 @@ 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;
/** /**
* 2019-03-10 (Edited on 2019-03-23) * 2019-03-10 (Edited on 2019-03-23)
@@ -28,6 +27,8 @@ import java.util.concurrent.ExecutionException;
public class ShipWarfareGUI extends Player { public class ShipWarfareGUI extends Player {
ShipWarfareGUILogic logic = new ShipWarfareGUILogic(getPlayer());
private ShipWarfareGUI ship; private ShipWarfareGUI ship;
private Circle cannon; private Circle cannon;
private VBox buttonBox; private VBox buttonBox;
@@ -103,6 +104,7 @@ public class ShipWarfareGUI extends Player {
* @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 {
cannon.setLayoutX(beginningX); cannon.setLayoutX(beginningX);
cannon.setLayoutY(beginningY); cannon.setLayoutY(beginningY);
int calculateLoot = 0; int calculateLoot = 0;
@@ -124,12 +126,22 @@ public class ShipWarfareGUI extends Player {
int hitOrMiss = randomValue.nextInt(2) + 1; int hitOrMiss = randomValue.nextInt(2) + 1;
if (hitOrMiss == 2) { if (hitOrMiss == 2) {
numOfLittyShips--; //numOfLittyShips--;
if (numOfLittyShips <= 0) { logic.setNumOfLittyShips(logic.getNumOfLittyShips()-1);
/*if (numOfLittyShips <= 0) {
exitValue = 1; exitValue = 1;
//break; //break;
} }
hitCounter++; hitCounter++;
*/
if (logic.getNumOfLittyShips() <= 0) {
exitValue = 1;
//break;
}
hitCounter++;
} else { } else {
@@ -151,18 +163,26 @@ public class ShipWarfareGUI extends Player {
} }
/*
if (numOfLittyShips <= 0) { if (numOfLittyShips <= 0) {
exitValue = 1; exitValue = 1;
//break; //break;
} }
*/
if (logic.getNumOfLittyShips() <= 0) {
exitValue = 1;
//break;
}
if (getGuns() > 0) { if (getGuns() > 0) {
chanceOfEnemyRun = randomValue.nextInt(2) + 1; chanceOfEnemyRun = randomValue.nextInt(2) + 1;
if (chanceOfEnemyRun == 2) { if (chanceOfEnemyRun == 2) {
howMuchRun = randomValue.nextInt(15) + 1; howMuchRun = randomValue.nextInt(15) + 1;
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) { if (howMuchRun != 0 && howMuchRun < logic.getNumOfLittyShips()) {
setNumOfLittyShips(numOfLittyShips - howMuchRun); logic.setNumOfLittyShips(logic.getNumOfLittyShips() - howMuchRun);
if (userAttacks == true) { if (userAttacks == true) {
if (howMuchRun > 0) { if (howMuchRun > 0) {
runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, getName())); runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, getName()));
@@ -178,14 +198,14 @@ public class ShipWarfareGUI extends Player {
} }
} }
shipsRemaining.setText(String.format("%d ships remaining and they look angry!", numOfLittyShips)); shipsRemaining.setText(String.format("%d ships remaining and they look angry!", logic.getNumOfLittyShips()));
//Computer volley //Computer volley
int takeGunChance = randomValue.nextInt(4) + 1; int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && getGuns() > 0) { if (takeGunChance == 1 && getGuns() > 0) {
setGuns(getGuns() - 1); setGuns(getGuns() - 1);
gunFrustration = true; gunFrustration = true;
} else { } else {
if (numOfLittyShips > 0) { if (logic.getNumOfLittyShips() > 0) {
int HPTaken = randomValue.nextInt(10); int HPTaken = randomValue.nextInt(10);
setHP(getHP() - (HPTaken)); setHP(getHP() - (HPTaken));
@@ -212,7 +232,7 @@ public class ShipWarfareGUI extends Player {
if (exitValue == 1) { if (exitValue == 1) {
wipe(); wipe();
int calculateLoot = calculateLoot(); calculateLoot = logic.calculateLoot();
report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot)); report.setText(String.format("Our firm has earned $%,d in loot! ", calculateLoot));
continueButton.setVisible(true); continueButton.setVisible(true);
completeWipe(); completeWipe();
@@ -306,7 +326,8 @@ public class ShipWarfareGUI extends Player {
* @throws Exception in case of interruptions withing the graphical interface * @throws Exception in case of interruptions withing the graphical interface
*/ */
public void initializeShip(Stage primaryStage) throws Exception { public void initializeShip(Stage primaryStage) throws Exception {
setNumOfLittyShips(numOfShips());
logic.setNumOfLittyShips(logic.numOfShips());
Pane root = new Pane(); Pane root = new Pane();
HBox usAgainstEnemyDivisor; HBox usAgainstEnemyDivisor;
@@ -334,7 +355,7 @@ public class ShipWarfareGUI extends Player {
shipsRemaining = new Label(); shipsRemaining = new Label();
report = new Label(); report = new Label();
title.setText(String.format("%d ships from Liu Yuen's Fleet are attacking, Would you like to fight or run?", numOfLittyShips)); title.setText(String.format("%d ships from Liu Yuen's Fleet are attacking, Would you like to fight or run?", logic.getNumOfLittyShips()));
fightButton.setText("Fight"); fightButton.setText("Fight");
@@ -490,7 +511,7 @@ public class ShipWarfareGUI extends Player {
report.setText("Epic"); report.setText("Epic");
counter++; counter++;
if (runFromShips(userAttacks) == false) { if (logic.runFromShips(userAttacks) == false) {
report.setText(("Couldn't run away")); report.setText(("Couldn't run away"));
try { try {
winOrLose = destroyLittyShipsOrEscape(primaryStage); winOrLose = destroyLittyShipsOrEscape(primaryStage);