Commit 9ecc4f25 authored by Darth Vernon's avatar Darth Vernon

validation fully functional

parent 5fe86d9e
...@@ -97,7 +97,7 @@ public class BSMain extends Application{ ...@@ -97,7 +97,7 @@ public class BSMain extends Application{
@FXML @FXML
void placeAction(ActionEvent event) { void placeAction(ActionEvent event) {
if (!playerG.MoveValidCheck(playerG, playerS.moves)){ if (!playerG.MoveValidCheck(playerG, playerS.moves, playerS)){
admiral.setText("Cordinates are taken. not added to grid"); admiral.setText("Cordinates are taken. not added to grid");
} }
else if (stage0) { else if (stage0) {
...@@ -110,6 +110,7 @@ public class BSMain extends Application{ ...@@ -110,6 +110,7 @@ public class BSMain extends Application{
else if (stage1) { else if (stage1) {
admiral.setText("Your in Battle, try *FIRE*"); admiral.setText("Your in Battle, try *FIRE*");
} }
} }
...@@ -127,7 +128,7 @@ public class BSMain extends Application{ ...@@ -127,7 +128,7 @@ public class BSMain extends Application{
playerB.fire(playerB, computerS, HmnMove, computerB.Score ); playerB.fire(playerB, computerS, HmnMove, computerB.Score );
computerB.fire(playerB, playerS, CmptrMove, playerB.Score); computerB.fire(playerB, playerS, CmptrMove, playerB.Score);
System.out.println("PLAYER SCORE =" + playerB.Score + "/" + computerS.allMoves.size() + " COMPUTER SCORE =" + playerB.Score + "/" + playerS.allMoves.size()); System.out.println("PLAYER SCORE =" + playerB.Score + "/" + computerS.allMoves.size() + " COMPUTER SCORE =" + computerB.Score + "/" + playerS.allMoves.size());
} }
else { else {
......
...@@ -5,35 +5,107 @@ public class BattleClass { ...@@ -5,35 +5,107 @@ public class BattleClass {
int Score; int Score;
public void fire (BattleClass usr, ShipClass opponent, String Cordinates, int score) { public void fire (BattleClass usr, ShipClass opponent, String Coordinates, int score) {
if(opponent.allMoves.contains(Cordinates)) { if(opponent.allMoves.contains(Coordinates)) {
System.out.println("Hit on " + Cordinates); System.out.println("Hit on " + Coordinates);
opponent.allMoves.remove(Cordinates); opponent.allMoves.remove(Coordinates);
usr.Score++; usr.Score++;
ShipCheck(Coordinates, opponent);
} }
else { else {
System.out.println("Miss at " + Cordinates ); System.out.println("Miss at " + Coordinates );
}
}
public static void ShipCheck(String coordinates, ShipClass opponent) {
System.out.println("Called");
if (opponent.aC.contains(coordinates)) {
opponent.aC.remove(coordinates);
if (opponent.aC.isEmpty()) {
System.out.println("Aircarft one is sunk!");
} }
}
if (opponent.bS.contains(coordinates)) {
opponent.bS.remove(coordinates);
if (opponent.bS.isEmpty()) {
System.out.println("BattleShip one is sunk!");
}
} }
if (opponent.bS2.contains(coordinates)) {
public static void sunkCheck() { opponent.bS2.remove(coordinates);
if (opponent.bS2.isEmpty()) {
System.out.println("Battleship two is sunk!");
} }
}
if (opponent.dS.contains(coordinates)) {
opponent.dS.remove(coordinates);
if (opponent.dS.isEmpty()) {
System.out.println("Destroyer one is sunk!");
}
} }
if (opponent.dS2.contains(coordinates)) {
opponent.dS2.remove(coordinates);
if (opponent.dS2.isEmpty()) {
System.out.println("Destroyer two is sunk!");
}
}
if (opponent.pB.contains(coordinates)) {
opponent.pB.remove(coordinates);
if (opponent.pB.isEmpty()) {
System.out.println("Patrol boat one is sunk!");
}
}
if (opponent.pB2.contains(coordinates)) {
opponent.pB2.remove(coordinates);
if (opponent.pB2.isEmpty()) {
System.out.println("Patrol boat two is sunk!");
}
}
if (opponent.pB3.contains(coordinates)) {
opponent.pB3.remove(coordinates);
if (opponent.pB3.isEmpty()) {
System.out.println("Patrol boat three is sunk!");
}
}
}
}
......
...@@ -30,7 +30,7 @@ public class ComputerInput { ...@@ -30,7 +30,7 @@ public class ComputerInput {
BSMain.computerS.ShipPlacer(BSMain.computerS,BSMain.ships.get(i),x,y); BSMain.computerS.ShipPlacer(BSMain.computerS,BSMain.ships.get(i),x,y);
if (!BSMain.computerG.MoveValidCheck(BSMain.computerG, BSMain.computerS.moves) ) { if (!BSMain.computerG.MoveValidCheck(BSMain.computerG, BSMain.computerS.moves, BSMain.computerS) ) {
i--; i--;
...@@ -39,7 +39,7 @@ public class ComputerInput { ...@@ -39,7 +39,7 @@ public class ComputerInput {
} }
System.out.println(BSMain.computerS.allMoves.toString());
} }
} }
...@@ -32,7 +32,7 @@ public class Grid { ...@@ -32,7 +32,7 @@ public class Grid {
return z.Avblcords; return z.Avblcords;
} }
public boolean MoveValidCheck(Grid inputer, ArrayList<String> moves ) { public boolean MoveValidCheck(Grid inputer, ArrayList<String> moves, ShipClass usr ) {
boolean valid = true; boolean valid = true;
...@@ -45,6 +45,13 @@ public class Grid { ...@@ -45,6 +45,13 @@ public class Grid {
valid = false; valid = false;
i = moves.size(); i = moves.size();
System.out.println(move + "Rejected");
for (int j=0 ; j < moves.size() ; j++ ) {
usr.allMoves.remove(moves.get(j));
}
}} }}
......
...@@ -14,7 +14,7 @@ public class ShipClass { ...@@ -14,7 +14,7 @@ public class ShipClass {
ArrayList<ArrayList<String>> shipsHealth = new ArrayList<ArrayList<String>>();
ArrayList<String> moves = new ArrayList<String>(); ArrayList<String> moves = new ArrayList<String>();
ArrayList<String> allMoves = new ArrayList<String>(); ArrayList<String> allMoves = new ArrayList<String>();
...@@ -22,7 +22,7 @@ public class ShipClass { ...@@ -22,7 +22,7 @@ public class ShipClass {
String name; String name;
public void ShipPlacer (ShipClass plyr ,String shipType, String x, String y) { public void ShipPlacer (ShipClass plyr ,String shipType, String x, String y) {
System.out.println("Ships are" + BSMain.computerS.shipsHealth);
int xIndex = Grid.xCordL.indexOf(x); int xIndex = Grid.xCordL.indexOf(x);
//int yIndex = Grid.yCordL.indexOf(y); //int yIndex = Grid.yCordL.indexOf(y);
...@@ -36,14 +36,15 @@ public class ShipClass { ...@@ -36,14 +36,15 @@ public class ShipClass {
for (int i = 0; i < 5 ; i++) { for (int i = 0; i < 5 ; i++) {
String newCord = Grid.xCordL.get(xIndex + i) + y; String newCord = Grid.xCordL.get(xIndex + i) + y;
plyr.aC.add(newCord);
plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.aC = plyr.moves;
plyr.moves = plyr.aC;
plyr.shipsHealth.add(plyr.aC);
System.out.println(plyr.aC.toString()); System.out.println(plyr.aC.toString());
} }
...@@ -52,13 +53,14 @@ public class ShipClass { ...@@ -52,13 +53,14 @@ public class ShipClass {
for (int i = 0; i < 4 ; i++) { for (int i = 0; i < 4 ; i++) {
String newCord = Grid.xCordL.get(xIndex + i) + y; String newCord = Grid.xCordL.get(xIndex + i) + y;
plyr.bS.add(newCord);
plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.moves =plyr.bS; plyr.bS = plyr.moves;
plyr.shipsHealth.add(plyr.bS);
System.out.println(plyr.bS.toString()); System.out.println(plyr.bS.toString());
} }
...@@ -67,26 +69,29 @@ public class ShipClass { ...@@ -67,26 +69,29 @@ public class ShipClass {
for (int i = 0; i < 4 ; i++) { for (int i = 0; i < 4 ; i++) {
String newCord = Grid.xCordL.get(xIndex + i) + y; String newCord = Grid.xCordL.get(xIndex + i) + y;
plyr.bS2.add(newCord);
plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.bS2 = plyr.moves;
plyr.moves = plyr.bS2;
plyr.shipsHealth.add(plyr.bS2);
System.out.println(plyr.bS2.toString()); System.out.println(plyr.bS2.toString());
} }
else if (shipType == BSMain.ships.get(3) ) { else if (shipType == BSMain.ships.get(3) ) {
for (int i = 0; i < 3 ; i++) { for (int i = 0; i < 3 ; i++) {
String newCord = Grid.xCordL.get(xIndex + i) + y; String newCord = Grid.xCordL.get(xIndex + i) + y;
plyr.dS.add(newCord);
plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.dS = plyr.moves;
plyr.moves = plyr.dS;
plyr.shipsHealth.add(plyr.dS);
System.out.println(plyr.dS.toString()); System.out.println(plyr.dS.toString());
} }
...@@ -95,13 +100,14 @@ public class ShipClass { ...@@ -95,13 +100,14 @@ public class ShipClass {
for (int i = 0; i < 3 ; i++) { for (int i = 0; i < 3 ; i++) {
String newCord = Grid.xCordL.get(xIndex + i) + y; String newCord = Grid.xCordL.get(xIndex + i) + y;
plyr.dS2.add(newCord);
plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.dS2 = plyr.moves;
plyr.moves = plyr.dS2;
plyr.shipsHealth.add(plyr.dS2);
System.out.println(plyr.dS2.toString()); System.out.println(plyr.dS2.toString());
} }
...@@ -109,11 +115,12 @@ public class ShipClass { ...@@ -109,11 +115,12 @@ public class ShipClass {
for (int i = 0; i < 2 ; i++) { for (int i = 0; i < 2 ; i++) {
String newCord = Grid.xCordL.get(xIndex + i) + y; String newCord = Grid.xCordL.get(xIndex + i) + y;
plyr.pB.add(newCord);
plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.pB = plyr.moves;
System.out.println(plyr.pB.toString()); System.out.println(plyr.pB.toString());
...@@ -122,13 +129,14 @@ public class ShipClass { ...@@ -122,13 +129,14 @@ public class ShipClass {
for (int i = 0; i < 2 ; i++) { for (int i = 0; i < 2 ; i++) {
String newCord = Grid.xCordL.get(xIndex + i) + y; String newCord = Grid.xCordL.get(xIndex + i) + y;
plyr.pB2.add(newCord);
plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.pB2 = plyr.moves;
plyr.moves = plyr.pB2 ;
plyr.shipsHealth.add(plyr.pB2);
System.out.println(plyr.pB2.toString()); System.out.println(plyr.pB2.toString());
} }
...@@ -137,13 +145,14 @@ public class ShipClass { ...@@ -137,13 +145,14 @@ public class ShipClass {
for (int i = 0; i < 2 ; i++) { for (int i = 0; i < 2 ; i++) {
String newCord = Grid.xCordL.get(xIndex + i) + y; String newCord = Grid.xCordL.get(xIndex + i) + y;
plyr.pB3.add(newCord);
plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.pB3 = plyr.moves;
plyr.moves = plyr.pB3;
plyr.shipsHealth.add(plyr.pB3);
System.out.println(plyr.pB3.toString()); System.out.println(plyr.pB3.toString());
......
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