Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Minesweeper.h
- using namespace std;
- class Minesweeper {
- private:
- int n;
- int m;
- bool** a;
- public:
- Minesweeper();
- Minesweeper(int n, int m);
- ~Minesweeper();
- int brVrsta() {
- return n;
- }
- int brKolona() {
- return m;
- }
- void ucitajMinesweeper();
- void ispisiMinesweeper();
- int opasnostPolja(int brV, int brK);
- };
- // Minesweeper.cpp
- #include "Minesweeper.h"
- #include <iostream>
- using namespace std;
- Minesweeper::Minesweeper(int n, int m) {
- this->n = n;
- this->m = m;
- a = new bool*[n];
- for (int i = 0; i < n; i++) {
- a[i] = new bool[m];
- }
- }
- Minesweeper::Minesweeper() {
- a = nullptr;
- this->n = n;
- this->m = m;
- }
- Minesweeper::~Minesweeper() {
- if (a) {
- for (int i = 0; i < n; i++) {
- delete [] a[i];
- }
- delete [] a;
- }
- }
- int Minesweeper::opasnostPolja(int x, int y) { //Smatra se da korisnik unosi matricu tako da je prvo polje (1,1)
- int i,j,br = 0;
- if (a[x - 1][y - 1] == true) {
- return -1;
- }
- else {
- for (i = 0; i < 3; i++) {
- for (j = 0; j < 3; j++) {
- if (x - i >= 0 && x - i < n && y - j >= 0 && y - j < m) {
- if (a[x - i][y - j] == true) {
- br++;
- }
- }
- }
- }
- }
- return br;
- }
- void Minesweeper::ucitajMinesweeper() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cin >> a[i][j];
- }
- }
- }
- void Minesweeper::ispisiMinesweeper() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cout << a[i][j];
- }
- cout << endl;
- }
- }
- // main.cpp
- #include "Minesweeper.h"
- #include <iostream>
- using namespace std;
- void main() {
- Minesweeper mine(4,4);
- int x, y;
- mine.ucitajMinesweeper();
- cin >> x >> y;
- if (mine.opasnostPolja(x,y) < 0) {
- mine.ispisiMinesweeper();
- }
- else {
- cout << mine.opasnostPolja(x,y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement