Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Polje.h
- #pragma once
- #include <iostream>
- using namespace std;
- class Polje {
- protected:
- int n;
- int m;
- bool **a;
- public:
- Polje(int x, int y);
- Polje();
- ~Polje();
- };
- // Polje.cpp
- #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;
- }
- }
- // MinesweeperObject.h
- #pragma once
- #include "Polje.h"
- class MinesweeperObject : public Polje {
- 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) = 0;
- int stampaj() {
- cout << z;
- if (z != '#')
- return 1;
- return 0;
- }
- int brOkolnihMina(int x, int y);
- };
- // MinesweeperObject.cpp
- #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) {
- int i, j, br = 0;
- 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++;
- }
- }
- }
- }
- brOM = br;
- return brOM;
- }
- // NeotkrivenoPolje.h
- #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);
- NeotkrivenoPolje() : MinesweeperObject() {}
- };
- // NeotkrivenoPolje.cpp
- #include "NeotkrivenoPolje.h"
- void NeotkrivenoPolje::komanda(int x, int y, int z) {
- if (z == 1) {
- if (a[x - 1][y - 1] == true) {
- cout << "KRAJ IGRE, POGODILI STE MINU!";
- exit(0);
- }
- else {
- if (brOkolnihMina(x, y) == 0)
- PraznoPolje();
- else {
- PoljeSaBrojem();
- }
- }
- }
- else
- PoljeSaMinom();
- }
- // PoljeSaMinom.h
- #pragma once
- #include "MinesweeperObject.h"
- #include "NeotkrivenoPolje.h"
- class PoljeSaMinom : public MinesweeperObject {
- public:
- virtual void komanda(int x, int y, int z) {
- if (z == 2)
- NeotkrivenoPolje(); // top kek
- }
- PoljeSaMinom() : MinesweeperObject(1, 0, 'X'){}
- };
- // PraznoPolje.h
- #pragma once
- #include "MinesweeperObject.h"
- class PraznoPolje : public MinesweeperObject {
- public:
- virtual void komanda(int x, int y, int z) {};
- PraznoPolje() : MinesweeperObject(0, 0, '_') {
- }
- };
- // PoljeSaBrojem
- #pragma once
- #include "MinesweeperObject.h"
- class PoljeSaBrojem : MinesweeperObject {
- public:
- PoljeSaBrojem() : MinesweeperObject(0, brOM, brOM){}
- virtual void komanda(int x, int y, int z) {};
- };
- // main.cpp
- #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);
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement