Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5.  
  6. int player1ShipPlacement();
  7. int player2ShipPlacement();
  8. int player1Turn();
  9. int player2Turn();
  10.  
  11. int player1Board[10][10] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  12. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  13. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  14. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  15. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  16. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  17. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  18. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  19. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  20. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
  21.  
  22. int player2Board[10][10] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  23. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  24. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  25. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  26. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  27. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  28. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  29. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  30. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  31. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
  32.  
  33. int player1BoardDisplayed[10][10] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  34. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  35. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  36. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  37. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  38. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  39. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  40. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  41. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  42. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
  43.  
  44. int player2BoardDisplayed[10][10] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  45. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  46. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  47. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  48. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  49. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  50. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  51. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  52. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  53. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
  54.  
  55. char carrierVertical;
  56. char battleshipVertical;
  57. char cruiserVertical;
  58. char submarineVertical;
  59. char destroyerVertical;
  60.  
  61. /*
  62. Carrier: 5
  63. Battleship: 4
  64. Cruiser: 3
  65. Submarine: 3
  66. Destroyer: 2
  67. */
  68.  
  69. int main() {
  70.  
  71. printf(" ____ ____ _ ____ _____ ____ _ _____ _____ _ _____ ____ _ _ ___ ____ ____ \n");
  72. printf("/ ___|| _ \\ / \\ / ___| ____| | __ ) / \\|_ _|_ _| | | ____/ ___|| | | |_ _| _ \\/ ___| \n");
  73. printf("\\___ \\| |_) / _ \\| | | _| | _ \\ / _ \\ | | | | | | | _| \\___ \\| |_| || || |_) \\___ \\ \n");
  74. printf(" ___) | __/ ___ \\ |___| |___ | |_) / ___ \\| | | | | |___| |___ ___) | _ || || __/ ___) |\n");
  75. printf("|____/|_| /_/ \\_\\____|_____| |____/_/ \\_\\_| |_| |_____|_____|____/|_| |_|___|_| |____/ \n\n");
  76.  
  77. int i;
  78. for (i=0;i<50;i++) {
  79. system("color 17");
  80. system("color 40");
  81. }
  82. system("color f0");
  83. system("pause");
  84. player1ShipPlacement();
  85. player2ShipPlacement();
  86.  
  87. return 0;
  88. }
  89.  
  90. int player1ShipPlacement() {
  91.  
  92. system("cls");
  93. system("color 0b");
  94. printf("PLAYER 1 SHIP PLACEMENT\n");
  95. bool check1 = false;
  96. bool check2 = false;
  97. bool check3 = false;
  98. bool check4 = false;
  99. bool check5 = false;
  100.  
  101. int coordinateX;
  102. int coordinateY;
  103.  
  104.  
  105. while (check1 == false) {
  106. printf("The carrier ship is 5 long. Would you like it to be vertical or horizontal?\n");
  107. fflush(stdin);
  108. scanf("%c", &carrierVertical);
  109. check1 = true;
  110. printf("Where would you like to place the carrier?\n");
  111. printf("X:\n");
  112. fflush(stdin);
  113. scanf("%d", &coordinateX);
  114. printf("Y:\n");
  115. fflush(stdin);
  116. scanf("%d", &coordinateY);
  117.  
  118. switch (carrierVertical){
  119.  
  120. case ('V'):
  121. if ((player1Board[coordinateX][coordinateY] == 0) &&
  122. (player1Board[coordinateX][coordinateY+1] == 0) &&
  123. (player1Board[coordinateX][coordinateY+2] == 0) &&
  124. (player1Board[coordinateX][coordinateY+3] == 0) &&
  125. (player1Board[coordinateX][coordinateY+4] == 0)) {
  126.  
  127. player1Board[coordinateX][coordinateY] = 1;
  128. player1Board[coordinateX][coordinateY + 1] = 1;
  129. player1Board[coordinateX][coordinateY + 2] = 1;
  130. player1Board[coordinateX][coordinateY + 3] = 1;
  131. player1Board[coordinateX][coordinateY + 4] = 1;
  132. } else {
  133. printf("Coordinates are invalid. Please try again.\n");
  134. check1 = false;
  135. }
  136.  
  137. break;
  138.  
  139. case ('H'):
  140. if ((player1Board[coordinateX][coordinateY] == 0) &&
  141. (player1Board[coordinateX + 1][coordinateY] == 0) &&
  142. (player1Board[coordinateX + 2][coordinateY] == 0) &&
  143. (player1Board[coordinateX + 3][coordinateY] == 0) &&
  144. (player1Board[coordinateX + 4][coordinateY] == 0)) {
  145.  
  146. player1Board[coordinateX][coordinateY] = 1;
  147. player1Board[coordinateX + 1][coordinateY] = 1;
  148. player1Board[coordinateX + 2][coordinateY] = 1;
  149. player1Board[coordinateX + 3][coordinateY] = 1;
  150. player1Board[coordinateX + 4][coordinateY] = 1;
  151. } else {
  152. printf("Coordinates are invalid. Please try again.\n");
  153. check1 = false;
  154. }
  155.  
  156. }
  157.  
  158. }
  159.  
  160.  
  161.  
  162. while (check2 == false) {
  163. check2 = true;
  164. printf("The battleship is 4 long. Would you like it to be vertical or horizontal?\n");
  165. fflush(stdin);
  166. scanf("%c", &battleshipVertical);
  167. printf("Where would you like to place the battleship?\n");
  168. printf("X:\n");
  169. fflush(stdin);
  170. scanf("%d", &coordinateX);
  171. printf("Y:\n");
  172. fflush(stdin);
  173. scanf("%d", &coordinateY);
  174.  
  175. switch (battleshipVertical){
  176.  
  177. case ('V'):
  178. if ((player1Board[coordinateX][coordinateY] == 0) &&
  179. (player1Board[coordinateX][coordinateY+1] == 0) &&
  180. (player1Board[coordinateX][coordinateY+2] == 0) &&
  181. (player1Board[coordinateX][coordinateY+3] == 0)) {
  182.  
  183. player1Board[coordinateX][coordinateY] = 1;
  184. player1Board[coordinateX][coordinateY + 1] = 1;
  185. player1Board[coordinateX][coordinateY + 2] = 1;
  186. player1Board[coordinateX][coordinateY + 3] = 1;
  187. } else {
  188. printf("Coordinates are invalid. Please try again.\n");
  189. check2 = false;
  190. }
  191.  
  192. break;
  193.  
  194. case ('H'):
  195. if ((player1Board[coordinateX][coordinateY] == 0) &&
  196. (player1Board[coordinateX + 1][coordinateY] == 0) &&
  197. (player1Board[coordinateX + 2][coordinateY] == 0) &&
  198. (player1Board[coordinateX + 3][coordinateY] == 0)) {
  199.  
  200. player1Board[coordinateX][coordinateY] = 1;
  201. player1Board[coordinateX + 1][coordinateY] = 1;
  202. player1Board[coordinateX + 2][coordinateY] = 1;
  203. player1Board[coordinateX + 3][coordinateY] = 1;
  204. } else {
  205. printf("Coordinates are invalid. Please try again.\n");
  206. check2 = false;
  207. }
  208.  
  209. break;
  210.  
  211. }
  212.  
  213. }
  214.  
  215. while (check3 == false) {
  216. printf("The cruiser ship is 3 long. Would you like it to be vertical or horizontal?\n");
  217. fflush(stdin);
  218. scanf("%c", &cruiserVertical);
  219. check3 = true;
  220. printf("Where would you like to place the cruiser?\n");
  221. printf("X:\n");
  222. fflush(stdin);
  223. scanf("%d", &coordinateX);
  224. printf("Y:\n");
  225. fflush(stdin);
  226. scanf("%d", &coordinateY);
  227.  
  228. switch (cruiserVertical){
  229.  
  230. case ('V'):
  231. if ((player1Board[coordinateX][coordinateY] == 0) &&
  232. (player1Board[coordinateX][coordinateY+1] == 0) &&
  233. (player1Board[coordinateX][coordinateY+2] == 0)) {
  234.  
  235. player1Board[coordinateX][coordinateY] = 1;
  236. player1Board[coordinateX][coordinateY + 1] = 1;
  237. player1Board[coordinateX][coordinateY + 2] = 1;
  238. } else {
  239. printf("Coordinates are invalid. Please try again.\n");
  240. check3 = false;
  241. }
  242.  
  243. break;
  244.  
  245. case ('H'):
  246. if ((player1Board[coordinateX][coordinateY] == 0) &&
  247. (player1Board[coordinateX + 1][coordinateY] == 0) &&
  248. (player1Board[coordinateX + 2][coordinateY] == 0)) {
  249.  
  250. player1Board[coordinateX][coordinateY] = 1;
  251. player1Board[coordinateX + 1][coordinateY] = 1;
  252. player1Board[coordinateX + 2][coordinateY] = 1;
  253. } else {
  254. printf("Coordinates are invalid. Please try again.\n");
  255. check3 = false;
  256. }
  257.  
  258. }
  259.  
  260. }
  261.  
  262. while (check4 == false) {
  263. printf("The submarine is 3 long. Would you like it to be vertical or horizontal?\n");
  264. fflush(stdin);
  265. scanf("%c", &submarineVertical);
  266. check4 = true;
  267. printf("Where would you like to place the submarine?\n");
  268. printf("X:\n");
  269. fflush(stdin);
  270. scanf("%d", &coordinateX);
  271. printf("Y:\n");
  272. fflush(stdin);
  273. scanf("%d", &coordinateY);
  274.  
  275. switch (submarineVertical){
  276.  
  277. case ('V'):
  278. if ((player1Board[coordinateX][coordinateY] == 0) &&
  279. (player1Board[coordinateX][coordinateY+1] == 0) &&
  280. (player1Board[coordinateX][coordinateY+2] == 0)) {
  281.  
  282. player1Board[coordinateX][coordinateY] = 1;
  283. player1Board[coordinateX][coordinateY + 1] = 1;
  284. player1Board[coordinateX][coordinateY + 2] = 1;
  285. } else {
  286. printf("Coordinates are invalid. Please try again.\n");
  287. check4 = false;
  288. }
  289.  
  290. break;
  291.  
  292. case ('H'):
  293. if ((player1Board[coordinateX][coordinateY] == 0) &&
  294. (player1Board[coordinateX + 1][coordinateY] == 0) &&
  295. (player1Board[coordinateX + 2][coordinateY] == 0)) {
  296.  
  297. player1Board[coordinateX][coordinateY] = 1;
  298. player1Board[coordinateX + 1][coordinateY] = 1;
  299. player1Board[coordinateX + 2][coordinateY] = 1;
  300. } else {
  301. printf("Coordinates are invalid. Please try again.\n");
  302. check4 = false;
  303. }
  304.  
  305. }
  306.  
  307. }
  308.  
  309.  
  310. while (check5 == false) {
  311. printf("The destroyer is 2 long. Would you like it to be vertical or horizontal?\n");
  312. fflush(stdin);
  313. scanf("%c", &destroyerVertical);
  314. check5 = true;
  315. printf("Where would you like to place the destroyer?\n");
  316. printf("X:\n");
  317. fflush(stdin);
  318. scanf("%d", &coordinateX);
  319. printf("Y:\n");
  320. fflush(stdin);
  321. scanf("%d", &coordinateY);
  322.  
  323. switch (submarineVertical){
  324.  
  325. case ('V'):
  326. if ((player1Board[coordinateX][coordinateY] == 0) &&
  327. (player1Board[coordinateX][coordinateY+1] == 0)) {
  328.  
  329. player1Board[coordinateX][coordinateY] = 1;
  330. player1Board[coordinateX][coordinateY + 1] = 1;
  331.  
  332. } else {
  333. printf("Coordinates are invalid. Please try again.\n");
  334. check5 = false;
  335. }
  336.  
  337. break;
  338.  
  339. case ('H'):
  340. if ((player1Board[coordinateX][coordinateY] == 0) &&
  341. (player1Board[coordinateX + 1][coordinateY] == 0)) {
  342.  
  343. player1Board[coordinateX][coordinateY] = 1;
  344. player1Board[coordinateX + 1][coordinateY] = 1;
  345. } else {
  346. printf("Coordinates are invalid. Please try again.\n");
  347. check5 = false;
  348. }
  349.  
  350. }
  351.  
  352. }
  353.  
  354. int w;
  355. int x;
  356. system("cls");
  357. printf("PLAYER 1 SHIP PLACEMENT:\n\n");
  358. for(w=0;w<10;w++) {
  359. for(x=0;x<10;x++) {
  360. printf("%d ", player1Board[x][w]);
  361. }
  362. printf("\n\n");
  363. }
  364. system("pause");
  365.  
  366. return 0;
  367. }
  368.  
  369. int player2ShipPlacement() {
  370.  
  371. system("cls");
  372. system("color 0c");
  373. printf("PLAYER 2 SHIP PLACEMENT\n");
  374. bool check1 = false;
  375. bool check2 = false;
  376. bool check3 = false;
  377. bool check4 = false;
  378. bool check5 = false;
  379.  
  380. int coordinateX;
  381. int coordinateY;
  382.  
  383.  
  384. while (check1 == false) {
  385. printf("The carrier ship is 5 long. Would you like it to be vertical or horizontal?\n");
  386. fflush(stdin);
  387. scanf("%c", &carrierVertical);
  388. check1 = true;
  389. printf("Where would you like to place the carrier?\n");
  390. printf("X:\n");
  391. fflush(stdin);
  392. scanf("%d", &coordinateX);
  393. printf("Y:\n");
  394. fflush(stdin);
  395. scanf("%d", &coordinateY);
  396.  
  397. switch (carrierVertical){
  398.  
  399. case ('V'):
  400. if ((player2Board[coordinateX][coordinateY] == 0) &&
  401. (player2Board[coordinateX][coordinateY+1] == 0) &&
  402. (player2Board[coordinateX][coordinateY+2] == 0) &&
  403. (player2Board[coordinateX][coordinateY+3] == 0) &&
  404. (player2Board[coordinateX][coordinateY+4] == 0)) {
  405.  
  406. player2Board[coordinateX][coordinateY] = 1;
  407. player2Board[coordinateX][coordinateY + 1] = 1;
  408. player2Board[coordinateX][coordinateY + 2] = 1;
  409. player2Board[coordinateX][coordinateY + 3] = 1;
  410. player2Board[coordinateX][coordinateY + 4] = 1;
  411. } else {
  412. printf("Coordinates are invalid. Please try again.\n");
  413. check1 = false;
  414. }
  415.  
  416. break;
  417.  
  418. case ('H'):
  419. if ((player2Board[coordinateX][coordinateY] == 0) &&
  420. (player2Board[coordinateX + 1][coordinateY] == 0) &&
  421. (player2Board[coordinateX + 2][coordinateY] == 0) &&
  422. (player2Board[coordinateX + 3][coordinateY] == 0) &&
  423. (player2Board[coordinateX + 4][coordinateY] == 0)) {
  424.  
  425. player2Board[coordinateX][coordinateY] = 1;
  426. player2Board[coordinateX + 1][coordinateY] = 1;
  427. player2Board[coordinateX + 2][coordinateY] = 1;
  428. player2Board[coordinateX + 3][coordinateY] = 1;
  429. player2Board[coordinateX + 4][coordinateY] = 1;
  430. } else {
  431. printf("Coordinates are invalid. Please try again.\n");
  432. check1 = false;
  433. }
  434.  
  435. }
  436.  
  437. }
  438.  
  439.  
  440.  
  441. while (check2 == false) {
  442. check2 = true;
  443. printf("The battleship is 4 long. Would you like it to be vertical or horizontal?\n");
  444. fflush(stdin);
  445. scanf("%c", &battleshipVertical);
  446. printf("Where would you like to place the battleship?\n");
  447. printf("X:\n");
  448. fflush(stdin);
  449. scanf("%d", &coordinateX);
  450. printf("Y:\n");
  451. fflush(stdin);
  452. scanf("%d", &coordinateY);
  453.  
  454. switch (battleshipVertical){
  455.  
  456. case ('V'):
  457. if ((player2Board[coordinateX][coordinateY] == 0) &&
  458. (player2Board[coordinateX][coordinateY+1] == 0) &&
  459. (player2Board[coordinateX][coordinateY+2] == 0) &&
  460. (player2Board[coordinateX][coordinateY+3] == 0)) {
  461.  
  462. player2Board[coordinateX][coordinateY] = 1;
  463. player2Board[coordinateX][coordinateY + 1] = 1;
  464. player2Board[coordinateX][coordinateY + 2] = 1;
  465. player2Board[coordinateX][coordinateY + 3] = 1;
  466. } else {
  467. printf("Coordinates are invalid. Please try again.\n");
  468. check2 = false;
  469. }
  470.  
  471. break;
  472.  
  473. case ('H'):
  474. if ((player2Board[coordinateX][coordinateY] == 0) &&
  475. (player2Board[coordinateX + 1][coordinateY] == 0) &&
  476. (player2Board[coordinateX + 2][coordinateY] == 0) &&
  477. (player2Board[coordinateX + 3][coordinateY] == 0)) {
  478.  
  479. player2Board[coordinateX][coordinateY] = 1;
  480. player2Board[coordinateX + 1][coordinateY] = 1;
  481. player2Board[coordinateX + 2][coordinateY] = 1;
  482. player2Board[coordinateX + 3][coordinateY] = 1;
  483. } else {
  484. printf("Coordinates are invalid. Please try again.\n");
  485. check2 = false;
  486. }
  487.  
  488. break;
  489.  
  490. }
  491.  
  492. }
  493.  
  494. while (check3 == false) {
  495. printf("The cruiser ship is 3 long. Would you like it to be vertical or horizontal?\n");
  496. fflush(stdin);
  497. scanf("%c", &cruiserVertical);
  498. check3 = true;
  499. printf("Where would you like to place the cruiser?\n");
  500. printf("X:\n");
  501. fflush(stdin);
  502. scanf("%d", &coordinateX);
  503. printf("Y:\n");
  504. fflush(stdin);
  505. scanf("%d", &coordinateY);
  506.  
  507. switch (cruiserVertical){
  508.  
  509. case ('V'):
  510. if ((player2Board[coordinateX][coordinateY] == 0) &&
  511. (player2Board[coordinateX][coordinateY+1] == 0) &&
  512. (player2Board[coordinateX][coordinateY+2] == 0)) {
  513.  
  514. player2Board[coordinateX][coordinateY] = 1;
  515. player2Board[coordinateX][coordinateY + 1] = 1;
  516. player2Board[coordinateX][coordinateY + 2] = 1;
  517. } else {
  518. printf("Coordinates are invalid. Please try again.\n");
  519. check3 = false;
  520. }
  521.  
  522. break;
  523.  
  524. case ('H'):
  525. if ((player2Board[coordinateX][coordinateY] == 0) &&
  526. (player2Board[coordinateX + 1][coordinateY] == 0) &&
  527. (player2Board[coordinateX + 2][coordinateY] == 0)) {
  528.  
  529. player2Board[coordinateX][coordinateY] = 1;
  530. player2Board[coordinateX + 1][coordinateY] = 1;
  531. player2Board[coordinateX + 2][coordinateY] = 1;
  532. } else {
  533. printf("Coordinates are invalid. Please try again.\n");
  534. check3 = false;
  535. }
  536.  
  537. }
  538.  
  539. }
  540.  
  541. while (check4 == false) {
  542. printf("The submarine is 3 long. Would you like it to be vertical or horizontal?\n");
  543. fflush(stdin);
  544. scanf("%c", &submarineVertical);
  545. check4 = true;
  546. printf("Where would you like to place the submarine?\n");
  547. printf("X:\n");
  548. fflush(stdin);
  549. scanf("%d", &coordinateX);
  550. printf("Y:\n");
  551. fflush(stdin);
  552. scanf("%d", &coordinateY);
  553.  
  554. switch (submarineVertical){
  555.  
  556. case ('V'):
  557. if ((player2Board[coordinateX][coordinateY] == 0) &&
  558. (player2Board[coordinateX][coordinateY+1] == 0) &&
  559. (player2Board[coordinateX][coordinateY+2] == 0)) {
  560.  
  561. player2Board[coordinateX][coordinateY] = 1;
  562. player2Board[coordinateX][coordinateY + 1] = 1;
  563. player2Board[coordinateX][coordinateY + 2] = 1;
  564. } else {
  565. printf("Coordinates are invalid. Please try again.\n");
  566. check4 = false;
  567. }
  568.  
  569. break;
  570.  
  571. case ('H'):
  572. if ((player2Board[coordinateX][coordinateY] == 0) &&
  573. (player2Board[coordinateX + 1][coordinateY] == 0) &&
  574. (player2Board[coordinateX + 2][coordinateY] == 0)) {
  575.  
  576. player2Board[coordinateX][coordinateY] = 1;
  577. player2Board[coordinateX + 1][coordinateY] = 1;
  578. player2Board[coordinateX + 2][coordinateY] = 1;
  579. } else {
  580. printf("Coordinates are invalid. Please try again.\n");
  581. check4 = false;
  582. }
  583.  
  584. }
  585.  
  586. }
  587.  
  588.  
  589. while (check5 == false) {
  590. printf("The destroyer is 2 long. Would you like it to be vertical or horizontal?\n");
  591. fflush(stdin);
  592. scanf("%c", &destroyerVertical);
  593. check5 = true;
  594. printf("Where would you like to place the destroyer?\n");
  595. printf("X:\n");
  596. fflush(stdin);
  597. scanf("%d", &coordinateX);
  598. printf("Y:\n");
  599. fflush(stdin);
  600. scanf("%d", &coordinateY);
  601.  
  602. switch (submarineVertical){
  603.  
  604. case ('V'):
  605. if ((player2Board[coordinateX][coordinateY] == 0) &&
  606. (player2Board[coordinateX][coordinateY+1] == 0)) {
  607.  
  608. player2Board[coordinateX][coordinateY] = 1;
  609. player2Board[coordinateX][coordinateY + 1] = 1;
  610.  
  611. } else {
  612. printf("Coordinates are invalid. Please try again.\n");
  613. check5 = false;
  614. }
  615.  
  616. break;
  617.  
  618. case ('H'):
  619. if ((player2Board[coordinateX][coordinateY] == 0) &&
  620. (player2Board[coordinateX + 1][coordinateY] == 0)) {
  621.  
  622. player2Board[coordinateX][coordinateY] = 1;
  623. player2Board[coordinateX + 1][coordinateY] = 1;
  624. } else {
  625. printf("Coordinates are invalid. Please try again.\n");
  626. check5 = false;
  627. }
  628.  
  629. }
  630.  
  631. }
  632.  
  633. int w;
  634. int x;
  635. system("cls");
  636. printf("PLAYER 2 SHIP PLACEMENT:\n\n");
  637. for(w=0;w<10;w++) {
  638. for(x=0;x<10;x++) {
  639. printf("%d ", player2Board[x][w]);
  640. }
  641. printf("\n\n");
  642. }
  643. system("pause");
  644.  
  645. return 0;
  646. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement