Added fight Button gif. Might not work on your computers yet though... I inputed my own local documents folder as the library temporarily.

This commit is contained in:
KahootChampion
2019-03-19 23:34:54 -06:00
parent 2bc96e5d07
commit a33273035a
3 changed files with 166 additions and 78 deletions

2
.idea/misc.xml generated
View File

@@ -9,7 +9,7 @@
<component name="ProjectKey"> <component name="ProjectKey">
<option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" /> <option name="state" value="project://63537948-39a4-48a0-9c97-34259a0fa913" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8.0_201" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
<component name="SvnBranchConfigurationManager"> <component name="SvnBranchConfigurationManager">

View File

@@ -4,39 +4,49 @@ import javafx.geometry.Insets;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Random;
/** /**
* 2019-03-10 * 2019-03-10 (Edited on 2019-03-19)
* Authors: Haris Muhammad * Authors: Haris Muhammad
* ShipWarfareGUI class, Generates and utilizes ships which the user can attack or run from * ShipWarfareGUI class, Generates and utilizes ships which the user can attack or run from
* *
*/ */
import java.util.Random;
public class ShipWarfareGUI extends Player{ public class ShipWarfareGUI extends Player{
private HBox hBox; private HBox hBox;
private Button fightButton; private Button fightButton;
private Button runButton; private Button runButton;
private VBox vBox; private VBox vBox;
private Label title; private Label title;
private Label chooseFightOrRun; private Label chooseFightOrRun;
private Label report; private HBox hBox0;
private Label runAwayOrLeft; private VBox vBox0;
private Label shipsRemaining; private Label shipsRemaining;
private Label HPLeft; private Label report;
private Label gunsLeftOrTaken; private Label runAwayOrLeft;
private Label continueToFight; private Label HPLeft;
private Label gunsLeftOrTaken;
private Label continueToFight;
private ImageView imageView;
private int counter1; private int counter1;
private Button continueButton; private Button continueButton;
private int numOfPeasantShips = 0; private int numOfPeasantShips = 0;
private int numOfLittyShips = 0; private int numOfLittyShips = 0;
private boolean userAttacks = true; private boolean userAttacks = true;
@@ -257,7 +267,7 @@ public class ShipWarfareGUI extends Player{
userAttacks = true; userAttacks = true;
} }
continueToFight.setText(String.format("Captain, what are your orders? (Click the fight button or the run button)", getGuns())); continueToFight.setText(String.format("Captain, what are your orders?"));
if (exitValue == 1) { if (exitValue == 1) {
wipe(); wipe();
@@ -287,7 +297,7 @@ public class ShipWarfareGUI extends Player{
* @return stage so that another class can switch to the stage * @return stage so that another class can switch to the stage
*/ */
public Stage initializeShip(Stage stage) { public Stage initializeShip(Stage stage) throws FileNotFoundException {
setNumOfPeasantShips(numOfShips()); setNumOfPeasantShips(numOfShips());
BorderPane BorderPane = new BorderPane(); BorderPane BorderPane = new BorderPane();
@@ -302,15 +312,23 @@ public class ShipWarfareGUI extends Player{
vBox = new VBox(); vBox = new VBox();
title = new Label(); title = new Label();
chooseFightOrRun = new Label(); chooseFightOrRun = new Label();
hBox0 = new HBox();
vBox0 = new VBox();
shipsRemaining = new Label();
report = new Label(); report = new Label();
runAwayOrLeft = new Label(); runAwayOrLeft = new Label();
shipsRemaining = new Label();
HPLeft = new Label(); HPLeft = new Label();
gunsLeftOrTaken = new Label(); gunsLeftOrTaken = new Label();
continueToFight = new Label(); continueToFight = new Label();
imageView = new ImageView();
continueButton = new Button(); continueButton = new Button();
chooseFightOrRun.setVisible(false);
continueToFight.setPrefWidth(379);
continueButton.setVisible(false); continueButton.setVisible(false);
title.setVisible(true);
BorderPane.setPrefHeight(400.0); BorderPane.setPrefHeight(400.0);
@@ -326,18 +344,57 @@ public class ShipWarfareGUI extends Player{
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)); title.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
//Creating an image
//Image image = new Image(new FileInputStream("/Users/harismuhammad/Desktop/ShipsAttacking.gif"));
Image image = new Image(new FileInputStream("/Users/harismuhammad/Documents/TaipanClone/src/ShipsAttacking.gif"));
//Setting the image view
ImageView shipsAttackingGif = new ImageView(image);
shipsAttackingGif.setFitHeight(193.0);
shipsAttackingGif.setFitWidth(349.0);
shipsAttackingGif.setPickOnBounds(true);
shipsAttackingGif.setPreserveRatio(true);
shipsAttackingGif.setVisible(false);
BorderPane.setAlignment(hBox, javafx.geometry.Pos.CENTER);
hBox.setAlignment(javafx.geometry.Pos.CENTER);
hBox.setPrefHeight(100.0);
hBox.setPrefWidth(200.0);
hBox.setSpacing(10.0);
fightAndRunButtonSetting();
runButton.setText("Run");
BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
vBox.setPrefHeight(200.0);
vBox.setPrefWidth(200);
vBox.setSpacing(30.0);
titleSetting(title);
chooseFightOrRun.setText("Ohh, Fight ehh?");
hBox0.setPrefHeight(100.0);
hBox0.setPrefWidth(200.0);
vBox0.setPrefHeight(102.0);
vBox0.setPrefWidth(400.0);
vBox0.setSpacing(30.0);
continueButton.setMnemonicParsing(false); continueButton.setMnemonicParsing(false);
continueButton.setText("Continue?"); continueButton.setText("Continue?");
fightButton.setAlignment(javafx.geometry.Pos.CENTER); fightAndRunButtonSetting();
fightButton.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
fightButton.setId("Button1");
fightButton.setMnemonicParsing(false);
fightButton.setText("Fight");
runButton.setAlignment(javafx.geometry.Pos.CENTER);
runButton.setId("Button2");
runButton.setMnemonicParsing(false);
BorderPane.setBottom(hBox); BorderPane.setBottom(hBox);
runButton.setText("Run"); runButton.setText("Run");
@@ -345,14 +402,13 @@ public class ShipWarfareGUI extends Player{
javafx.scene.layout.BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER); javafx.scene.layout.BorderPane.setAlignment(vBox, javafx.geometry.Pos.CENTER);
vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER); vBox.setAlignment(javafx.geometry.Pos.TOP_CENTER);
vBox.setPrefHeight(200.0); vBox.setPrefHeight(200.0);
vBox.setPrefWidth(100.0); vBox.setPrefWidth(400.0);
vBox.setSpacing(20.0); vBox.setSpacing(20.0);
report.setAlignment(javafx.geometry.Pos.TOP_CENTER); titleSetting(report);
report.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
report.setId("Label1");
report.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
vBox.setPadding(new Insets(0.0, 0.0, 10.0, 0.0)); vBox.setPadding(new Insets(0.0, 0.0, 10.0, 0.0));
vBox0.setPadding(new Insets(0.0, 0.0, 0.0, 6.0));
BorderPane.setTop(vBox); BorderPane.setTop(vBox);
BorderPane.setPadding(new Insets(6.0, 0.0, 0.0, 0.0)); BorderPane.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
@@ -360,12 +416,15 @@ public class ShipWarfareGUI extends Player{
hBox.getChildren().add(runButton); hBox.getChildren().add(runButton);
vBox.getChildren().add(title); vBox.getChildren().add(title);
vBox.getChildren().add(chooseFightOrRun); vBox.getChildren().add(chooseFightOrRun);
vBox.getChildren().add(report); vBox0.getChildren().add(shipsRemaining);
vBox.getChildren().add(runAwayOrLeft); vBox0.getChildren().add(report);
vBox.getChildren().add(shipsRemaining); vBox0.getChildren().add(runAwayOrLeft);
vBox.getChildren().add(HPLeft); vBox0.getChildren().add(HPLeft);
vBox.getChildren().add(gunsLeftOrTaken); vBox0.getChildren().add(gunsLeftOrTaken);
vBox.getChildren().add(continueToFight); vBox0.getChildren().add(continueToFight);
hBox0.getChildren().add(vBox0);
hBox0.getChildren().add(shipsAttackingGif);
vBox.getChildren().add(hBox0);
vBox.getChildren().add(continueButton); vBox.getChildren().add(continueButton);
@@ -378,32 +437,19 @@ public class ShipWarfareGUI extends Player{
*/ */
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
counter++; counter++;
chooseFightOrRun.setText("Ohh, Fight ehh?"); chooseFightOrRun.setVisible(true);
try { try {
shipsAttackingGif.setVisible(true);
if (destroyPeasantShipsOrEscape(stage)) { if (destroyPeasantShipsOrEscape(stage)) {
completeWipe(); shipsAttackingGif.setVisible(false);
continueButton.setVisible(true); setVisibilitiesAndTransition(stage);
fightButton.setVisible(false);
runButton.setVisible(false);
continueButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
/**
* Switches to Taipan Shop scene
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
});
} }
} catch (Exception e) { } catch (Exception e) {
} }
if (counter >= 2) { if (counter >= 1) {
title.setVisible(false); title.setVisible(false);
} }
@@ -427,22 +473,7 @@ public class ShipWarfareGUI extends Player{
report.setText(("Couldn't run away")); report.setText(("Couldn't run away"));
try { try {
if (destroyPeasantShipsOrEscape(stage) == true) { if (destroyPeasantShipsOrEscape(stage) == true) {
completeWipe(); setVisibilitiesAndTransition(stage);
continueButton.setVisible(true);
fightButton.setVisible(false);
runButton.setVisible(false);
continueButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
/**
* Switches to Taipan Shop scene
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
});
} }
} catch (Exception e) { } catch (Exception e) {
@@ -450,9 +481,7 @@ public class ShipWarfareGUI extends Player{
} else { } else {
completeWipe(); completeWipe();
report.setText("Phew! Got away safely"); report.setText("Phew! Got away safely");
TaipanShopGUI shop = new TaipanShopGUI(getPlayer()); setVisibilitiesAndTransition(stage);
shop.initializeShop(stage);
stage.show();
} }
@@ -471,12 +500,64 @@ public class ShipWarfareGUI extends Player{
return stage; return stage;
} }
/**
* sets the title and does basic layout for the label
* @param title label which is set
*/
public void titleSetting(Label title) {
title.setAlignment(javafx.geometry.Pos.TOP_CENTER);
title.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
title.setId("Label1");
title.setPadding(new Insets(6.0, 0.0, 0.0, 0.0));
}
/**
* Sets the fightButton and runButton to a specific layout
*/
public void fightAndRunButtonSetting() {
fightButton.setAlignment(javafx.geometry.Pos.CENTER);
fightButton.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER);
fightButton.setId("Button1");
fightButton.setMnemonicParsing(false);
fightButton.setText("Fight");
runButton.setAlignment(javafx.geometry.Pos.CENTER);
runButton.setId("Button2");
runButton.setMnemonicParsing(false);
}
/**
* 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) {
completeWipe();
continueButton.setVisible(true);
fightButton.setVisible(false);
runButton.setVisible(false);
continueButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
/**
* Switches to Taipan Shop scene
* @param event, once button is clicked, executes graphical information
*/
public void handle(ActionEvent event) {
TaipanShopGUI shop = new TaipanShopGUI(getPlayer());
shop.initializeShop(stage);
stage.show();
}
});
}
/** /**
* sets scene and runs stage * sets scene and runs stage
* *
* @param primaryStage the stage in which the scene may be run and switched to * @param primaryStage the stage in which the scene may be run and switched to
*/ */
public void start(Stage primaryStage) { public void start(Stage primaryStage) throws FileNotFoundException{
primaryStage = initializeShip(primaryStage); primaryStage = initializeShip(primaryStage);
primaryStage.show(); primaryStage.show();
} }

View File

@@ -14,6 +14,9 @@ import javafx.geometry.Insets;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random; import java.util.Random;
public class TravelGUI extends Player{ public class TravelGUI extends Player{
@@ -57,7 +60,7 @@ public class TravelGUI extends Player{
* @param stage sets the stage to which we will execute the scene of the TravelGUI class * @param stage sets the stage to which we will execute the scene of the TravelGUI class
* @return stage so that another class can switch to the stage * @return stage so that another class can switch to the stage
*/ */
public Stage initializeTravel(Stage stage){ public Stage initializeTravel(Stage stage) {
//Updates the stage for the first-time you read it //Updates the stage for the first-time you read it
updateStage(); updateStage();
@@ -173,7 +176,11 @@ public class TravelGUI extends Player{
continueButton.setOnAction(event -> { continueButton.setOnAction(event -> {
if(peasantShipScene){ if(peasantShipScene){
ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer()); ShipWarfareGUI ship = new ShipWarfareGUI(getPlayer());
ship.initializeShip(stage); try {
ship.initializeShip(stage);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
stage.show(); stage.show();
} }
else if(shopScene){ else if(shopScene){