Commit 3914ec7e authored by Darth Vernon's avatar Darth Vernon

validation sorted, i think, plz be sorted

parent 9ecc4f25
...@@ -83,10 +83,12 @@ public class BSMain extends Application{ ...@@ -83,10 +83,12 @@ public class BSMain extends Application{
DPx.getSelectionModel().selectedItemProperty().addListener((ObservableValue, oldValue, newValue) -> { DPx.getSelectionModel().selectedItemProperty().addListener((ObservableValue, oldValue, newValue) -> {
x=(newValue.toString()); x=(newValue.toString());
System.out.println(x);
}); });
DPy.getSelectionModel().selectedItemProperty().addListener((ObservableValue, oldValue, newValue) -> { DPy.getSelectionModel().selectedItemProperty().addListener((ObservableValue, oldValue, newValue) -> {
y=(newValue.toString()); y=(newValue.toString());
System.out.println(y);
}); });
shipSelection.getSelectionModel().selectedItemProperty().addListener((ObservableValue, oldValue, newValue) -> { shipSelection.getSelectionModel().selectedItemProperty().addListener((ObservableValue, oldValue, newValue) -> {
...@@ -97,14 +99,15 @@ public class BSMain extends Application{ ...@@ -97,14 +99,15 @@ public class BSMain extends Application{
@FXML @FXML
void placeAction(ActionEvent event) { void placeAction(ActionEvent event) {
if (!playerG.MoveValidCheck(playerG, playerS.moves, playerS)){
admiral.setText("Cordinates are taken. not added to grid");
}
else if (stage0) {
playerS.ShipPlacer(playerS,ship, x, y); if (stage0) {
playerS.ShipPlacer(playerS,ship, x, y);
admiral.setText("Admiral Nutsey: Ship placed at " + x + y); admiral.setText("Admiral Nutsey: Ship placed at " + x + y);
if (!playerG.MoveValidCheck(playerG, playerS.moves, playerS, ship)){
admiral.setText("Cordinates are taken. not added to grid");
}
} }
else if (stage1) { else if (stage1) {
...@@ -126,9 +129,9 @@ public class BSMain extends Application{ ...@@ -126,9 +129,9 @@ public class BSMain extends Application{
String CmptrMove = (String) ComputerInput.CoOrdRandomiser().get(0) String CmptrMove = (String) ComputerInput.CoOrdRandomiser().get(0)
+ (String) ComputerInput.CoOrdRandomiser().get(1); + (String) ComputerInput.CoOrdRandomiser().get(1);
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 =" + computerB.Score + "/" + playerS.allMoves.size()); System.out.println(computerS.allMoves.size() + "Left of Computer ships" + playerS.allMoves.size() + "Left of Player ships");
} }
else { else {
......
...@@ -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, BSMain.computerS) ) { if (!BSMain.computerG.MoveValidCheck(BSMain.computerG, BSMain.computerS.moves, BSMain.computerS,BSMain.ships.get(i)) ) {
i--; i--;
......
...@@ -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, ShipClass usr ) { public boolean MoveValidCheck(Grid inputer, ArrayList<String> moves, ShipClass usr, String shipType ) {
boolean valid = true; boolean valid = true;
...@@ -62,6 +62,10 @@ public class Grid { ...@@ -62,6 +62,10 @@ public class Grid {
inputer.Avblcords.remove(moves.get(i)); inputer.Avblcords.remove(moves.get(i));
} }
int index = BSMain.ships.indexOf(shipType);
usr.shipsPlaced[index] = true;
} }
return valid; return valid;
} }
......
...@@ -12,6 +12,17 @@ public class ShipClass { ...@@ -12,6 +12,17 @@ public class ShipClass {
ArrayList<String> pB2 = new ArrayList<String>(); ArrayList<String> pB2 = new ArrayList<String>();
ArrayList<String> pB3 = new ArrayList<String>(); ArrayList<String> pB3 = new ArrayList<String>();
Boolean aCB = false;
Boolean dSB = false;
Boolean dS2B = false;
Boolean bSB = false;
Boolean bS2B = false;
Boolean pBB = false;
Boolean pB2B = false;
Boolean pB3B = false;
Boolean shipsPlaced[] = {aCB,dSB,dS2B,bSB,bS2B,pBB,pB2B,pB3B};
...@@ -32,7 +43,7 @@ public class ShipClass { ...@@ -32,7 +43,7 @@ public class ShipClass {
System.out.println(shipType + " "+ x + " " + y); System.out.println(shipType + " "+ x + " " + y);
System.out.println(allMoves.toString()); System.out.println(allMoves.toString());
if (shipType == BSMain.ships.get(0) ) { if (shipType == BSMain.ships.get(0) && !plyr.shipsPlaced[0]) {
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;
...@@ -49,7 +60,7 @@ public class ShipClass { ...@@ -49,7 +60,7 @@ public class ShipClass {
} }
else if (shipType == BSMain.ships.get(1) ) { else if (shipType == BSMain.ships.get(1) && !plyr.shipsPlaced[1] ) {
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;
...@@ -65,7 +76,7 @@ public class ShipClass { ...@@ -65,7 +76,7 @@ public class ShipClass {
} }
else if (shipType == BSMain.ships.get(2) ) { else if (shipType == BSMain.ships.get(2) && !plyr.shipsPlaced[2]) {
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;
...@@ -80,7 +91,7 @@ public class ShipClass { ...@@ -80,7 +91,7 @@ public class ShipClass {
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)&& !plyr.shipsPlaced[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;
...@@ -96,7 +107,7 @@ public class ShipClass { ...@@ -96,7 +107,7 @@ public class ShipClass {
} }
else if (shipType == BSMain.ships.get(4) ) { else if (shipType == BSMain.ships.get(4)&& !plyr.shipsPlaced[4]) {
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;
...@@ -111,7 +122,7 @@ public class ShipClass { ...@@ -111,7 +122,7 @@ public class ShipClass {
System.out.println(plyr.dS2.toString()); System.out.println(plyr.dS2.toString());
} }
else if (shipType == BSMain.ships.get(5) ) { else if (shipType == BSMain.ships.get(5) && !plyr.shipsPlaced[5] ) {
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;
...@@ -125,7 +136,7 @@ public class ShipClass { ...@@ -125,7 +136,7 @@ public class ShipClass {
System.out.println(plyr.pB.toString()); System.out.println(plyr.pB.toString());
} }
else if (shipType == BSMain.ships.get(6) ) { else if (shipType == BSMain.ships.get(6) && !plyr.shipsPlaced[6]) {
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;
...@@ -141,7 +152,7 @@ public class ShipClass { ...@@ -141,7 +152,7 @@ public class ShipClass {
} }
else if (shipType == BSMain.ships.get(7) ) { else if (shipType == BSMain.ships.get(7) && !plyr.shipsPlaced[7]) {
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;
...@@ -160,7 +171,7 @@ public class ShipClass { ...@@ -160,7 +171,7 @@ public class ShipClass {
else { else {
System.out.println("Type of ship not valid"); System.out.println("Type of ship not valid or already placed for that type");
} }
} }
......
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