Unique data check in a 2d array using objects

Okay, so, as anyone can tell by going through my recent question history, I have been asking a lot of questions in regards to objects, placement in an array, and checking to see if that data is unique. This is sort of the culmination of all the problems leading up to this point.

I have a 2d character array(10x10) that is going to be filled with '0', Each play "piece" is going to occupy a location on this 2d array.

The shapes of the pieces are 2x1 (2 long, 1 wide), 3x1, 4x1, 5x1. My issue here is checking to see whether or not I can place an entire piece down without causing a collision(with another piece) on my grid or not.

I've been playing around with different ways of doing this, for now I have this:

if (SelectedBoat.orientation==1){ // Is vertical
for (j=0; j<SelectedBoat.health; j++){
if (arrayPLAYER[SelectedBoat.location[0]][SelectedBoat.location[1]] !='0'){
System.out.println("This piece collides at location: "+ arrayPLAYER

for (k=0; k<SelectedBoat.health; k++){
arrayPLAYER[SelectedBoat.location[0]][SelectedBoat.location[1]] = SelectedBoat.letter; // Place Boat letter into the array
SelectedBoat.location[1]++; // iterate the value

My issue with this is that I'm not entirely sure if the first for loop is going to catch the issues that I need it to catch, or if it will iterate all the way through before the piece is placed....

Is my logic on this right? Help!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!