Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. #include <ctime>
  5. #include <fstream>
  6. #include <Windows.h>
  7.  
  8. using namespace std;
  9.  
  10. class Square {
  11. friend class Blank;
  12. friend class Piece;
  13. friend class DoublePiece;
  14. friend class Checkers;
  15.  
  16. bool P1;
  17. bool P2;
  18. bool DP;
  19.  
  20. friend class P1;
  21.  
  22. Square() {
  23. P1 = false;
  24. P2 = false;
  25. DP = false;
  26. }
  27.  
  28. virtual void viewSquare() = 0;
  29. };
  30.  
  31. class Blank : public Square {
  32.  
  33. friend class Checkers;
  34. Blank() {}
  35.  
  36. virtual void viewSquare() {
  37. cout << " ";
  38. }
  39. };
  40.  
  41. class Piece : public Square {
  42. friend class Checkers;
  43.  
  44. Piece(int Player) {
  45. if (Player == 1) {
  46. P1 = true;
  47. }
  48. else {
  49. P2 = true;
  50. }
  51. }
  52.  
  53. virtual void viewSquare() {
  54. cout << " ţ ";
  55. }
  56. };
  57.  
  58. class DoublePiece : public Square {
  59. friend class Checkers;
  60.  
  61. DoublePiece(int Player) {
  62. if (Player == 1) {
  63. P1 = true;
  64. DP = true;
  65. }
  66. else {
  67. P2 = true;
  68. DP = true;
  69. }
  70. }
  71.  
  72. virtual void viewSquare() {
  73. cout << "[ţ]";
  74. }
  75. };
  76.  
  77. class Checkers {
  78. friend bool Game();
  79.  
  80. Square ***Grid;
  81.  
  82. Checkers() {
  83. Grid = new Square**[8];
  84.  
  85. for (int i = 0; i < 8; i++) {
  86. Grid[i] = new Square*[8];
  87. }
  88.  
  89. for (int y = 0; y < 8; y++) {
  90. for (int x = 0; x < 8; x++) {
  91. Grid[x][y] = new Blank;
  92. }
  93. }
  94. }
  95.  
  96. void view() {
  97.  
  98. cout << " ";
  99. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x80);
  100. cout << " " << endl;
  101. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
  102.  
  103. for (int y = 0; y < 8; y++) {
  104.  
  105. cout << " ";
  106. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x80);
  107. cout << " ";
  108. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
  109.  
  110. for (int x = 0; x < 8; x++) {
  111. if (y % 2) {
  112. if (x % 2) {
  113. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xF0);
  114. Grid[x][y]->viewSquare();
  115. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
  116. }
  117. else {
  118. if (Grid[x][y]->P1) {
  119. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0B);
  120. }
  121. else if (Grid[x][y]->P2) {
  122. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0E);
  123. }
  124. Grid[x][y]->viewSquare();
  125. }
  126. }
  127. else {
  128. if (x % 2) {
  129. if (Grid[x][y]->P1) {
  130. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0B);
  131. }
  132. else if (Grid[x][y]->P2) {
  133. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0E);
  134. }
  135. Grid[x][y]->viewSquare();
  136. }
  137. else {
  138. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xF0);
  139. Grid[x][y]->viewSquare();
  140. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
  141. }
  142. }
  143. }
  144. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x80);
  145. cout << " ";
  146. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
  147.  
  148. cout << endl;
  149. }
  150.  
  151. cout << " ";
  152. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x80);
  153. cout << " " << endl;
  154. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0F);
  155. }
  156.  
  157. void setPieces() {
  158. for (int x = 1; x < 8; x+=2) {
  159. Grid[x][0] = new Piece(2);
  160. }
  161. for (int x = 0; x < 8; x += 2) {
  162. Grid[x][1] = new Piece(2);
  163. }
  164. for (int x = 1; x < 8; x += 2) {
  165. Grid[x][2] = new Piece(2);
  166. }
  167.  
  168. for (int x = 0; x < 8; x += 2) {
  169. Grid[x][5] = new Piece(1);
  170. }
  171. for (int x = 1; x < 8; x += 2) {
  172. Grid[x][6] = new Piece(1);
  173. }
  174. for (int x = 0; x < 8; x += 2) {
  175. Grid[x][7] = new Piece(1);
  176. }
  177. }
  178. };
  179.  
  180.  
  181. bool Game() {
  182. system("cls");
  183. cout << "Warcaby" << endl << endl;
  184.  
  185. Checkers Game;
  186.  
  187. Game.setPieces();
  188. Game.view();
  189.  
  190. return 1;
  191.  
  192. /*cout << "[1] Zagraj" << endl << "[2] Wyswietl rezultaty ostatnich gier" << endl;
  193.  
  194. unsigned char choice;
  195. choice = _getch();
  196.  
  197. if (choice == 49) { system("cls"); }
  198. else if (choice == 50) {
  199. system("cls");
  200. cout << "Rezultaty ostatnich gier:" << endl << endl;
  201.  
  202. fstream file;
  203. file.open("Statki.txt", ios::in);
  204.  
  205. string result;
  206.  
  207. while (getline(file, result)) {
  208. cout << result << endl;
  209. }
  210.  
  211. file.close();
  212.  
  213. cout << endl << "Kliknij dowolny przycisk, aby kontynuowac";
  214. _getch();
  215.  
  216. return 1;
  217. }
  218. else { return 1; }
  219.  
  220. string Name1, Name2;
  221.  
  222. cout << "Wpisz imiona graczy:" << endl;
  223.  
  224. cout << "Gracz 1: ";
  225. cin >> Name1;
  226. cout << "Gracz 2: ";
  227. cin >> Name2;
  228.  
  229. srand(time(0));
  230. int random = rand() % 2;
  231.  
  232. if (random) {
  233. swap(Name1, Name2);
  234. }
  235.  
  236. Player Player1(Name1);
  237. Player Player2(Name2);
  238.  
  239. system("cls");
  240. cout << Player1.Name << " ustawia statki.";
  241. cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
  242. _getch();
  243. Player1.setShips();
  244. cout << endl << "Gotowe";
  245. cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
  246. _getch();
  247.  
  248. system("cls");
  249. cout << Player2.Name << " ustawia statki.";
  250. cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
  251. _getch();
  252. Player2.setShips();
  253. cout << endl << "Gotowe";
  254. cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
  255. _getch();
  256.  
  257. while (true) {
  258. system("cls");
  259. cout << "Ruch gracza: " << Player1.Name;
  260. cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
  261. _getch();
  262.  
  263. while (true) {
  264. system("cls");
  265. Player2.displayEnemysGrid();
  266. cout << endl;
  267. Player1.displayMyGrid();
  268.  
  269. cout << endl << "Wybierz cel: ";
  270. string Point;
  271. cin >> Point;
  272.  
  273. int pointX = Point[0] - 65;
  274. int pointY = Point[1] - 48;
  275. }
  276.  
  277. system("cls");
  278. cout << "Ruch gracza: " << Player2.Name;
  279. cout << endl << endl << "Kliknij dowolny przycisk, aby kontynuowac";
  280. _getch();
  281.  
  282. while (true) {
  283. system("cls");
  284. Player1.displayEnemysGrid();
  285. cout << endl;
  286. Player2.displayMyGrid();
  287.  
  288. cout << endl << "Wybierz cel: ";
  289. string Point;
  290. cin >> Point;
  291.  
  292. int pointX = Point[0] - 65;
  293. int pointY = Point[1] - 48;
  294. }
  295. }*/
  296. }
  297.  
  298. int main() {
  299. Game();
  300. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement