Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Create (int n)
- {
- Random rand = new Random();
- ships = new PointShip[n];
- for (int x=0; x<n; x++) {
- do {
- ships[x].pos_x=rand.nextInt(10);
- ships[x].pos_y=rand.nextInt(10);
- if(CanPut(ships[x],n)) break;
- } while (true);
- }
- }
- boolean CanPut(PointShip ship, int n) {
- int repeat=0;
- for (int i=0; i<n; i++) {
- if (ships[i].pos_x==ship.pos_x && ships[i].pos_y==ship.pos_y) {
- repeat++;
- }
- }
- if (repeat>1) return false;
- else return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement