int randRow = rand.nextInt(rows-4);
int randColumn = rand.nextInt(columns);
here i check if my new ship doesn't interfere with my first ship. the entire array is filled with objects which contain a '.' char except for where the first ship is
if(field[randRow][randColumn].value == '.' &&
field[randRow][randColumn+1].value == '.' &&
field[randRow][randColumn+2].value == '.' &&
field[randRow][randColumn+3].value == '.'){
field[randRow][randColumn] = new Square('b');
field[randRow+1][randColumn] = new Square('b');
field[randRow+2][randColumn] = new Square('b');
field[randRow+3][randColumn] = new Square('b');
}else{
if my new ship doesn't fit i want to retry with different random values but i don't know how.
}
Aucun commentaire:
Enregistrer un commentaire