Guest User

Untitled

a guest
Jul 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.15 KB | None | 0 0
  1. #include<iostream>
  2. #include<ctime>
  3. #include<iomanip>
  4. #include<string>
  5. #include<Windows.h>
  6. #include<windows.h>
  7. using namespace std;
  8.  
  9. HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
  10. #define _CRT_NO_SECURITY_WARNINGS
  11.  
  12. const int FIELD_SIZE = 10;
  13.  
  14. char Player1[100];
  15. char Player2[100];
  16.  
  17. int amount_of_ship_cells_left_to_drown_P1;
  18. int amount_of_ship_cells_left_to_drown_P2;
  19.  
  20. // [x][y], где x - вертикаль, y - горизонталь
  21.  
  22. char WaterP1 = '~';
  23. char WaterP2 = '~';
  24. char TorpedeP1 = 'Т';
  25. char TorpedeP2 = 'Т';
  26. char DestroyerP1 = 'К';
  27. char DestroyerP2 = 'К';
  28. char CruiserP1 = 'Э';
  29. char CruiserP2 = 'Э';
  30. char BattleshipP1 = 'Л';
  31. char BattleshipP2 = 'Л';
  32. char ShipHitP1 = 'Х';
  33. char ShipHitP2 = 'X';
  34. char HitMissP1 = '*';
  35. char HitMissP2 = '*';
  36.  
  37. void ifP1Win(char* p1) {
  38. system("cls");
  39. cout << "Игрок " << p1 << " ПОБЕДИЛ!!! Поздравляем!" << endl;
  40. system("pause");
  41. }
  42.  
  43. void ifP2Win(char* p2) {
  44. system("cls");
  45. cout << "Игрок " << p2 << " ПОБЕДИЛ!!! Поздравляем!" << endl;
  46. system("pause");
  47. }
  48.  
  49. bool Cell_checker(int PlayerNumber, int asked_cell) {
  50.  
  51. char T;
  52. char D;
  53. char C;
  54. char BS;
  55.  
  56. switch (PlayerNumber)
  57. {
  58. case 1:
  59. {
  60. T = TorpedeP1;
  61. D = DestroyerP1;
  62. C = CruiserP1;
  63. BS = BattleshipP1;
  64. } break;
  65.  
  66. case 2:
  67. {
  68. T = TorpedeP2;
  69. D = DestroyerP2;
  70. C = CruiserP2;
  71. BS = BattleshipP2;
  72. } break;
  73.  
  74. }
  75.  
  76. if (asked_cell == T || asked_cell == D || asked_cell == C || asked_cell ==
  77. BS)
  78. return true;
  79. else
  80. return false;
  81. }
  82.  
  83. void Print_table(char arr[][FIELD_SIZE]) {
  84. for (int i = 0; i < FIELD_SIZE; i++)
  85. {
  86. for (int j = 0; j < FIELD_SIZE; j++)
  87. {
  88. cout << arr[i][j] << " ";
  89. }
  90. cout << endl;
  91. }
  92. }
  93.  
  94. void Print_hidden_table(char arr[][FIELD_SIZE]) {
  95. for (int i = 0; i < FIELD_SIZE; i++)
  96. {
  97. for (int j = 0; j < FIELD_SIZE; j++)
  98. {
  99. cout << '~' << " ";
  100. }
  101. cout << endl;
  102. }
  103. }
  104.  
  105.  
  106. void Players_names(char* Player1, char* Player2) {
  107.  
  108. cout << "Введите имя ";
  109. SetConsoleTextAttribute(h, 3);
  110. cout << "первого";
  111. SetConsoleTextAttribute(h, 7);
  112. cout << " игрока() : ";
  113.  
  114. cin >> Player1;
  115.  
  116. cout << "Введите имя ";
  117. SetConsoleTextAttribute(h, 4);
  118. cout << "второго";
  119. SetConsoleTextAttribute(h, 7);
  120. cout << " игрока() : ";
  121.  
  122. cin >> Player2;
  123.  
  124. }
  125.  
  126. void Create_table(char arr[][FIELD_SIZE], char c) {
  127. for (int i = 0; i < FIELD_SIZE; i++)
  128. {
  129. for (int j = 0; j < FIELD_SIZE; j++)
  130. {
  131. arr[i][j] = c;
  132. }
  133. }
  134.  
  135. }
  136.  
  137. void Pass2AnotherPlayer() {
  138. system("cls");
  139. cout << "Переход к другому игроку. И не подглядывайте ;)" << endl;
  140. Sleep(5000);
  141. system("cls");
  142. }
  143.  
  144. void Set_ships(char arr[][FIELD_SIZE], int PlayerNumber) {
  145.  
  146. char PNEnd[5];
  147. char Torp;
  148. char Destr;
  149. char Crui;
  150. char BShip;
  151.  
  152. if (PlayerNumber == 1) {
  153. Torp = TorpedeP1;
  154. Destr = DestroyerP1;
  155. Crui = CruiserP1;
  156. BShip = BattleshipP1;
  157.  
  158. strcpy_s(PNEnd, "-ый");
  159. }
  160. else {
  161. Torp = TorpedeP2;
  162. Destr = DestroyerP2;
  163. Crui = CruiserP2;
  164. BShip = BattleshipP2;
  165.  
  166. strcpy_s(PNEnd, "-ой");
  167. }
  168.  
  169. int nmb_of_cells_for_current_ship = 1;
  170. char type_of_ship[100];
  171. int plant_choise_x, plant_choise_y;
  172. int amount_of_checked_cells = 0;
  173.  
  174. while (amount_of_checked_cells < 21)
  175. {
  176. system("cls");
  177.  
  178. Print_table(arr);
  179.  
  180. if (nmb_of_cells_for_current_ship == 4)
  181. strcpy_s(type_of_ship, "линкор (4 клетки для размещения)");
  182.  
  183. if (nmb_of_cells_for_current_ship == 3)
  184. strcpy_s(type_of_ship, "крейсер (3 клетки для размещения)");
  185.  
  186. if (nmb_of_cells_for_current_ship == 2)
  187. strcpy_s(type_of_ship, "эсминец (2 клетки для размещения)");
  188.  
  189. if (nmb_of_cells_for_current_ship == 1)
  190. strcpy_s(type_of_ship, "торпедный катер (1 клетка для размещения)");
  191.  
  192.  
  193. cout << "Введите порядковый номер клетки, на которую " << PlayerNumber << PNEnd << " игрок хочет поместить кораблик (x,y).";
  194. cout << endl << "Помещается " << type_of_ship << "." << endl;
  195. cout << " Ваши координаты: ";
  196.  
  197. cin >> plant_choise_x >> plant_choise_y;
  198.  
  199. if (Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y] /* само место, куда ставится клетка*/) == false
  200. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1] /* верхняя правая клетка */) == false
  201. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1] /* нижняя левая клетка */) == false
  202. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1] /* верхняя левая клетка */) == false
  203. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1] /* нижняя правая клетка */) == false
  204. )
  205. {
  206.  
  207. if (
  208. Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false /* нижняя */
  209. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false /* верхняя */
  210. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 1]) == false /* левая */
  211. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 1]) == false /* правая */
  212. )
  213. {
  214. arr[plant_choise_x][plant_choise_y] = Torp;
  215. amount_of_checked_cells++;
  216. }
  217.  
  218.  
  219. else if (amount_of_checked_cells > 4 && amount_of_checked_cells < 12) {
  220.  
  221. if (nmb_of_cells_for_current_ship == 1)
  222. nmb_of_cells_for_current_ship++;
  223.  
  224. if (arr[plant_choise_x + 1][plant_choise_y] == Destr
  225. && (Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false
  226. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 1]) == false /// choise_cords (1)
  227. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 1]) == false
  228.  
  229. && Cell_checker(PlayerNumber, arr[plant_choise_x + 2][plant_choise_y - 1]) == false // [1]
  230. && Cell_checker(PlayerNumber, arr[plant_choise_x + 2][plant_choise_y + 1]) == false // [2]
  231. && Cell_checker(PlayerNumber, arr[plant_choise_x + 2][plant_choise_y]) == false /// choise_cords (2)
  232. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false
  233. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false
  234. )
  235. ||
  236. (arr[plant_choise_x - 1][plant_choise_y] == Destr // [2]
  237. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y]) == false // [1]
  238. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false /// choise_cords (1) // низ
  239. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false // нижнелевая клетка
  240. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false // нижнеправая клетка
  241. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 1]) == false // лево
  242. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 1]) == false // право
  243.  
  244. && Cell_checker(PlayerNumber, arr[plant_choise_x - 2][plant_choise_y]) == false /// choise_cords (2) // верх
  245. && Cell_checker(PlayerNumber, arr[plant_choise_x - 2][plant_choise_y - 1]) == false // верхнелевая клетка
  246. && Cell_checker(PlayerNumber, arr[plant_choise_x - 2][plant_choise_y + 1]) == false // верхнеправая клетка
  247. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1]) == false // левая
  248. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // правая
  249. )
  250. ||
  251. (
  252. arr[plant_choise_x][plant_choise_y + 1] == Destr // ---->
  253. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y]) == false // [1][2]
  254.  
  255. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false /// choise_cords (1) // низ
  256. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false // верх
  257. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false // нижнелевая клетка
  258. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1]) == false // верхнелевая клетка
  259. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 1]) == false // лево
  260.  
  261. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false /// choise_cords (2) // верх
  262. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false // низ
  263. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 2]) == false // верхнеправая клетка
  264. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 2]) == false // правая
  265. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 2]) == false // нижнеправая
  266. )
  267. ||
  268. (
  269. arr[plant_choise_x][plant_choise_y - 1] == Destr // [1] // [2][1]
  270. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false // верх (1)
  271. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false // низ
  272. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 1]) == false // правая
  273. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхнеправая клетка
  274. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false // нижнеправая кллетка
  275.  
  276. // [2]
  277. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 2]) == false // верхнелевая клетка
  278. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false // нижняя
  279. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1]) == false // верхняя
  280. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 2]) == false // левая
  281. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 2]) == false // верхнелевая
  282. )
  283. ||
  284. (
  285. Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y]) == false // сама клетка
  286. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false // верхняя
  287. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false // нижняя
  288. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 1]) == false // левая
  289. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 1]) == false // правая
  290. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1]) == false // верхнелевая
  291. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхнеправая
  292. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false // нижнелевая
  293. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false // нижнеправая
  294. )
  295.  
  296. ) {
  297. arr[plant_choise_x][plant_choise_y] = Destr;
  298. amount_of_checked_cells++;
  299. }
  300.  
  301. if (amount_of_checked_cells >= 12)
  302. {
  303. if (nmb_of_cells_for_current_ship == 2)
  304. nmb_of_cells_for_current_ship++;
  305.  
  306. /// [1][2][3]
  307.  
  308. //[1]
  309. if ((arr[plant_choise_x][plant_choise_y + 1] == Crui && arr[plant_choise_x][plant_choise_y + 2] == Crui
  310. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y]) == false
  311.  
  312. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false // верхняя
  313. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false // нижняя
  314. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 1]) == false // левая
  315. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1]) == false // верхнелевая
  316. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false // нижелевая
  317.  
  318. //[2]
  319. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхняя
  320. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false // нижнняя
  321.  
  322. //[3]
  323. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 2]) == false // верхняя
  324. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 2]) == false // нижняя
  325. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 3]) == false // правая
  326. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 3]) == false // верхнеправая
  327. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 3]) == false // нижнеправая
  328. )
  329. ||
  330.  
  331. /// [3][2][1]
  332. (
  333. Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y]) == false
  334. && arr[plant_choise_x][plant_choise_y - 1] == Crui && arr[plant_choise_x][plant_choise_y - 2] == Crui
  335.  
  336. // [1]
  337.  
  338. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false // верхняя
  339. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false // нижняя
  340. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 1]) == false // правая
  341. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхнеправая
  342. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false // нижнеправая
  343.  
  344. // [2]
  345.  
  346. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1]) == false // верхняя
  347. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false // нижняя
  348.  
  349. // [3]
  350.  
  351. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 2]) == false // верхняя
  352. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 2]) == false // нижняя
  353. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 3]) == false // левая
  354. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 3]) == false // верхнелевая
  355. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 3]) == false // нижнелевая
  356. )
  357. ||
  358. (
  359. Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y]) == false
  360. && arr[plant_choise_x][plant_choise_y - 1] == Crui && arr[plant_choise_x][plant_choise_y + 1] == Crui
  361.  
  362. /// [2][1][3]
  363. // [1]
  364. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false // верхняя
  365. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false // нижняя
  366.  
  367. // [2]
  368. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1]) == false // верхняя
  369. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false // нижняя
  370. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 2]) == false // левая
  371. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 2]) == false // верхнелевая
  372. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 2]) == false // нижнелевая
  373.  
  374. // [3]
  375. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхняя
  376. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false // нижняя
  377. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 2]) == false // правая
  378. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 2]) == false // верхнеправая
  379. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 2]) == false // нижеправая
  380. )
  381. ||
  382. (
  383. /*
  384. [1]
  385. [2]
  386. [3]
  387. */
  388.  
  389. Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y]) == false
  390. && arr[plant_choise_x + 1][plant_choise_y] == Crui && arr[plant_choise_x + 2][plant_choise_y] == Crui
  391.  
  392. // [1]
  393.  
  394. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false // верхняя
  395. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 1]) == false // левая
  396. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 1]) == false // правая
  397. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y - 1]) == false // верхнелевая
  398. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхнеправая
  399.  
  400. // [2]
  401.  
  402. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y - 1]) == false // левая
  403. && Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y + 1]) == false // правая
  404.  
  405. // [3]
  406.  
  407. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхняя
  408. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхняя
  409. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхняя
  410. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхняя
  411. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y + 1]) == false // верхняя
  412.  
  413.  
  414.  
  415. )
  416. ) {
  417. arr[plant_choise_x][plant_choise_y] = Crui;
  418. amount_of_checked_cells++;
  419. }
  420.  
  421. if (amount_of_checked_cells == 17)
  422. {
  423. if (nmb_of_cells_for_current_ship == 3)
  424. nmb_of_cells_for_current_ship++;
  425.  
  426. arr[plant_choise_x][plant_choise_y] = BShip;
  427. break;
  428. }
  429. }
  430. }
  431. }
  432.  
  433. else
  434. {
  435. system("cls");
  436. cout << "Введите правильную ячейку! " << endl;
  437. Sleep(1250);
  438. }
  439. }
  440. }
  441.  
  442. void Player_move(char arr1[][FIELD_SIZE], char arr2[][FIELD_SIZE], int
  443. PlayerNumber, char* p1, char* p2)
  444. {
  445. int choise_x;
  446. int choise_y;
  447.  
  448. while (true) {
  449. system("cls");
  450. choise_x = 0; choise_y = 0;
  451.  
  452. if (PlayerNumber == 1) {
  453.  
  454. Print_table(arr1);
  455.  
  456. cout << "n Введите координаты клетки, в которую вы хотите стрельнуть, " << p1 << ": ";
  457. cout << "n Вам осталось потопить клеток кораблей: " << amount_of_ship_cells_left_to_drown_P2;
  458. cin >> arr2[choise_x][choise_y];
  459.  
  460.  
  461. if ((arr2[choise_x][choise_y] == TorpedeP2
  462. || arr2[choise_x][choise_y] == DestroyerP2
  463. || arr2[choise_x][choise_y] == CruiserP2
  464. || arr2[choise_x][choise_y] == BattleshipP2)
  465. && arr2[choise_x][choise_y] != ShipHitP2
  466. && arr2[choise_x][choise_y] != HitMissP2)
  467. {
  468. arr2[choise_x][choise_y] = ShipHitP2;
  469. --amount_of_ship_cells_left_to_drown_P2;
  470. system("cls");
  471. cout << "Попадание!" << endl;
  472. system("pause");
  473. continue;
  474. }
  475.  
  476. else if (arr2[choise_x][choise_y] == ShipHitP2
  477. || arr2[choise_x][choise_y] == HitMissP2) {
  478. system("cls");
  479. cout << "Вы по этой клетке уже попадали!" << endl;
  480. system("pause");
  481. continue;
  482. }
  483.  
  484. else {
  485. arr2[choise_x][choise_y] = HitMissP2;
  486. system("cls");
  487. Pass2AnotherPlayer();
  488. break;
  489. }
  490. }
  491.  
  492. else {
  493. Print_table(arr2);
  494.  
  495. cout << "n Введите координаты клетки, в которую вы хотите стрельнуть, " << p2 << ": ";
  496. cout << "n Вам осталось потопить клеток кораблей: " << amount_of_ship_cells_left_to_drown_P1;
  497. cin >> arr1[choise_x][choise_y];
  498.  
  499. if ((arr1[choise_x][choise_y] == TorpedeP1
  500. || arr1[choise_x][choise_y] == DestroyerP1
  501. || arr1[choise_x][choise_y] == CruiserP1
  502. || arr1[choise_x][choise_y] == BattleshipP1)
  503. && arr1[choise_x][choise_y] != ShipHitP1
  504. && arr1[choise_x][choise_y] != HitMissP1)
  505. {
  506. arr1[choise_x][choise_y] = ShipHitP1;
  507. --amount_of_ship_cells_left_to_drown_P1;
  508. system("cls");
  509. cout << "Попадание!" << endl;
  510. system("pause");
  511. continue;
  512. }
  513.  
  514. else if (arr1[choise_x][choise_y] == ShipHitP1
  515. || arr1[choise_x][choise_y] == HitMissP1) {
  516. system("cls");
  517. cout << "Вы по этой клетке уже попадали!" << endl;
  518. system("pause");
  519. continue;
  520. }
  521.  
  522. else {
  523. arr1[choise_x][choise_y] = HitMissP1;
  524. system("cls");
  525. Pass2AnotherPlayer();
  526. break;
  527. }
  528. }
  529. }
  530. }
  531.  
  532. bool Win(int ship_cells) {
  533.  
  534. if (ship_cells == 0)
  535. return true;
  536. return false;
  537. }
  538.  
  539. int main()
  540. {
  541. srand((unsigned)time(0));
  542. setlocale(LC_ALL, "Russian");
  543.  
  544. char arr1[FIELD_SIZE][FIELD_SIZE];
  545. char arr2[FIELD_SIZE][FIELD_SIZE];
  546.  
  547. Players_names(Player1, Player2);
  548.  
  549. system("cls");
  550.  
  551. cout << "Имя первого игрока: " << Player1 << endl;
  552. cout << "Имя второго игрока: " << Player2 << endl << endl;
  553.  
  554. system("pause");
  555.  
  556. Create_table(arr1, WaterP1);
  557. Set_ships(arr1, 1);
  558.  
  559. Pass2AnotherPlayer();
  560.  
  561. Create_table(arr2, WaterP2);
  562. Set_ships(arr2, 2);
  563.  
  564. system("pause");
  565.  
  566. system("cls");
  567.  
  568. cout << "t BETA TEST" << endl << endl;
  569. cout << "Поле игрока с именем (или никнеймом) " << Player1 << endl;
  570. Print_table(arr1);
  571.  
  572. cout << endl;
  573.  
  574. cout << "Поле игрока с именем (или никнеймом) " << Player2 << endl;
  575. Print_table(arr2);
  576.  
  577.  
  578.  
  579. while (true)
  580. {
  581. Player_move(arr1, arr2, 1, Player1, Player2);
  582. Player_move(arr1, arr2, 2, Player1, Player2);
  583. Win(amount_of_ship_cells_left_to_drown_P1);
  584. Win(amount_of_ship_cells_left_to_drown_P2);
  585.  
  586. if (Win(amount_of_ship_cells_left_to_drown_P2) == true) {
  587. ifP1Win(Player1);
  588. }
  589.  
  590. else if (Win(amount_of_ship_cells_left_to_drown_P1) == true) {
  591. ifP2Win(Player2);
  592. }
  593.  
  594. cout << "Поле игрока с именем (никнеймом) " << Player1 << endl << endl;
  595. Print_table(arr1);
  596.  
  597. cout << endl;
  598.  
  599. cout << "Поле игрока с именем (никнеймом) " << Player2 << endl << endl;
  600. Print_table(arr2);
  601.  
  602. system("pause");
  603. }
  604.  
  605.  
  606.  
  607. system("pause");
  608. return 0;
  609. }
  610.  
  611. if (nmb_of_cells_for_current_ship == 4)
  612. strcpy_s(type_of_ship, "линкор (4 клетки для размещения)");
  613.  
  614. if (nmb_of_cells_for_current_ship == 3)
  615. strcpy_s(type_of_ship, "крейсер (3 клетки для размещения)");
  616.  
  617. if (nmb_of_cells_for_current_ship == 2)
  618. strcpy_s(type_of_ship, "эсминец (2 клетки для размещения)");
  619.  
  620. if (nmb_of_cells_for_current_ship == 1)
  621. strcpy_s(type_of_ship, "торпедный катер (1 клетка для размещения)");
  622.  
  623. if (
  624. Cell_checker(PlayerNumber, arr[plant_choise_x + 1][plant_choise_y]) == false /* нижняя */
  625. && Cell_checker(PlayerNumber, arr[plant_choise_x - 1][plant_choise_y]) == false /* верхняя */
  626. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y - 1]) == false /* левая */
  627. && Cell_checker(PlayerNumber, arr[plant_choise_x][plant_choise_y + 1]) == false /* правая */
  628. )
  629. {
  630. arr[plant_choise_x][plant_choise_y] = Torp;
  631. amount_of_checked_cells++;
  632. }
  633. else if (amount_of_checked_cells > 4 && amount_of_checked_cells < 12) {
  634.  
  635. if (nmb_of_cells_for_current_ship == 1)
  636. nmb_of_cells_for_current_ship++;
  637. ...
  638. }
  639.  
  640. if (условие1)
  641. {
  642. ...
  643. }
  644. else if (условие2)
  645. {
  646. ...
  647. }
  648. else if (условиеN)
  649. {
  650. ...
  651. }
  652. else
  653. {
  654. ...
  655. }
Add Comment
Please, Sign In to add comment