Advertisement
ithoran

Untitled

Dec 15th, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.52 KB | None | 0 0
  1. #include <iostream>
  2. #include "Polje.h"
  3. #include "MinesweeperObject.h"
  4. #include "NeotkrivenoPolje.h"
  5. #include "PoljeSaBrojem.h"
  6. #include "PoljeSaMinom.h"
  7. #include "PraznoPolje.h"
  8. using namespace std;
  9.  
  10. void main()
  11. {
  12.     int n, m, f, x, y, s = 0;
  13.     cout << "Unesite velicinu polja:\n";
  14.     cin >> n >> m;
  15.     Polje a(n, m);
  16.     MinesweeperObject **mine;
  17.     mine = new MinesweeperObject*[n];
  18.     for (int i = 0; i < n; i++) {
  19.         mine[i] = new NeotkrivenoPolje[m];
  20.     }
  21.     while (1) {
  22.         cout << "Unesite kordinate polja i funkciju:\n";
  23.         cin >> x >> y >> f;
  24.         mine[x - 1][y - 1].komanda(n, m, f, a);
  25.         for (int i = 0; i < n; i++)
  26.             for (int j = 0; j < m; j++)
  27.                 s = s + mine[x - 1][y - 1].stampaj();
  28.         if (s == n*m) {
  29.             cout << "Presli ste, cestitamo!";
  30.             return;
  31.         }
  32.     }
  33. }
  34.  
  35. #pragma once
  36. #include "Polje.h"
  37.  
  38. class MinesweeperObject {
  39. protected:
  40.     int m;
  41.     int brOM;
  42.     char z;
  43. public:
  44.     MinesweeperObject(int m, int brOM, char z);
  45.     MinesweeperObject();
  46.     virtual void komanda(int x, int y, int z, Polje a) = 0;
  47.     int stampaj() {
  48.         cout << z;
  49.         if (z != '#')
  50.             return 1;
  51.         return 0;
  52.     }
  53.     int brOkolnihMina(int x, int y, Polje a);
  54. };
  55.  
  56. #include "MinesweeperObject.h"
  57. #include "Polje.h"
  58.  
  59. MinesweeperObject::MinesweeperObject() {
  60.     z = '#';
  61. }
  62.  
  63. MinesweeperObject::MinesweeperObject(int m, int brOM, char z) {
  64.     this->m = m;
  65.     this->brOM = brOM;
  66.     this->z = z;
  67. }
  68.  
  69. int MinesweeperObject::brOkolnihMina(int x, int y, Polje a) {
  70.     int i, j, br = 0;
  71.     for (i = 0; i < 3; i++) {
  72.         for (j = 0; j < 3; j++) {
  73.             if (x - i >= 0 && x - i < a.n && y - j >= 0 && y - j < m) {
  74.                 if (a.a[x - i][y - j] == true) {
  75.                     br++;
  76.                 }
  77.             }
  78.         }
  79.     }
  80.     brOM = br;
  81.     return brOM;
  82. }
  83.  
  84. #pragma once
  85. #include <iostream>
  86. using namespace std;
  87.  
  88. class Polje {
  89. public:
  90.     int n;
  91.     int m;
  92.     bool **a;
  93.     Polje(int x, int y);
  94.     Polje();
  95.     ~Polje();
  96. };
  97.  
  98. #pragma once
  99. #include "Polje.h"
  100.  
  101. Polje::Polje(int x, int y) {
  102.     n = x;
  103.     m = y;
  104.     a = new bool*[n];
  105.     for (int i = 0; i < n; i++) {
  106.         a[i] = new bool[m];
  107.     }
  108.     for (int i = 0; i < n; i++) {
  109.         for (int j = 0; j < n; j++) {
  110.             cin >> a[i][j];
  111.         }
  112.     }
  113. }
  114.  
  115. Polje::Polje() {
  116. }
  117.  
  118. Polje::~Polje() {
  119.     if (a) {
  120.         for (int i = 0; i < n; i++)
  121.             delete[] a[i];
  122.         delete a;
  123.     }
  124. }
  125.  
  126. #pragma once
  127. #include "MinesweeperObject.h"
  128. #include "PraznoPolje.h"
  129. #include "PoljeSaMinom.h"
  130. #include "PoljeSaBrojem.h"
  131.  
  132. class NeotkrivenoPolje : public MinesweeperObject {
  133. public:
  134.     void komanda(int x, int y, int z, Polje a);
  135.     NeotkrivenoPolje() : MinesweeperObject() {}
  136. };
  137.  
  138. #include "NeotkrivenoPolje.h"
  139. #include "Polje.h"
  140.  
  141. void NeotkrivenoPolje::komanda(int x, int y, int z, Polje a) {
  142.     if (z == 1) {
  143.         if (a.a[x - 1][y - 1] == true) {
  144.             cout << "KRAJ IGRE, POGODILI STE MINU!";
  145.             exit(0);
  146.         }
  147.         else {
  148.             if (brOkolnihMina(x, y, a) == 0)
  149.                 PraznoPolje();
  150.             else {
  151.                 PoljeSaBrojem();
  152.             }
  153.         }
  154.     }
  155.     else
  156.         PoljeSaMinom();
  157. }
  158.  
  159. #pragma once
  160. #include "MinesweeperObject.h"
  161.  
  162. class PoljeSaBrojem : MinesweeperObject {
  163. public:
  164.     PoljeSaBrojem() : MinesweeperObject(0, brOM, brOM){}
  165.     virtual void komanda(int x, int y, int z, Polje a) {};
  166. };
  167.  
  168. #pragma once
  169. #include "MinesweeperObject.h"
  170. #include "NeotkrivenoPolje.h"
  171.  
  172. class PoljeSaMinom : public MinesweeperObject {
  173. public:
  174.     virtual void  komanda(int x, int y, int z, Polje a) {}
  175.     PoljeSaMinom() : MinesweeperObject(1, 0, 'X'){}
  176. };
  177.  
  178. #pragma once
  179. #include "MinesweeperObject.h"
  180.  
  181. class PraznoPolje : public MinesweeperObject {
  182. public:
  183.     virtual void komanda(int x, int y, int z, Polje a) {};
  184.     PraznoPolje() : MinesweeperObject(0, 0, '_') {
  185.     }
  186. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement