Have logic and ShipWarfareGUI sufficiently separated

This commit is contained in:
KahootChampion
2019-04-07 14:17:44 -06:00
parent f834afb98f
commit 9e97877e6e
3 changed files with 25 additions and 33 deletions

View File

@@ -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
*/

View File

@@ -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 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,6 +38,11 @@ public class ShipWarfareLogic extends Player {
}
}
/**
* get the number of ships attacking
*
* @return the number of ships attacking
*/
public int getNumOfShips() {
return numOfShips;
}
@@ -79,11 +87,11 @@ public class ShipWarfareLogic extends Player {
}
return numOfShipsAttacking;
}
/**
* Calculates the loot for defeating a fleet
*
* @return the loot for defeating the fleet
*/
public int calculateLoot() {
@@ -95,7 +103,4 @@ public class ShipWarfareLogic extends Player {
return calculateLoot;
}
}

View File

@@ -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();
}
}