Shipwarfare fight button GUI almost complete
This commit is contained in:
@@ -45,7 +45,6 @@ public class ShipWarfareGUI extends Application {
|
||||
private Label continueToFight;
|
||||
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
launch(args);
|
||||
}
|
||||
@@ -62,6 +61,7 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
/**
|
||||
* setter method for player
|
||||
*
|
||||
* @param player object of the class Player
|
||||
*/
|
||||
public void setPlayer(Player player) {
|
||||
@@ -71,6 +71,7 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
/**
|
||||
* getter method for obtaining a player object.
|
||||
*
|
||||
* @return returns player object
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @throws Exception in case of errors due to the delay
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @throws Exception in case of errors due to the delay
|
||||
*/
|
||||
public void littyFleetAttack() throws Exception {
|
||||
@@ -164,6 +167,7 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
/**
|
||||
* setter method that takes in an integer as an argument
|
||||
*
|
||||
* @param numOfLittyShips the number of ships to be used in the litty fleet attack
|
||||
*/
|
||||
public void setNumOfLittyShips(int numOfLittyShips) {
|
||||
@@ -174,6 +178,7 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
/**
|
||||
* setter method that takes in an integer as an argument
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @return the number of ships which will attack
|
||||
*/
|
||||
public int numOfShips() {
|
||||
@@ -214,6 +219,7 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
/**
|
||||
* One in two chance of running away
|
||||
*
|
||||
* @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 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
|
||||
* @throws Exception in case of errors due to the
|
||||
*
|
||||
* */
|
||||
*/
|
||||
public boolean destroyLittyShipsOrEscape() throws Exception {
|
||||
int calculateLoot = 0;
|
||||
int chanceOfEnemyRun = 0;
|
||||
@@ -270,7 +276,7 @@ public class ShipWarfareGUI extends Application {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName());
|
||||
System.out.printf("%s! We don't have any GUNS!!!!\n", player.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -331,7 +337,7 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
|
||||
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;
|
||||
player.setMoney(player.getMoney() + calculateLoot);
|
||||
System.out.printf("We got $%,d!\n", calculateLoot);
|
||||
@@ -349,13 +355,8 @@ 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);
|
||||
runAwayOrLeft.setVisible(false);
|
||||
shipsRemaining.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 {
|
||||
int calculateLoot = 0;
|
||||
int chanceOfEnemyRun = 0;
|
||||
int hitCounter=0;
|
||||
int missCounter=0;
|
||||
boolean gunFrustration= false;
|
||||
|
||||
int hitCounter = 0;
|
||||
int missCounter = 0;
|
||||
boolean gunFrustration = false;
|
||||
//runAwayOrLeft.setVisible(false);
|
||||
runAwayOrLeft.setText("No ships ran away");
|
||||
|
||||
Scanner userInput = new Scanner(System.in);
|
||||
Random randomValue = new Random();
|
||||
@@ -401,9 +410,8 @@ public class ShipWarfareGUI extends Application {
|
||||
//continue;
|
||||
}
|
||||
}
|
||||
report.setText(String.format("Report: Ships we hit: %d Shots missed: %d", hitCounter,missCounter));
|
||||
}
|
||||
else{
|
||||
report.setText(String.format("Report: Ships hit: %d, Shots missed: %d", hitCounter, missCounter));
|
||||
} else {
|
||||
report.setText("We don't have any guns!!!");
|
||||
|
||||
}
|
||||
@@ -421,11 +429,13 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
|
||||
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
|
||||
if (userAttacks == true) {
|
||||
runAwayOrLeft.setText(String.format("Ahhh, %d ships ran away %s! ", howMuchRun, player.getName()));
|
||||
if (howMuchRun > 0) {
|
||||
runAwayOrLeft.setText(String.format("Cowards! %d ships ran away %s! ", howMuchRun, player.getName()));
|
||||
//runAwayOrLeft.setVisible(true);
|
||||
} else {
|
||||
runAwayOrLeft.setText(String.format("Escaped %d of them! ", howMuchRun));
|
||||
runAwayOrLeft.setText("None chose to flee!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -435,7 +445,7 @@ public class ShipWarfareGUI extends Application {
|
||||
int takeGunChance = randomValue.nextInt(4) + 1;
|
||||
if (takeGunChance == 1 && player.getGuns() > 0) {
|
||||
player.setGuns(player.getGuns() - 1);
|
||||
gunFrustration=true;
|
||||
gunFrustration = true;
|
||||
} else {
|
||||
player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
|
||||
}
|
||||
@@ -443,10 +453,9 @@ public class ShipWarfareGUI extends Application {
|
||||
exitValue = 2;
|
||||
//break;
|
||||
}
|
||||
if(gunFrustration==true){
|
||||
if (gunFrustration == true) {
|
||||
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()));
|
||||
}
|
||||
|
||||
@@ -466,12 +475,9 @@ public class ShipWarfareGUI extends Application {
|
||||
exitValue = 3;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
else if(fightButton.isPressed()){
|
||||
} else if (fightButton.isPressed()) {
|
||||
title.setText("AYYYYYYYYYYY");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
@@ -481,11 +487,11 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
if (exitValue == 1) {
|
||||
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());
|
||||
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
|
||||
player.setMoney(player.getMoney() + calculateLoot);
|
||||
report.setText(String.format("We got $%,d! ",calculateLoot));
|
||||
report.setText(String.format("We got $%,d! ", calculateLoot));
|
||||
return true;
|
||||
} else if (exitValue == 2) {
|
||||
player.gameOver();
|
||||
@@ -500,14 +506,13 @@ public class ShipWarfareGUI extends Application {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Main G
|
||||
private int counter = 0;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -521,8 +526,6 @@ public class ShipWarfareGUI extends Application {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setLabel1(String sysOut) {
|
||||
report.setText(sysOut);
|
||||
}
|
||||
@@ -537,7 +540,6 @@ public class ShipWarfareGUI extends Application {
|
||||
|
||||
public void start(Stage stage) throws Exception {
|
||||
setNumOfPeasantShips(numOfShips());
|
||||
player.setGuns(5);
|
||||
|
||||
BorderPane BorderPane = new BorderPane();
|
||||
|
||||
@@ -559,7 +561,6 @@ public class ShipWarfareGUI extends Application {
|
||||
continueToFight = new Label();
|
||||
|
||||
|
||||
|
||||
BorderPane.setPrefHeight(400.0);
|
||||
BorderPane.setPrefWidth(600.0);
|
||||
hBox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
@@ -570,7 +571,7 @@ public class ShipWarfareGUI extends Application {
|
||||
title.setAlignment(javafx.geometry.Pos.TOP_CENTER);
|
||||
title.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
|
||||
title.setId("Label1");
|
||||
title.setText(String.format("%d ships attacking. Would you like to Fight or Run?",numOfPeasantShips));
|
||||
title.setText(String.format("%d ships attacking. Would you like to Fight or Run?", numOfPeasantShips));
|
||||
title.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
|
||||
|
||||
fightButton.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
@@ -611,9 +612,6 @@ public class ShipWarfareGUI extends Application {
|
||||
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()));
|
||||
|
||||
|
||||
@@ -625,8 +623,8 @@ public class ShipWarfareGUI extends Application {
|
||||
chooseFightOrRun.setText("Ohh, Fight ehh?");
|
||||
try {
|
||||
destroyPeasantShipsOrEscape();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch(Exception e){}
|
||||
if (counter == 2) {
|
||||
title.setVisible(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user