From 9e97877e6ec568842198190a7816476ee0608f9d Mon Sep 17 00:00:00 2001
From: KahootChampion
Date: Sun, 7 Apr 2019 14:17:44 -0600
Subject: [PATCH] Have logic and ShipWarfareGUI sufficiently separated
---
src/ShipWarfareGUI.java | 7 +------
src/ShipWarfareLogic.java | 29 +++++++++++++++++------------
src/ShipWarfareText.java | 22 +++++++---------------
3 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java
index 1ad6ea6..26b3998 100644
--- a/src/ShipWarfareGUI.java
+++ b/src/ShipWarfareGUI.java
@@ -63,7 +63,6 @@ public class ShipWarfareGUI extends Player {
/**
* constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
- *
* @param player is a Player object that will be copied and the player instance variable is set to the copy.
*/
public ShipWarfareGUI(Player player) {
@@ -73,7 +72,7 @@ public class ShipWarfareGUI extends Player {
/**
- * Sets most of the labels invisible except for the "fight or run" label
+ * Sets most of the labels invisible
*/
public void wipe() {
wipeWithTitle(title);
@@ -100,7 +99,6 @@ public class ShipWarfareGUI extends Player {
/**
* The user faces off against the ships and either prevails, dies, or runs away
- *
* @return true if the user wins, loses, or flees, it returns false otherwise
*/
public boolean destroyShipsOrEscape(Stage stage) throws Exception {
@@ -257,7 +255,6 @@ public class ShipWarfareGUI extends Player {
/**
* Ships attack player ship back in an animation
*/
-
public void shipsRetaliate() {
cannon.setVisible(true);
enemyShots.setFromX(270);
@@ -272,7 +269,6 @@ public class ShipWarfareGUI extends Player {
/**
* Sets most buttons to being invisble and switches to TaipanShop scene
- *
* @param stage stage the user incorporates when they utilize the GUI
*/
public void setVisibilitiesAndTransition(Stage stage) {
@@ -295,7 +291,6 @@ 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
*/
diff --git a/src/ShipWarfareLogic.java b/src/ShipWarfareLogic.java
index 24bb95b..287c466 100644
--- a/src/ShipWarfareLogic.java
+++ b/src/ShipWarfareLogic.java
@@ -1,20 +1,23 @@
import java.util.Random;
/**
- * 2019-03-10 (Edited on 2019-04-1)
+ * 2019-03-10 (Edited on 2019-04-07)
* Author: Haris Muhammad
- * ShipWarfareGUILogic class, logic for ships which the user can attack or run from
+ * ShipWarfareLogic class, logic for ships which the user can attack or run from
*/
public class ShipWarfareLogic extends Player {
-
-
private int numOfShips = 0;
- private int startingShips=0;
+ private int startingShips = 0;
+ private int counter = 0;
- private int counter;
+ /**
+ * constructor; only runs when a Player object is provided. The constructor is fully encapsulated.
+ *
+ * @param player is a Player object that will be copied and the player instance variable is set to the copy.
+ */
public ShipWarfareLogic(Player player) {
Player playerDummy = new Player(player);
@@ -35,7 +38,12 @@ public class ShipWarfareLogic extends Player {
}
}
- public int getNumOfShips(){
+ /**
+ * get the number of ships attacking
+ *
+ * @return the number of ships attacking
+ */
+ public int getNumOfShips() {
return numOfShips;
}
@@ -79,14 +87,14 @@ public class ShipWarfareLogic extends Player {
}
return numOfShipsAttacking;
-
}
/**
* Calculates the loot for defeating a fleet
+ *
* @return the loot for defeating the fleet
*/
- public int calculateLoot(){
+ public int calculateLoot() {
Random randomValue = new Random();
int calculateLoot;
@@ -95,7 +103,4 @@ public class ShipWarfareLogic extends Player {
return calculateLoot;
}
-
-
-
}
diff --git a/src/ShipWarfareText.java b/src/ShipWarfareText.java
index 08d673c..816906a 100644
--- a/src/ShipWarfareText.java
+++ b/src/ShipWarfareText.java
@@ -2,6 +2,13 @@ import java.util.Scanner;
import java.util.Random;
import java.util.concurrent.TimeUnit;
+/**
+ * 2019-04-07
+ * Author: Haris Muhammad
+ * ShipWarfareText class, Based on logic class for ShipWarfare, text-based version which allwos for ship warfare
+ */
+
+
public class ShipWarfareText extends Player {
@@ -60,25 +67,19 @@ public class ShipWarfareText extends Player {
} else {
System.out.println("Invalid response, please try again");
}
-
}
-
}
/**
* Asks user if they would like to fight or run against ships
*/
-
public void fightOrRunMessage() {
System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)\n", getGuns());
-
}
-
/**
* delays for a specific amount of seconds, takes an integer as an argument
- *
* @param num the seconds to delay
* @throws Exception in case of errors due to the delay
*/
@@ -89,11 +90,9 @@ public class ShipWarfareText extends Player {
/**
* The user faces off against the peasant ships and either prevails, dies, or runs away
- *
* @return true if the user wins, loses, or flees, it returns false otherwise
* @throws Exception in case of errors due to the delay
*/
-
public boolean destroyPeasantShipsOrEscape() throws Exception {
int calculateLoot = 0;
int chanceOfEnemyRun = 0;
@@ -211,7 +210,6 @@ public class ShipWarfareText extends Player {
/**
* Ask the user to input either "f" or "r"
- *
* @param userInput scanner object which is used to ask for user input
* @return user input which is the users response
* @throws Exception in case the delay afects this piece of code
@@ -233,10 +231,4 @@ public class ShipWarfareText extends Player {
return response;
}
- public static void main(String[] args) throws Exception {
- Player littyBoi = new Player();
- ShipWarfareText test = new ShipWarfareText(littyBoi);
- test.peasantFleetAttack();
- }
-
}
\ No newline at end of file