Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Polje.h"
- #include "MinesweeperObject.h"
- #include "NeotkrivenoPolje.h"
- #include "PoljeSaBrojem.h"
- #include "PoljeSaMinom.h"
- #include "PraznoPolje.h"
- using namespace std;
- void main()
- {
- int n, m, f, x, y, s = 0;
- cout << "Unesite velicinu polja:\n";
- cin >> n >> m;
- Polje a(n, m);
- MinesweeperObject **mine;
- mine = new MinesweeperObject*[n];
- for (int i = 0; i < n; i++) {
- mine[i] = new NeotkrivenoPolje[m];
- }
- while (1) {
- cout << "Unesite kordinate polja i funkciju:\n";
- cin >> x >> y >> f;
- mine[x - 1][y - 1].komanda(n, m, f, a);
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- s = s + mine[x - 1][y - 1].stampaj();
- if (s == n*m) {
- cout << "Presli ste, cestitamo!";
- return;
- }
- }
- }
- #pragma once
- #include "Polje.h"
- class MinesweeperObject {
- protected:
- int m;
- int brOM;
- char z;
- public:
- MinesweeperObject(int m, int brOM, char z);
- MinesweeperObject();
- virtual void komanda(int x, int y, int z, Polje a) = 0;
- int stampaj() {
- cout << z;
- if (z != '#')
- return 1;
- return 0;
- }
- int brOkolnihMina(int x, int y, Polje a);
- };
- #include "MinesweeperObject.h"
- #include "Polje.h"
- MinesweeperObject::MinesweeperObject() {
- z = '#';
- }
- MinesweeperObject::MinesweeperObject(int m, int brOM, char z) {
- this->m = m;
- this->brOM = brOM;
- this->z = z;
- }
- int MinesweeperObject::brOkolnihMina(int x, int y, Polje a) {
- int i, j, br = 0;
- for (i = 0; i < 3; i++) {
- for (j = 0; j < 3; j++) {
- if (x - i >= 0 && x - i < a.n && y - j >= 0 && y - j < m) {
- if (a.a[x - i][y - j] == true) {
- br++;
- }
- }
- }
- }
- brOM = br;
- return brOM;
- }
- #pragma once
- #include <iostream>
- using namespace std;
- class Polje {
- public:
- int n;
- int m;
- bool **a;
- Polje(int x, int y);
- Polje();
- ~Polje();
- };
- #pragma once
- #include "Polje.h"
- Polje::Polje(int x, int y) {
- n = x;
- m = y;
- a = new bool*[n];
- for (int i = 0; i < n; i++) {
- a[i] = new bool[m];
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cin >> a[i][j];
- }
- }
- }
- Polje::Polje() {
- }
- Polje::~Polje() {
- if (a) {
- for (int i = 0; i < n; i++)
- delete[] a[i];
- delete a;
- }
- }
- #pragma once
- #include "MinesweeperObject.h"
- #include "PraznoPolje.h"
- #include "PoljeSaMinom.h"
- #include "PoljeSaBrojem.h"
- class NeotkrivenoPolje : public MinesweeperObject {
- public:
- void komanda(int x, int y, int z, Polje a);
- NeotkrivenoPolje() : MinesweeperObject() {}
- };
- #include "NeotkrivenoPolje.h"
- #include "Polje.h"
- void NeotkrivenoPolje::komanda(int x, int y, int z, Polje a) {
- if (z == 1) {
- if (a.a[x - 1][y - 1] == true) {
- cout << "KRAJ IGRE, POGODILI STE MINU!";
- exit(0);
- }
- else {
- if (brOkolnihMina(x, y, a) == 0)
- PraznoPolje();
- else {
- PoljeSaBrojem();
- }
- }
- }
- else
- PoljeSaMinom();
- }
- #pragma once
- #include "MinesweeperObject.h"
- class PoljeSaBrojem : MinesweeperObject {
- public:
- PoljeSaBrojem() : MinesweeperObject(0, brOM, brOM){}
- virtual void komanda(int x, int y, int z, Polje a) {};
- };
- #pragma once
- #include "MinesweeperObject.h"
- #include "NeotkrivenoPolje.h"
- class PoljeSaMinom : public MinesweeperObject {
- public:
- virtual void komanda(int x, int y, int z, Polje a) {}
- PoljeSaMinom() : MinesweeperObject(1, 0, 'X'){}
- };
- #pragma once
- #include "MinesweeperObject.h"
- class PraznoPolje : public MinesweeperObject {
- public:
- virtual void komanda(int x, int y, int z, Polje a) {};
- PraznoPolje() : MinesweeperObject(0, 0, '_') {
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement