fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //#pragma once
  5. class Pole
  6. {
  7. char X; //wspołrzędna X
  8. char Y; //wspołrzędna Y
  9. int status = 0; //przypisany status
  10. enum flaga
  11. { wolne = 1, zaznaczone = 2, trafione= 3 }; //flaga pola
  12. char znak; // znak pola
  13.  
  14. public:
  15. Pole();
  16. Pole(const char, const char );
  17. ~Pole();
  18. void Wprowadz_Pole(const char,const char);
  19. bool Sprawdz_Wolne(char, char) const;
  20. int Sprawdz_Status(const char, const char);
  21. void Ustaw_Staus(int);
  22. void Ustaw_Znak();
  23. void Pokaz_Znak();
  24. int Zwroc_Zaznaczone();
  25. };
  26.  
  27.  
  28. //#include "Pole.h"
  29. //#include <iostream>
  30. //using namespace std;
  31.  
  32.  
  33. Pole::Pole()
  34. {
  35. this->X = 0; // NULL jest wskaźnikiem, nie znakiem !
  36. this->Y = 0; // NULL jest wskaźnikiem, nie znakiem !
  37. this->status = wolne;
  38. Ustaw_Znak();
  39. }
  40. Pole::Pole(const char x, const char y)
  41. {
  42. this->X = x;
  43. this->Y = y;
  44. this->status = wolne;
  45. Ustaw_Znak();
  46.  
  47. }
  48.  
  49.  
  50. Pole::~Pole()
  51. {
  52. }
  53.  
  54. void Pole::Wprowadz_Pole(const char x, const char y)
  55. {
  56. this->X = x;
  57. this->Y = y;
  58. }
  59. int Pole::Sprawdz_Status(const char x, const char y)
  60. {
  61.  
  62. for (int i = 0; i < 9; ++i) //duza pętla po X
  63. {
  64. if (this->X == x)
  65. {
  66. for (int j = 0; j < 9; ++j)
  67. {
  68. if (this->Y == y)
  69. return this->status;
  70. }
  71. }
  72. }
  73. }
  74.  
  75. void Pole::Ustaw_Staus(int a)
  76. {
  77. this->status = a;
  78. cout<<"this->status = a;"<<endl;
  79. }
  80. void Pole::Ustaw_Znak()
  81. {
  82. if (this->status == trafione)
  83. this->znak = 'T';
  84. else if (this->status == zaznaczone)
  85. this->znak = 'X'; // TU ZBĘDNA SPACJA
  86. else
  87. this->znak = 'W';
  88.  
  89. }
  90. void Pole::Pokaz_Znak()
  91. {
  92. cout << this->znak;
  93. }
  94. int Pole::Zwroc_Zaznaczone()
  95. {
  96. return this->zaznaczone;
  97. }
  98.  
  99.  
  100.  
  101. //PLANSZA
  102. //#pragma once
  103. //#include "Pole.h"
  104.  
  105.  
  106. class Plansza
  107. {
  108. Pole plansza[9][9];
  109.  
  110. public:
  111. Plansza();
  112. ~Plansza();
  113. void Wyswietl_Plansze();
  114. void Ustaw_Pole(const char, const char, int);
  115. int Zwroc_Zaznaczone(const char, const char);
  116. };
  117.  
  118. //#include "Plansza.h"
  119. //#include <iostream>
  120.  
  121. //using namespace std;
  122.  
  123. Plansza::Plansza()
  124. {
  125. for (char i = 0; i < 9; ++i)
  126. {
  127. for (char j = 0; j < 9; ++j)
  128. {
  129. //plansza[i][j]; // Po kiego ten wiersz ?
  130. plansza[i][j]=Pole(i, j); // Była próba bezpośredniego uruchomienia konstruktora
  131. }
  132. }
  133. }
  134.  
  135.  
  136. Plansza::~Plansza()
  137. {
  138. }
  139.  
  140. void Plansza::Wyswietl_Plansze()
  141. {
  142. for (int i = 0; i <= 9; ++i)
  143. {
  144.  
  145. for (int j = 0; j <= 9; ++j)
  146. {
  147.  
  148. cout <<"|"<< " "<<"|";
  149. plansza[i][j];
  150. plansza[i][j].Pokaz_Znak();
  151. }
  152. cout << endl << endl;;
  153. }
  154.  
  155.  
  156. }
  157. void Plansza::Ustaw_Pole(const char x, const char y, int a)
  158. {
  159. plansza[x][y].Ustaw_Staus(2);
  160. }
  161. int Plansza::Zwroc_Zaznaczone(const char x, const char y)
  162. {
  163. return plansza[x][y].Zwroc_Zaznaczone(); // Po kiego to Pole:: ?
  164.  
  165. }
  166.  
  167.  
  168.  
  169. //STATKI
  170. //#pragma once
  171. //#include "Plansza.h"
  172. class Statki
  173. {
  174. Plansza okrety;
  175. public:
  176. Statki();
  177. ~Statki();
  178. void Jedno_Masztowiec(const char, const char);
  179. void Dwu_Masztowiec();
  180. void Trzy_Masztowiec();
  181. void Ustaw_Polozenie(const char, const char);
  182. };
  183.  
  184. //#include "Statki.h"
  185.  
  186.  
  187. Statki::Statki()
  188. {
  189. }
  190.  
  191.  
  192. Statki::~Statki()
  193. {
  194. }
  195. void Statki::Jedno_Masztowiec(const char x, const char y)
  196. {
  197. Ustaw_Polozenie(x, y);
  198. }
  199.  
  200. void Statki::Ustaw_Polozenie(const char x, const char y)
  201. {
  202. okrety.Ustaw_Pole(x, y, okrety.Zwroc_Zaznaczone(x,y));
  203. }
  204.  
  205. int main()
  206. {
  207. Statki s;
  208. s.Ustaw_Polozenie(0,0);
  209. s.Ustaw_Polozenie(8,8);
  210. s.Jedno_Masztowiec(2,3);
  211. return 0;
  212. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
this->status = a;
this->status = a;
this->status = a;