Commit 85916d50 authored by Darth Vernon's avatar Darth Vernon

Grid comments

parent a0fb468d
......@@ -2,9 +2,9 @@ import java.util.ArrayList;
public class Grid {
ArrayList<String> Avblcords = new ArrayList<String>();
static ArrayList<String> xCordL = new ArrayList<String>();
static ArrayList<String> yCordL = new ArrayList<String>();
ArrayList<String> Avblcords = new ArrayList<String>(); //Holds coordinates of which user is allowed to use.
static ArrayList<String> xCordL = new ArrayList<String>(); //Holds X coordinates
static ArrayList<String> yCordL = new ArrayList<String>(); //Holds Y coordinates
static String xCord[] = {"0","1","2","3","4","5","6","7","8","9"};
static String yCord[] = {"A","B","C","D","E","F","G","H","I","J"};
......@@ -12,9 +12,9 @@ public class Grid {
public ArrayList<String> CoOrdGen(Grid z) {
public ArrayList<String> CoOrdGen(Grid z) { //Takes a grid object and generates a list of available coordinates.
for (int i = 0 ; i < 10 ; i ++ ) {
for (int i = 0 ; i < 10 ; i ++ ) { //Loads arrays into more useful ArrayLists.
yCordL.add(yCord[i]);
xCordL.add(xCord[i]);
......@@ -22,7 +22,7 @@ public class Grid {
}
for (int i = 0 ; i < 10 ; i ++ ) {
for (int i = 0 ; i < 10 ; i ++ ) { //Loops through both x and y lists to generate the entire grid.
String letter = yCord[i];
for (int j = 0 ; j < 10 ; j ++ ) {
String number = xCord[j];
......@@ -34,21 +34,21 @@ public class Grid {
public boolean MoveValidCheck(Grid inputer, ArrayList<String> moves, ShipClass usr, String shipType ) {
boolean valid = true;
boolean valid = true; //Coordinates assumed to be valid until proven otherwise.
for (int i=0 ; i < moves.size() ; i++ ) {
String move = (String) moves.get(i);
String move = (String) moves.get(i); //Takes each move from moves to test individually.
if (!inputer.Avblcords.contains(move) && (valid)) {
if (!inputer.Avblcords.contains(move) && (valid)) { //If move is not in the grid objects available coordinates it is rejected.
valid = false;
valid = false; //Stops all checking and renders entire list of moves as invalid.
i = moves.size();
System.out.println(move + "Rejected");
for (int j=0 ; j < moves.size() ; j++ ) {
usr.allMoves.remove(moves.get(j));
usr.allMoves.remove(moves.get(j)); //Invalid moves are removed from ships class objects All moves list.
}
......@@ -59,13 +59,13 @@ public class Grid {
for(int i=0 ; i < moves.size() ; i++ ) {
inputer.Avblcords.remove(moves.get(i));
inputer.Avblcords.remove(moves.get(i)); //Removes from available Coordinates so, they can't be used again.
}
int index = BSMain.ships.indexOf(shipType);
if(!(index == -1)) {
usr.shipsPlaced[index] = true;
if(!(index == -1)) { //Averts out of bounds error.
usr.shipsPlaced[index] = true; //Sets as true so that ship can't be placed again.
}
}
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