Shipwarfare fight button GUI almost complete
This commit is contained in:
@@ -45,7 +45,6 @@ public class ShipWarfareGUI extends Application {
|
|||||||
private Label continueToFight;
|
private Label continueToFight;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
@@ -62,6 +61,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setter method for player
|
* setter method for player
|
||||||
|
*
|
||||||
* @param player object of the class Player
|
* @param player object of the class Player
|
||||||
*/
|
*/
|
||||||
public void setPlayer(Player player) {
|
public void setPlayer(Player player) {
|
||||||
@@ -71,6 +71,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getter method for obtaining a player object.
|
* getter method for obtaining a player object.
|
||||||
|
*
|
||||||
* @return returns player object
|
* @return returns player object
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
@@ -80,6 +81,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
|
* This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits
|
||||||
|
*
|
||||||
* @throws Exception in case of errors due to the delay
|
* @throws Exception in case of errors due to the delay
|
||||||
*/
|
*/
|
||||||
public void peasantFleetAttack() throws Exception {
|
public void peasantFleetAttack() throws Exception {
|
||||||
@@ -118,6 +120,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
|
* This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
|
||||||
|
*
|
||||||
* @throws Exception in case of errors due to the delay
|
* @throws Exception in case of errors due to the delay
|
||||||
*/
|
*/
|
||||||
public void littyFleetAttack() throws Exception {
|
public void littyFleetAttack() throws Exception {
|
||||||
@@ -164,6 +167,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setter method that takes in an integer as an argument
|
* setter method that takes in an integer as an argument
|
||||||
|
*
|
||||||
* @param numOfLittyShips the number of ships to be used in the litty fleet attack
|
* @param numOfLittyShips the number of ships to be used in the litty fleet attack
|
||||||
*/
|
*/
|
||||||
public void setNumOfLittyShips(int numOfLittyShips) {
|
public void setNumOfLittyShips(int numOfLittyShips) {
|
||||||
@@ -174,6 +178,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setter method that takes in an integer as an argument
|
* setter method that takes in an integer as an argument
|
||||||
|
*
|
||||||
* @param numOfPeasantShips the number of ships to be used in the peasant fleet attack
|
* @param numOfPeasantShips the number of ships to be used in the peasant fleet attack
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -184,9 +189,9 @@ public class ShipWarfareGUI extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of ships that attack is based on the amount of money one has on hand
|
* The number of ships that attack is based on the amount of money one has on hand
|
||||||
|
*
|
||||||
* @return the number of ships which will attack
|
* @return the number of ships which will attack
|
||||||
*/
|
*/
|
||||||
public int numOfShips() {
|
public int numOfShips() {
|
||||||
@@ -214,6 +219,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* One in two chance of running away
|
* One in two chance of running away
|
||||||
|
*
|
||||||
* @return true if the user is allowed to run, false if not, the "default" is false
|
* @return true if the user is allowed to run, false if not, the "default" is false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -232,10 +238,10 @@ public class ShipWarfareGUI extends Application {
|
|||||||
/**
|
/**
|
||||||
* 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
|
||||||
* The loot for defeating a litty fleet is much higher than that of a peasant one
|
* The loot for defeating a litty fleet is much higher than that of a peasant one
|
||||||
|
*
|
||||||
* @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
|
||||||
* @throws Exception in case of errors due to the
|
* @throws Exception in case of errors due to the
|
||||||
*
|
*/
|
||||||
* */
|
|
||||||
public boolean destroyLittyShipsOrEscape() throws Exception {
|
public boolean destroyLittyShipsOrEscape() throws Exception {
|
||||||
int calculateLoot = 0;
|
int calculateLoot = 0;
|
||||||
int chanceOfEnemyRun = 0;
|
int chanceOfEnemyRun = 0;
|
||||||
@@ -331,7 +337,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
|
|
||||||
if (exitValue == 1) {
|
if (exitValue == 1) {
|
||||||
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
|
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%%% ship status\n", player.getHP());
|
||||||
calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300;
|
calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300;
|
||||||
player.setMoney(player.getMoney() + calculateLoot);
|
player.setMoney(player.getMoney() + calculateLoot);
|
||||||
System.out.printf("We got $%,d!\n", calculateLoot);
|
System.out.printf("We got $%,d!\n", calculateLoot);
|
||||||
@@ -349,11 +355,6 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 void wipe() {
|
public void wipe() {
|
||||||
title.setVisible(false);
|
title.setVisible(false);
|
||||||
@@ -366,13 +367,21 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
public boolean destroyPeasantShipsOrEscape() throws Exception {
|
||||||
int calculateLoot = 0;
|
int calculateLoot = 0;
|
||||||
int chanceOfEnemyRun = 0;
|
int chanceOfEnemyRun = 0;
|
||||||
int hitCounter = 0;
|
int hitCounter = 0;
|
||||||
int missCounter = 0;
|
int missCounter = 0;
|
||||||
boolean gunFrustration = false;
|
boolean gunFrustration = false;
|
||||||
|
//runAwayOrLeft.setVisible(false);
|
||||||
|
runAwayOrLeft.setText("No ships ran away");
|
||||||
|
|
||||||
Scanner userInput = new Scanner(System.in);
|
Scanner userInput = new Scanner(System.in);
|
||||||
Random randomValue = new Random();
|
Random randomValue = new Random();
|
||||||
@@ -401,9 +410,8 @@ public class ShipWarfareGUI extends Application {
|
|||||||
//continue;
|
//continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
report.setText(String.format("Report: Ships we hit: %d Shots missed: %d", hitCounter,missCounter));
|
report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
report.setText("We don't have any guns!!!");
|
report.setText("We don't have any guns!!!");
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -421,11 +429,13 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
|
|
||||||
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
|
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
|
||||||
if (userAttacks == true) {
|
if (howMuchRun > 0) {
|
||||||
runAwayOrLeft.setText(String.format("Ahhh, %d ships ran away %s! ", howMuchRun, player.getName()));
|
runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, player.getName()));
|
||||||
|
//runAwayOrLeft.setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
runAwayOrLeft.setText(String.format("Escaped %d of them! ", howMuchRun));
|
runAwayOrLeft.setText("None chose to flee!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,8 +455,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
}
|
}
|
||||||
if (gunFrustration == true) {
|
if (gunFrustration == true) {
|
||||||
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", player.getGuns()));
|
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", player.getGuns()));
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
gunsLeftOrTaken.setText(String.format("We still have %d guns left", player.getGuns()));
|
gunsLeftOrTaken.setText(String.format("We still have %d guns left", player.getGuns()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,12 +475,9 @@ public class ShipWarfareGUI extends Application {
|
|||||||
exitValue = 3;
|
exitValue = 3;
|
||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
}
|
} else if (fightButton.isPressed()) {
|
||||||
|
|
||||||
else if(fightButton.isPressed()){
|
|
||||||
title.setText("AYYYYYYYYYYY");
|
title.setText("AYYYYYYYYYYY");
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,7 +487,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
if (exitValue == 1) {
|
if (exitValue == 1) {
|
||||||
wipe();
|
wipe();
|
||||||
chooseFightOrRun.setText(String.format("Ayy We won! We survived at %d ship status!", player.getHP()));
|
chooseFightOrRun.setText(String.format("Ayy We won! We survived at %d%% ship status!", player.getHP()));
|
||||||
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
|
System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP());
|
||||||
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
|
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
|
||||||
player.setMoney(player.getMoney() + calculateLoot);
|
player.setMoney(player.getMoney() + calculateLoot);
|
||||||
@@ -500,14 +506,13 @@ public class ShipWarfareGUI extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Main G
|
//Main G
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delays for a specific amount of seconds, takes an integer as an argument
|
* delays for a specific amount of seconds, takes an integer as an argument
|
||||||
|
*
|
||||||
* @param num the seconds to delay
|
* @param num the seconds to delay
|
||||||
* @throws Exception in case of errors due to the delay
|
* @throws Exception in case of errors due to the delay
|
||||||
*/
|
*/
|
||||||
@@ -521,8 +526,6 @@ public class ShipWarfareGUI extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setLabel1(String sysOut) {
|
public void setLabel1(String sysOut) {
|
||||||
report.setText(sysOut);
|
report.setText(sysOut);
|
||||||
}
|
}
|
||||||
@@ -537,7 +540,6 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
public void start(Stage stage) throws Exception {
|
public void start(Stage stage) throws Exception {
|
||||||
setNumOfPeasantShips(numOfShips());
|
setNumOfPeasantShips(numOfShips());
|
||||||
player.setGuns(5);
|
|
||||||
|
|
||||||
BorderPane BorderPane = new BorderPane();
|
BorderPane BorderPane = new BorderPane();
|
||||||
|
|
||||||
@@ -559,7 +561,6 @@ public class ShipWarfareGUI extends Application {
|
|||||||
continueToFight = new Label();
|
continueToFight = new Label();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BorderPane.setPrefHeight(400.0);
|
BorderPane.setPrefHeight(400.0);
|
||||||
BorderPane.setPrefWidth(600.0);
|
BorderPane.setPrefWidth(600.0);
|
||||||
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||||
@@ -611,9 +612,6 @@ public class ShipWarfareGUI extends Application {
|
|||||||
vBox.getChildren().add(continueToFight);
|
vBox.getChildren().add(continueToFight);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//report.setText(String.format("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), shipWarfare.getNumOfPeasantShips(), player.getHP()));
|
//report.setText(String.format("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), shipWarfare.getNumOfPeasantShips(), player.getHP()));
|
||||||
|
|
||||||
|
|
||||||
@@ -625,8 +623,8 @@ public class ShipWarfareGUI extends Application {
|
|||||||
chooseFightOrRun.setText("Ohh, Fight ehh?");
|
chooseFightOrRun.setText("Ohh, Fight ehh?");
|
||||||
try {
|
try {
|
||||||
destroyPeasantShipsOrEscape();
|
destroyPeasantShipsOrEscape();
|
||||||
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
catch(Exception e){}
|
|
||||||
if (counter == 2) {
|
if (counter == 2) {
|
||||||
title.setVisible(false);
|
title.setVisible(false);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user