Commit d2bd455e authored by Darth Vernon's avatar Darth Vernon

placement modified to work with sunk - currently works.

parent 3914ec7e
...@@ -44,7 +44,7 @@ public class BSMain extends Application{ ...@@ -44,7 +44,7 @@ public class BSMain extends Application{
static Grid playerG = new Grid(); static Grid playerG = new Grid();
static Grid computerG = new Grid(); static Grid computerG = new Grid();
static ShipClass playerS = new ShipClass(); ShipClass playerS = new ShipClass();
static ShipClass computerS = new ShipClass(); static ShipClass computerS = new ShipClass();
static BattleClass playerB = new BattleClass(); static BattleClass playerB = new BattleClass();
static BattleClass computerB = new BattleClass(); static BattleClass computerB = new BattleClass();
...@@ -129,15 +129,27 @@ public class BSMain extends Application{ ...@@ -129,15 +129,27 @@ 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(computerS, HmnMove);
computerB.fire(playerB, playerS, CmptrMove, playerB.Score); computerB.fire(playerS, CmptrMove);
System.out.println(computerS.allMoves.size() + "Left of Computer ships" + playerS.allMoves.size() + "Left of Player ships"); System.out.println(computerS.allMoves.size() + "Left of Computer ships" + playerS.allMoves.size() + "Left of Player ships");
} }
else { else if (stage0) {
admiral.setText("Place all ships before firing"); admiral.setText("Place all ships before firing");
} }
else if(playerS.allMoves.isEmpty()) {
stage1 = false;
admiral.setText("You have lost :( ");
}
else if(computerS.allMoves.isEmpty()) {
stage1 = false;
admiral.setText("You have lost won!!! ");
}
else {
error.setText("The Game has ended, press *QUIT*");
}
} }
@FXML @FXML
...@@ -164,8 +176,7 @@ public class BSMain extends Application{ ...@@ -164,8 +176,7 @@ public class BSMain extends Application{
playerG.CoOrdGen(playerG); playerG.CoOrdGen(playerG);
computerG.CoOrdGen(computerG); computerG.CoOrdGen(computerG);
ComputerInput.cmptrMoveGen(); ComputerInput.cmptrMoveGen();
playerS.name = "PLAYER";
computerS.name = "COMPUTER";
launch(args); launch(args);
......
public class BattleClass { public class BattleClass {
Boolean win = false;
int Score;
public void fire (BattleClass usr, ShipClass opponent, String Coordinates, int score) {
public void fire ( ShipClass opponent, String Coordinates) {
...@@ -14,7 +14,6 @@ public class BattleClass { ...@@ -14,7 +14,6 @@ public class BattleClass {
System.out.println("Hit on " + Coordinates); System.out.println("Hit on " + Coordinates);
opponent.allMoves.remove(Coordinates); opponent.allMoves.remove(Coordinates);
usr.Score++;
ShipCheck(Coordinates, opponent); ShipCheck(Coordinates, opponent);
...@@ -28,9 +27,9 @@ public class BattleClass { ...@@ -28,9 +27,9 @@ public class BattleClass {
} }
public static void ShipCheck(String coordinates, ShipClass opponent) { public void ShipCheck(String coordinates, ShipClass opponent) {
System.out.println("Called");
if (opponent.aC.contains(coordinates)) { if (opponent.aC.contains(coordinates)) {
opponent.aC.remove(coordinates); opponent.aC.remove(coordinates);
...@@ -40,7 +39,7 @@ public class BattleClass { ...@@ -40,7 +39,7 @@ public class BattleClass {
} }
} }
if (opponent.bS.contains(coordinates)) { else if (opponent.bS.contains(coordinates)) {
opponent.bS.remove(coordinates); opponent.bS.remove(coordinates);
...@@ -49,7 +48,7 @@ public class BattleClass { ...@@ -49,7 +48,7 @@ public class BattleClass {
} }
} }
if (opponent.bS2.contains(coordinates)) { else if (opponent.bS2.contains(coordinates)) {
opponent.bS2.remove(coordinates); opponent.bS2.remove(coordinates);
...@@ -58,7 +57,7 @@ public class BattleClass { ...@@ -58,7 +57,7 @@ public class BattleClass {
} }
} }
if (opponent.dS.contains(coordinates)) { else if (opponent.dS.contains(coordinates)) {
opponent.dS.remove(coordinates); opponent.dS.remove(coordinates);
...@@ -67,7 +66,7 @@ public class BattleClass { ...@@ -67,7 +66,7 @@ public class BattleClass {
} }
} }
if (opponent.dS2.contains(coordinates)) { else if (opponent.dS2.contains(coordinates)) {
opponent.dS2.remove(coordinates); opponent.dS2.remove(coordinates);
...@@ -76,7 +75,7 @@ public class BattleClass { ...@@ -76,7 +75,7 @@ public class BattleClass {
} }
} }
if (opponent.pB.contains(coordinates)) { else if (opponent.pB.contains(coordinates)) {
opponent.pB.remove(coordinates); opponent.pB.remove(coordinates);
...@@ -85,7 +84,7 @@ public class BattleClass { ...@@ -85,7 +84,7 @@ public class BattleClass {
} }
} }
if (opponent.pB2.contains(coordinates)) { else if (opponent.pB2.contains(coordinates)) {
opponent.pB2.remove(coordinates); opponent.pB2.remove(coordinates);
...@@ -94,7 +93,7 @@ public class BattleClass { ...@@ -94,7 +93,7 @@ public class BattleClass {
} }
} }
if (opponent.pB3.contains(coordinates)) { else if (opponent.pB3.contains(coordinates)) {
opponent.pB3.remove(coordinates); opponent.pB3.remove(coordinates);
......
...@@ -34,6 +34,8 @@ public class ShipClass { ...@@ -34,6 +34,8 @@ public class ShipClass {
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("this one " + plyr.aC.toString() + plyr.dS.toString() + plyr.dS2.toString());
int xIndex = Grid.xCordL.indexOf(x); int xIndex = Grid.xCordL.indexOf(x);
//int yIndex = Grid.yCordL.indexOf(y); //int yIndex = Grid.yCordL.indexOf(y);
...@@ -47,13 +49,13 @@ public class ShipClass { ...@@ -47,13 +49,13 @@ 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.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.aC = plyr.moves;
System.out.println(plyr.aC.toString()); System.out.println(plyr.aC.toString());
...@@ -64,13 +66,13 @@ public class ShipClass { ...@@ -64,13 +66,13 @@ 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.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.bS = plyr.moves;
System.out.println(plyr.bS.toString()); System.out.println(plyr.bS.toString());
...@@ -80,12 +82,12 @@ public class ShipClass { ...@@ -80,12 +82,12 @@ 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.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.bS2 = plyr.moves;
...@@ -95,12 +97,12 @@ public class ShipClass { ...@@ -95,12 +97,12 @@ 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.dS.add(newCord);
plyr.moves.add(newCord); plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.dS = plyr.moves;
System.out.println(plyr.dS.toString()); System.out.println(plyr.dS.toString());
...@@ -111,12 +113,12 @@ public class ShipClass { ...@@ -111,12 +113,12 @@ 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.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.dS2 = plyr.moves;
System.out.println(plyr.dS2.toString()); System.out.println(plyr.dS2.toString());
...@@ -126,12 +128,12 @@ public class ShipClass { ...@@ -126,12 +128,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.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());
...@@ -140,12 +142,12 @@ public class ShipClass { ...@@ -140,12 +142,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.pB2.add(newCord);
plyr.moves.add(newCord); plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.pB2 = plyr.moves;
System.out.println(plyr.pB2.toString()); System.out.println(plyr.pB2.toString());
...@@ -156,12 +158,12 @@ public class ShipClass { ...@@ -156,12 +158,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.pB3.add(newCord);
plyr.moves.add(newCord); plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
} }
plyr.pB3 = plyr.moves;
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