Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- srand(time(0));
- int const size = 10;
- int arr[size][size];
- for (int i = 0; i < size; i++)
- {
- for (int j = 0; j < size; j++)
- {
- arr[i][j] = 0;
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- //Draw 4 lvl boat
- int x = 1, y = 1;
- bool acces = false;
- do
- {
- acces = false;
- x = rand() % 10;
- y = rand() % 10;
- if (x > size - 4)
- {
- acces = true;
- }
- else
- {
- for (int i = x; i < x + 4; i++)
- if (arr[y][i] != 0)
- acces = true;
- }
- } while (acces);
- if (!acces)
- {
- for (int i = y - 1; i < y + 2; i++)
- {
- for (int j = x - 1; j < x + 5; j++)
- {
- if (i >= 0 && j >= 0 && i < size && j < size)
- arr[i][j] = 2;
- }
- }
- }
- for (int i = x; i < x + 4; i++)
- {
- arr[y][i] = 1;
- }
- //draw 1 lvl boat
- for (int n = 0; n < 4; n++)
- {
- int x, y;
- do
- {
- x = rand() % 10;
- y = rand() % 10;
- } while (arr[x][y] != 0);
- for (int i = y - 1; i < y + 2; i++)
- {
- for (int j = x - 1; j < x + 2; j++)
- {
- if (i >= 0 && j >= 0 && i < size && j < size)
- arr[j][i] = 2;
- }
- }
- arr[x][y] = 1;
- }
- //shown all place
- for (int i = 0; i < size; i++)
- {
- for (int j = 0; j < size; j++)
- cout << arr[i][j] << " ";
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement