Commit 96b49fcb authored by Darth Vernon's avatar Darth Vernon

GUI ERROR

parent 7ca9d1b4
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
<children> <children>
<ChoiceBox fx:id="DPx" layoutX="164.0" layoutY="617.0" prefHeight="28.0" prefWidth="184.0" /> <ChoiceBox fx:id="DPx" layoutX="164.0" layoutY="617.0" prefHeight="28.0" prefWidth="184.0" />
<ChoiceBox fx:id="shipSelection" layoutX="164.0" layoutY="645.0" prefHeight="28.0" prefWidth="184.0" /> <ChoiceBox fx:id="shipSelection" layoutX="164.0" layoutY="645.0" prefHeight="28.0" prefWidth="184.0" />
<Label fx:id="admiral" layoutX="165.0" layoutY="600.0" prefHeight="17.0" prefWidth="734.0" text="Admiral Nutsey : &quot;Place your ships Captain!!!&quot;" /> <Label fx:id="admiral" layoutX="165.0" layoutY="600.0" prefHeight="17.0" prefWidth="368.0" text="Admiral Nutsey : &quot;Place your ships Captain!!!&quot;" />
<ChoiceBox fx:id="DPy" layoutX="348.0" layoutY="617.0" prefHeight="28.0" prefWidth="184.0" /> <ChoiceBox fx:id="DPy" layoutX="348.0" layoutY="617.0" prefHeight="28.0" prefWidth="184.0" />
<Label fx:id="error" alignment="CENTER" contentDisplay="CENTER" layoutX="348.0" layoutY="645.0" prefHeight="28.0" prefWidth="184.0" text="Stage : Preperation" textAlignment="JUSTIFY" wrapText="true" /> <Label fx:id="stage" alignment="CENTER" contentDisplay="CENTER" layoutX="348.0" layoutY="645.0" prefHeight="28.0" prefWidth="184.0" text="Stage : Preperation" textAlignment="JUSTIFY" wrapText="true" />
<Button fx:id="place" layoutX="716.0" layoutY="617.0" mnemonicParsing="false" onAction="#placeAction" prefHeight="28.0" prefWidth="184.0" text="*PLACE A SHIP*" textAlignment="CENTER" /> <Button fx:id="place" layoutX="716.0" layoutY="617.0" mnemonicParsing="false" onAction="#placeAction" prefHeight="28.0" prefWidth="184.0" text="*PLACE A SHIP*" textAlignment="CENTER" />
<Button fx:id="fire" layoutX="532.0" layoutY="617.0" mnemonicParsing="false" onAction="#fireAction" prefHeight="28.0" prefWidth="184.0" text="*FIRE*" /> <Button fx:id="fire" layoutX="532.0" layoutY="617.0" mnemonicParsing="false" onAction="#fireAction" prefHeight="28.0" prefWidth="184.0" text="*FIRE*" />
<Button fx:id="quit" layoutX="532.0" layoutY="646.0" mnemonicParsing="false" onAction="#quitAction" prefHeight="25.0" prefWidth="184.0" text="*QUIT*" /> <Button fx:id="quit" layoutX="532.0" layoutY="646.0" mnemonicParsing="false" onAction="#quitAction" prefHeight="25.0" prefWidth="184.0" text="*QUIT*" />
...@@ -281,6 +281,8 @@ ...@@ -281,6 +281,8 @@
<Label fx:id="c0A" layoutX="460.0" layoutY="342.0" prefHeight="67.0" prefWidth="53.0" text="Label" /> <Label fx:id="c0A" layoutX="460.0" layoutY="342.0" prefHeight="67.0" prefWidth="53.0" text="Label" />
</children> </children>
</GridPane> </GridPane>
<Label fx:id="occupiedSpace" layoutX="165.0" layoutY="690.0" prefHeight="17.0" prefWidth="734.0" text="Your ships are :" />
<Label fx:id="EnemyHM" layoutX="532.0" layoutY="600.0" prefHeight="17.0" prefWidth="368.0" text="Computer: Prepare to die!" />
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>
......
...@@ -29,6 +29,8 @@ public class BSMain extends Application{ ...@@ -29,6 +29,8 @@ public class BSMain extends Application{
@FXML public ChoiceBox<String> DPx; @FXML public ChoiceBox<String> DPx;
@FXML public ChoiceBox<String> DPy; @FXML public ChoiceBox<String> DPy;
@FXML public ChoiceBox<String> shipSelection; @FXML public ChoiceBox<String> shipSelection;
@FXML public Label occupiedSpace;
@FXML public Label EnemyHM;
@FXML private Button place; @FXML private Button place;
...@@ -36,7 +38,7 @@ public class BSMain extends Application{ ...@@ -36,7 +38,7 @@ public class BSMain extends Application{
@FXML private Button battleStage; @FXML private Button battleStage;
@FXML private Button quit; @FXML private Button quit;
@FXML public Label error; @FXML public Label stage;
@FXML public Label admiral; @FXML public Label admiral;
@FXML public Label status; @FXML public Label status;
...@@ -340,12 +342,19 @@ public class BSMain extends Application{ ...@@ -340,12 +342,19 @@ public class BSMain extends Application{
void placeAction(ActionEvent event) { void placeAction(ActionEvent event) {
if (stage0) { if (stage0) {
String response = "";
admiral.setText("Admiral Nutsey: Ship placed at " + (playerS.ShipPlacer(playerS,ship, x, y).toString()) );
if (!playerS.ShipPlacer(playerS,ship, x, y).isEmpty()) {
response = playerS.moves.toString();
admiral.setText("Admiral Nutsey: Ship placed at " + response);
playerLabels[1].setText("Ship placed");
}
else {
admiral.setText("Admiral: Ship type is already Placed");
}
if (!playerG.MoveValidCheck(playerG, playerS.moves, playerS, ship)){ if (!playerG.MoveValidCheck(playerG, playerS.moves, playerS, ship)){
admiral.setText("Admiral Nutsey: Space occupied"); admiral.setText("Admiral Nutsey: Space occupied");
...@@ -355,22 +364,28 @@ public class BSMain extends Application{ ...@@ -355,22 +364,28 @@ public class BSMain extends Application{
else if (stage1) { else if (stage1) {
admiral.setText("Admiral Nutsey: Your in Battle, try *FIRE*"); admiral.setText("Admiral Nutsey: Your in Battle, try *FIRE*");
} }
occupiedSpace.setText(playerS.allMoves.toString());
} }
@FXML @FXML
void fireAction(ActionEvent event) { void fireAction(ActionEvent event) {
if(playerS.allMoves.isEmpty()) { if(playerS.allMoves.isEmpty()) {
Boolean win = true;
stage1 = false; stage1 = false;
admiral.setText("Admiral Nutsey: You have lost :( "); admiral.setText("Admiral Nutsey: You have lost :( ");
EnemyHM.setText(ComputerInput.talk(win));
stage.setText("Stage: GAME OVER");
} }
else if(computerS.allMoves.isEmpty()) { else if(computerS.allMoves.isEmpty()) {
Boolean win = false;
stage1 = false; stage1 = false;
admiral.setText("Admiral Nutsey: You have won!!! "); admiral.setText("Admiral Nutsey: You have won!!!");
EnemyHM.setText(ComputerInput.talk(win));
} }
else if (stage1) { else if (stage1) {
...@@ -380,10 +395,22 @@ public class BSMain extends Application{ ...@@ -380,10 +395,22 @@ public class BSMain extends Application{
+ (String) ComputerInput.CoOrdRandomiser().get(1); + (String) ComputerInput.CoOrdRandomiser().get(1);
if (playerB.fire(computerS, HmnMove)) { if (playerB.fire(computerS, HmnMove)) {
admiral.setText(BattleClass.ShipCheck(HmnMove, computerS)); admiral.setText("Player has " + BattleClass.ShipCheck(HmnMove, computerS));
}
else if (!playerB.fire(computerS, HmnMove)) {
admiral.setText("Player has missed at " + HmnMove);
} }
if (computerB.fire(playerS, CmptrMove)) { if (computerB.fire(playerS, CmptrMove)) {
admiral.setText(BattleClass.ShipCheck(CmptrMove, playerS)); EnemyHM.setText("Computer: I have hit " + BattleClass.ShipCheck(CmptrMove, playerS));
}
else if (!computerB.fire(playerS, CmptrMove)) {
EnemyHM.setText("Computer: I have missed at " + CmptrMove);
} }
status.setText("Computer status: " + computerS.allMoves.size() + " Player Status: " + playerS.allMoves.size()); status.setText("Computer status: " + computerS.allMoves.size() + " Player Status: " + playerS.allMoves.size());
...@@ -393,6 +420,8 @@ public class BSMain extends Application{ ...@@ -393,6 +420,8 @@ public class BSMain extends Application{
admiral.setText("Place all ships before firing"); admiral.setText("Place all ships before firing");
} }
occupiedSpace.setText(playerS.allMoves.toString());
} }
@FXML @FXML
...@@ -400,6 +429,8 @@ public class BSMain extends Application{ ...@@ -400,6 +429,8 @@ public class BSMain extends Application{
stage0 = false; stage0 = false;
stage1 = true; stage1 = true;
admiral.setText("Admiral Nutsey: Fire on the enemy"); admiral.setText("Admiral Nutsey: Fire on the enemy");
stage.setText("Stage: Battle");
} }
@FXML @FXML
......
...@@ -5,14 +5,14 @@ public class BattleClass { ...@@ -5,14 +5,14 @@ public class BattleClass {
public Boolean fire ( ShipClass opponent, String Coordinates) { public Boolean fire ( ShipClass opponent, String Coordinates) {
Boolean hit = false; Boolean hit = false;
if(opponent.allMoves.contains(Coordinates)) { if(opponent.allMoves.contains(Coordinates)) {
System.out.println("Hit on " + Coordinates);
opponent.allMoves.remove(Coordinates); opponent.allMoves.remove(Coordinates);
hit = true; hit = true;
...@@ -32,7 +32,7 @@ public class BattleClass { ...@@ -32,7 +32,7 @@ public class BattleClass {
opponent.aC.remove(coordinates); opponent.aC.remove(coordinates);
if (opponent.aC.isEmpty()) { if (opponent.aC.isEmpty()) {
response = ("Aircarft one is sunk!"); response = ("sunk Aircarft one");
} }
} }
...@@ -41,7 +41,7 @@ public class BattleClass { ...@@ -41,7 +41,7 @@ public class BattleClass {
opponent.bS.remove(coordinates); opponent.bS.remove(coordinates);
if (opponent.bS.isEmpty()) { if (opponent.bS.isEmpty()) {
response = ("BattleShip one is sunk!"); response = ("sunk BattleShip");
} }
} }
...@@ -50,7 +50,7 @@ public class BattleClass { ...@@ -50,7 +50,7 @@ public class BattleClass {
opponent.bS2.remove(coordinates); opponent.bS2.remove(coordinates);
if (opponent.bS2.isEmpty()) { if (opponent.bS2.isEmpty()) {
response = ("Battleship two is sunk!"); response = ("sunk Battleship two");
} }
} }
...@@ -59,7 +59,7 @@ public class BattleClass { ...@@ -59,7 +59,7 @@ public class BattleClass {
opponent.dS.remove(coordinates); opponent.dS.remove(coordinates);
if (opponent.dS.isEmpty()) { if (opponent.dS.isEmpty()) {
response = ("Destroyer one is sunk!"); response = ("sunk Destroyer one");
} }
} }
...@@ -68,7 +68,7 @@ public class BattleClass { ...@@ -68,7 +68,7 @@ public class BattleClass {
opponent.dS2.remove(coordinates); opponent.dS2.remove(coordinates);
if (opponent.dS2.isEmpty()) { if (opponent.dS2.isEmpty()) {
response = ("Destroyer two is sunk!"); response = ("sunk Destroyer two");
} }
} }
...@@ -77,7 +77,7 @@ public class BattleClass { ...@@ -77,7 +77,7 @@ public class BattleClass {
opponent.pB.remove(coordinates); opponent.pB.remove(coordinates);
if (opponent.pB.isEmpty()) { if (opponent.pB.isEmpty()) {
response = ("Patrol boat one is sunk!"); response = ("sunk Patrol boat!");
} }
} }
...@@ -86,7 +86,7 @@ public class BattleClass { ...@@ -86,7 +86,7 @@ public class BattleClass {
opponent.pB2.remove(coordinates); opponent.pB2.remove(coordinates);
if (opponent.pB2.isEmpty()) { if (opponent.pB2.isEmpty()) {
response = ("Patrol boat two is sunk!"); response = ("sunk Patrol boat two");
} }
} }
...@@ -95,7 +95,7 @@ public class BattleClass { ...@@ -95,7 +95,7 @@ public class BattleClass {
opponent.pB3.remove(coordinates); opponent.pB3.remove(coordinates);
if (opponent.pB3.isEmpty()) { if (opponent.pB3.isEmpty()) {
response = ("Patrol boat three is sunk!"); response = ("sunk Patrol boat three");
} }
} }
return response; return response;
......
...@@ -2,6 +2,21 @@ import java.util.ArrayList; ...@@ -2,6 +2,21 @@ import java.util.ArrayList;
import java.util.Random; import java.util.Random;
public class ComputerInput { public class ComputerInput {
static String cmptrWin[] = {"DIE","Yesss","To easy"};
static String cmptrLose[] = {"Noooo","How can this be","Cheat!"};
Boolean win = false;
public static String talk(Boolean win) {
String speach="";
Random rand = new Random();
if (win) {
speach = cmptrWin[rand.nextInt(2)];
}
else {
speach = cmptrLose[rand.nextInt(2)];
}
return speach;
}
public static ArrayList<String> CoOrdRandomiser() { public static ArrayList<String> CoOrdRandomiser() {
ArrayList<String> coOrd = new ArrayList<String>(); ArrayList<String> coOrd = new ArrayList<String>();
...@@ -18,6 +33,7 @@ public class ComputerInput { ...@@ -18,6 +33,7 @@ public class ComputerInput {
} }
public static void cmptrMoveGen() { public static void cmptrMoveGen() {
......
...@@ -64,8 +64,9 @@ public class Grid { ...@@ -64,8 +64,9 @@ public class Grid {
} }
int index = BSMain.ships.indexOf(shipType); int index = BSMain.ships.indexOf(shipType);
if(!(index == -1)) {
usr.shipsPlaced[index] = true; usr.shipsPlaced[index] = true;
}
} }
return valid; return valid;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment