Advertisement
Siwy_Krzysiek

Problem Hetmanów

Jan 21st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <vector>
  4.  
  5. using std::vector;
  6.  
  7. using namespace std;
  8.  
  9. class Hetman
  10. {
  11. public:
  12.     int x;
  13.     int y;
  14.     int wielkosc;
  15.     bool aktywny;
  16.     vector<vector<bool> > atakowanePola;
  17.  
  18.     //bool* atakowanePola;
  19.     //bool** atakowanePola2;
  20.  
  21. public:
  22.     Hetman()
  23.     {
  24.         x=0;
  25.         y=0;
  26.         aktywny=false;
  27.  
  28. //        bool atakowanePola2 = new bool*[3];
  29. //        for (int i = 0; i < 3; ++i )
  30. //        {
  31. //           atakowanePola2[i] = new bool[3];
  32. //        }
  33.     }
  34.  
  35.     Hetman(int wielkosc, int x, int y)
  36.     {
  37.         this->x=x;
  38.         this->y=y;
  39.         this->wielkosc=wielkosc;
  40.         aktywny=true;
  41.  
  42.         atakowanePola.resize(wielkosc);
  43.         for(int i=0; i<wielkosc; i++)
  44.             atakowanePola[i].resize(wielkosc);
  45.  
  46.  
  47.         for(int i=0; i<wielkosc; i++)
  48.         {
  49.             for(int j=0; j<wielkosc; j++)
  50.             {
  51.                 if(i==y)
  52.                     atakowanePola[i][j]=true;
  53.                 if(j==x)
  54.                     atakowanePola[i][j]=true;
  55.                 if(abs(x-i)==abs(y-j))
  56.                     atakowanePola[i][j]=true;
  57.             }
  58.         }
  59.             //pokazAtak();
  60.  
  61. //        atakowanePola = new bool[wielkosc*wielkosc];
  62. //        for(int i=0; i<wielkosc*wielkosc; i++) atakowanePola[i]=false;
  63. //
  64. //        for(int i=0; i<wielkosc*wielkosc; i++)
  65. //        {
  66. //            if(x%wielkosc==i%wielkosc) atakowanePola[i]=true;
  67. //
  68. //        }
  69.     }
  70.  
  71.     void ustaw(int wielkosc, int x, int y)
  72.     {
  73.         this->x=x;
  74.         this->y=y;
  75.         this->wielkosc=wielkosc;
  76.         aktywny=true;
  77.  
  78.         atakowanePola.resize(wielkosc);
  79.         for(int i=0; i<wielkosc; i++)
  80.             atakowanePola[i].resize(wielkosc);
  81.  
  82.  
  83.         for(int i=0; i<wielkosc; i++)
  84.         {
  85.             for(int j=0; j<wielkosc; j++)
  86.             {
  87.                 if(i==y)
  88.                     atakowanePola[i][j]=true;
  89.                 if(j==x)
  90.                     atakowanePola[i][j]=true;
  91.                 if(abs(x-i)==abs(y-j))
  92.                     atakowanePola[i][j]=true;
  93.             }
  94.         }
  95.     }
  96.  
  97.     void zedjmij()
  98.     {
  99.         x=0;
  100.         y=0;
  101.         aktywny=false;
  102.     }
  103.  
  104.     void pokazAtak()
  105.     {
  106.         cout << "Atakowane pola:\n";
  107.         for(int i=0; i<wielkosc; i++)
  108.         {
  109.             for(int j=0; j<wielkosc; j++)
  110.             {
  111.                 cout << atakowanePola[i][j];
  112.                 if(j!=wielkosc-1) cout << ":";
  113.             }
  114.             cout << endl;
  115.         }
  116.     }
  117.  
  118.  
  119. };
  120.  
  121. class Plansza
  122. {
  123. private:
  124.     int rozmiar;
  125.  
  126. public:
  127.  
  128.     Plansza(int wielkosc)
  129.     {
  130.         rozmiar=wielkosc;
  131.     }
  132.  
  133.     void rozwiaz()
  134.     {
  135.         Hetman tab[rozmiar];
  136.     }
  137.  
  138.  
  139. };
  140.  
  141. int main()
  142. {
  143.  
  144.  
  145.     //cout << a.atakowanePola[];
  146.  
  147.     vector<vector<int> > tablica2D;
  148.  
  149.     tablica2D.resize(3);
  150.     for(int i=0; i<3; i++)
  151.         tablica2D[i].resize(2);
  152.  
  153.     tablica2D[0][1]=3;
  154.  
  155.     for(int i=0; i<3; i++)
  156.     {
  157.         for(int j=0; j<2; j++)
  158.         {
  159.             cout << tablica2D[i][j];
  160.         }
  161.         cout << endl;
  162.     }
  163.     cout << "Koniec testu 1\n\n";
  164.  
  165.     Hetman a(5, 1, 0);
  166.  
  167.     a.pokazAtak();
  168.  
  169.     //cout << a.atakowanePola[1][0];
  170.  
  171.  
  172.     return 0;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement