Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- const int DIMX = 10;
- const int DIMY = 10;
- const int BOMB = 12;
- int glX = 0;
- int glY = 0;
- int randInt(int min, int max) { return min + (rand() % (int)(max - min + 1)); }
- struct mCase;
- void init(mCase table[DIMX][DIMY]);
- void print(mCase table[DIMX][DIMY]);
- //struct table;
- int main(void)
- {
- mCase table[DIMX][DIMY];
- init(table);
- print(table);
- system("pause");
- return 0;
- }
- struct mCase
- {
- int x;
- int y;
- int nearBomb = 0;
- bool isBomb = false;
- bool isVisible = true;
- bool isDisplayed = false;
- bool isFlagged = false;
- void init()
- {
- x = glX;
- y = glY;
- nearBomb = 0;
- if (x == 0 || y == 0 || x == DIMX || y == DIMY) isVisible == false;
- isFlagged = false;
- isBomb = false;
- }
- };
- void init(mCase table[DIMX][DIMY])
- {
- // Just calling init
- for (glX = 0; glX < DIMX; glX++)
- {
- for (glY = 0; glY < DIMY; glY++)
- {
- table[glX][glY].init();
- }
- }
- // Placing bombs
- for (int i = 0; i < BOMB; i++)
- {
- int x = randInt(1, DIMX - 1);
- int y = randInt(1, DIMY - 1);
- if (table[x][y].isBomb == false) table[x][y].isBomb = true;
- else i--;
- }
- // Count near bombs
- for (glX = 1; glX < DIMX - 1; glX++)
- {
- for (glY = 1; glY < DIMY - 1; glY++)
- {
- for (int x = glX - 1; x < 1; x++)
- {
- for (int y = glY - 1; y < 1; y++)
- {
- if (table[x][y].isBomb = true) table[x][y].nearBomb++;
- }
- }
- }
- }
- }
- void print(mCase table[DIMX][DIMY])
- {
- for (glX = 1; glX < DIMX - 1; glX++)
- {
- for (glY = 1; glY < DIMY - 1; glY++)
- {
- if (table[glX][glY].isBomb) cout << 'B';
- else cout << table[glX][glY].nearBomb;
- cout << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement