|
@ -137,12 +137,21 @@ public class Matchfield { |
|
|
do { |
|
|
do { |
|
|
|
|
|
|
|
|
Random random = new Random(); |
|
|
Random random = new Random(); |
|
|
int randomX = random.nextInt(this.size - length); |
|
|
|
|
|
int randomY = random.nextInt(this.size - length); |
|
|
|
|
|
origin = new Coordinate(randomX, randomY); |
|
|
|
|
|
|
|
|
|
|
|
randomDirection = random.nextInt(2); |
|
|
randomDirection = random.nextInt(2); |
|
|
|
|
|
|
|
|
|
|
|
int randomX = 0, randomY = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (randomDirection == 0) { |
|
|
|
|
|
randomX = random.nextInt(this.size - length); |
|
|
|
|
|
randomY = random.nextInt(this.size); |
|
|
|
|
|
} else if (randomDirection == 1) { |
|
|
|
|
|
randomX = random.nextInt(this.size); |
|
|
|
|
|
randomY = random.nextInt(this.size - length); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
origin = new Coordinate(randomX, randomY); |
|
|
|
|
|
|
|
|
if (this.isFreePosition(origin, length, randomDirection)) { |
|
|
if (this.isFreePosition(origin, length, randomDirection)) { |
|
|
success = this.setShip(new Coordinate(randomX, randomY), length, randomDirection); |
|
|
success = this.setShip(new Coordinate(randomX, randomY), length, randomDirection); |
|
|
} |
|
|
} |
|
|