Commit 96685993 authored by Darth Vernon's avatar Darth Vernon

Ship Class comments

parent c6018061
...@@ -3,7 +3,7 @@ import java.util.ArrayList; ...@@ -3,7 +3,7 @@ import java.util.ArrayList;
public class ShipClass { public class ShipClass {
ArrayList<String> aC = new ArrayList<String>(); ArrayList<String> aC = new ArrayList<String>(); //Holds coordinates of each ship
ArrayList<String> dS = new ArrayList<String>(); ArrayList<String> dS = new ArrayList<String>();
ArrayList<String> dS2 = new ArrayList<String>(); ArrayList<String> dS2 = new ArrayList<String>();
ArrayList<String> bS = new ArrayList<String>(); ArrayList<String> bS = new ArrayList<String>();
...@@ -12,7 +12,7 @@ public class ShipClass { ...@@ -12,7 +12,7 @@ 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 aCB = false; //Booleans to see if a ship is placed or not.
Boolean dSB = false; Boolean dSB = false;
Boolean dS2B = false; Boolean dS2B = false;
Boolean bSB = false; Boolean bSB = false;
...@@ -21,16 +21,16 @@ public class ShipClass { ...@@ -21,16 +21,16 @@ public class ShipClass {
Boolean pB2B = false; Boolean pB2B = false;
Boolean pB3B = false; Boolean pB3B = false;
Boolean shipsPlaced[] = {aCB,dSB,dS2B,bSB,bS2B,pBB,pB2B,pB3B}; Boolean shipsPlaced[] = {aCB,dSB,dS2B,bSB,bS2B,pBB,pB2B,pB3B}; //list of booleans for easier access.
ArrayList<String> moves = new ArrayList<String>(); ArrayList<String> moves = new ArrayList<String>(); //Holds current set of moves
ArrayList<String> allMoves = new ArrayList<String>(); ArrayList<String> allMoves = new ArrayList<String>(); //Holds all placements of player made
String name;
public ArrayList ShipPlacer (ShipClass plyr ,String shipType, String x, String y) { public ArrayList ShipPlacer (ShipClass plyr ,String shipType, String x, String y) {
...@@ -39,17 +39,18 @@ public class ShipClass { ...@@ -39,17 +39,18 @@ public class ShipClass {
int xIndex = Grid.xCordL.indexOf(x); int xIndex = Grid.xCordL.indexOf(x);
//int yIndex = Grid.yCordL.indexOf(y); //int yIndex = Grid.yCordL.indexOf(y);
plyr.moves.clear(); plyr.moves.clear(); // Moves are reset every time method is called, to ensure only current placements are stored.
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) && !plyr.shipsPlaced[0]) { //Each of these if statements varies only by the ship it refers to.
if (shipType == BSMain.ships.get(0) && !plyr.shipsPlaced[0]) { //If users ship input is equal the first index and that ship has not been placed.
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; //increase x coordinate by i. This creates the span of the ship.
plyr.aC.add(newCord); plyr.aC.add(newCord); //Add to relevant lists.
plyr.moves.add(newCord); plyr.moves.add(newCord);
plyr.allMoves.add(newCord); plyr.allMoves.add(newCord);
...@@ -176,7 +177,7 @@ public class ShipClass { ...@@ -176,7 +177,7 @@ public class ShipClass {
System.out.println("Type of ship not valid or already placed for that type"); System.out.println("Type of ship not valid or already placed for that type");
} }
return moves; return moves; // returns empty if selected ship is placed.
} }
} }
......
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