Advertisement
Guest User

safasfasfa

a guest
Dec 8th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.39 KB | None | 0 0
  1. #include <iostream>
  2. #include<stdlib.h>
  3. #include <cstdlib>
  4. #include <time.h>
  5. #include<conio.h>
  6. #define ROZMIARTALII 52
  7. using namespace std;
  8.  
  9.  
  10. enum kolor
  11. {
  12. pik, kier, trefl, karo
  13. };
  14. enum ranga
  15. {
  16. II, III, IV, V, VI, VII, VIII, IX, X, walet, dama, krol, as
  17. };
  18. typedef struct Karta
  19. {
  20. int wartosc;
  21. int kolor;
  22. }Karta_t;
  23. Karta_t talia[ROZMIARTALII];
  24.  
  25.  
  26.  
  27.  
  28.  
  29. //deklaracje funkcji
  30.  
  31. void q_add(Karta_t hand[], Karta_t card); // funkcja dodaje kartę na koniec ręki
  32. Karta_t q_remove(Karta_t hand[]); // funkcja zwraca pierwszą kartę w ręce i ją usuwa
  33. int count_cards(Karta_t hand[]); // funkcja zlicza karty w ręce bądź stole
  34. void play(Karta_t P1_hand[], Karta_t P2_hand[]); // funkcja rozgrywa 1 turę gry
  35. int war(Karta_t P1_hand[], Karta_t P2_hand[], Karta_t card_1, Karta_t card_2); // funkcja zwraca nr gracza który wygrywa wojnę
  36. void clear_table(Karta_t table[], int i); // funkcja czyści stół po każdej wojnie
  37. void drukujKarte(Karta_t karta);//drukuje podana karte
  38. void wypiszTalie(Karta_t* karta);
  39. void tasowanie(Karta_t* tablica, int n);
  40. void rozdanie(Karta_t reka1[], Karta_t reka2[]);
  41. void generujTalie();
  42. void playA(Karta_t P1_hand[], Karta_t P2_hand[]);
  43. int warA(Karta_t P1_hand[], Karta_t P2_hand[], Karta_t card_1, Karta_t card_2);
  44. void playA(Karta_t P1_hand[], Karta_t P2_hand[]);
  45. int warB(Karta_t P1_hand[], Karta_t P2_hand[], Karta_t card_1, Karta_t card_2);
  46. void playB(Karta_t P1_hand[], Karta_t P2_hand[]);
  47. int main()
  48. {
  49. Karta_t P1_hand[ROZMIARTALII];
  50. Karta_t P2_hand[ROZMIARTALII];
  51.  
  52.  
  53. int P1_cards_count = ROZMIARTALII / 2, P2_cards_count = ROZMIARTALII / 2;
  54. int* P1_count = &P1_cards_count;
  55. int* P2_count = &P2_cards_count;
  56. srand(time(NULL));
  57. generujTalie();
  58. tasowanie(talia,ROZMIARTALII);
  59. //wypiszTalie(talia);
  60. rozdanie(P1_hand, P2_hand);
  61. int wybor = 0;
  62. int ruchy = 0;
  63. cout << "Both players are ready, let's start the game!" << endl << "Press button in order to proceed in the game"<<endl;
  64. cout << "WYBIERZ RODZAJ WOJNY A==1 LUB B==2"<<endl;
  65.  
  66. cin >> wybor;
  67. if (wybor == 1) {
  68. while (P1_cards_count > 0 && P2_cards_count > 0) {
  69. playA(P1_hand, P2_hand);
  70. ruchy++;
  71. P1_cards_count = count_cards(P1_hand);
  72. P2_cards_count = count_cards(P2_hand);
  73. if (P1_cards_count == 0) cout << "Player 2 has won the game!" << "IT took " << ruchy << " moves to end the game";
  74. else if (P2_cards_count == 0) cout << "Player 1 has won the game!" << "IT took " << ruchy << " moves to end the game";
  75.  
  76. }
  77. }
  78. if (wybor == 2) {
  79. while (P1_cards_count > 0 && P2_cards_count > 0) {
  80. playB(P1_hand, P2_hand);
  81. ruchy++;
  82. P1_cards_count = count_cards(P1_hand);
  83. P2_cards_count = count_cards(P2_hand);
  84. if (P1_cards_count == 0) cout << "Player 2 has won the game!" << "IT took " << ruchy << " moves to end the game";
  85. else if (P2_cards_count == 0) cout << "Player 1 has won the game!" << "IT took " << ruchy << " moves to end the game";
  86.  
  87. }
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94. }
  95.  
  96.  
  97. void q_add(Karta_t hand[], Karta_t card) {
  98. hand[count_cards(hand)] = card;
  99. }
  100.  
  101. Karta_t q_remove(Karta_t hand[]) {
  102. Karta_t card = hand[0];
  103. for (int i = 0; i < count_cards(hand); ++i) {
  104. hand[i] = hand[i + 1];
  105. }
  106. return card;
  107. }
  108. int count_cards(Karta_t hand[]) {
  109. int count = 0;
  110. for (int i = 0; i < ROZMIARTALII; ++i) {
  111. if (hand[i].wartosc >= II && hand[i].wartosc <= as) count++;
  112. }
  113. return count;
  114. }
  115.  
  116. void play(Karta_t P1_hand[], Karta_t P2_hand[]) {
  117.  
  118. Karta_t card_1 = q_remove(P1_hand);
  119. Karta_t card_2 = q_remove(P2_hand);
  120.  
  121. drukujKarte(card_1); cout << " VS "; drukujKarte(card_2); cout << endl;
  122.  
  123. if (card_1.wartosc > card_2.wartosc) {
  124. q_add(P1_hand, card_1);
  125. q_add(P1_hand, card_2);
  126. cout << "Player 1 wins this turn and takes both cards! He now has " << count_cards(P1_hand) << "cards " << endl << endl;
  127. cout << "P1 has " << count_cards(P1_hand) << " cards, and P2 has " << count_cards(P2_hand) << " cards " << endl;
  128. }
  129. else if (card_1.wartosc < card_2.wartosc) {
  130. q_add(P2_hand, card_2);
  131. q_add(P2_hand, card_1);
  132. cout << "Player 2 wins this turn and takes both cards! He now has" << count_cards(P2_hand) << "cards" << endl << endl;
  133. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  134. }
  135.  
  136. else if (card_1.wartosc == card_2.wartosc) {
  137. war(P1_hand, P2_hand, card_1, card_2);
  138. cout << endl;
  139. }
  140.  
  141.  
  142. }
  143.  
  144. int war(Karta_t P1_hand[], Karta_t P2_hand[], Karta_t card_1, Karta_t card_2) {
  145. cout << endl << " War!those 2 card values are the same!" << endl;
  146.  
  147. int p1_count = count_cards(P1_hand);
  148. int p2_count = count_cards(P2_hand);
  149.  
  150. Karta_t table[ROZMIARTALII];
  151. q_add(table, card_1);
  152. q_add(table, card_2);
  153.  
  154. int winner = 0; // zmienna sprawdzająca kto jest zwycięzcą wojny
  155. while (winner == 0) {
  156.  
  157. q_add(table, q_remove(P1_hand));
  158. q_add(table, q_remove(P2_hand));
  159. cout<<"Both players now put unknown cards on the table" << endl;
  160. Karta_t visible_1 = q_remove(P1_hand);
  161. Karta_t visible_2 = q_remove(P2_hand);
  162. cout << "Now they put another card which is visible on the table:" << endl;
  163. drukujKarte(visible_1); cout << "VS"; drukujKarte(visible_2);
  164. q_add(table, visible_1);
  165. q_add(table, visible_2);
  166.  
  167. int i = count_cards(table) - 1; // i to ostatni indeks pod którym znajduje się karta w tablicy stołu
  168.  
  169. if (table[i].wartosc < table[i - 1].wartosc) {
  170.  
  171. for (int j = 0; j <= i; ++j) {
  172. if (j % 2 == 0) q_add(P1_hand, table[j]);
  173. }
  174. for (int j = 0; j <= i; ++j) {
  175. if (j % 2 == 1) q_add(P1_hand, table[j]);
  176. }
  177. cout << "Player 1 wins the war and takes all these cards! He now has" <<count_cards(P1_hand)<< "cards" << endl;
  178. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  179. winner = 1;
  180. clear_table(table, i);
  181. return winner;
  182.  
  183. }
  184. else if (table[i].wartosc > table[i - 1].wartosc) {
  185.  
  186. for (int j = 0; j <= i; ++j) {
  187. if (j % 2 == 1) {
  188. q_add(P2_hand, table[j]);
  189. }
  190. }
  191. for (int j = 0; j <= i; ++j) {
  192. if (j % 2 == 0) {
  193. q_add(P2_hand, table[j]);
  194. }
  195. }
  196. cout << "Player 2 wins the war and takes all these cards! He now has" << count_cards(P2_hand) << "cards" << endl;
  197. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  198. winner = 2;
  199. clear_table(table, i);
  200. return winner;
  201.  
  202. }
  203. else if (table[i + 1].wartosc == table[i].wartosc) {
  204. winner = war(P1_hand, P2_hand, table[i], table[i + 1]);
  205.  
  206. }
  207.  
  208. }
  209. return winner;
  210. }
  211.  
  212. void clear_table(Karta_t table[], int i) {
  213. for (int j = 0; j <= i; ++j) {
  214. q_remove(table);
  215. }
  216. }
  217. void drukujKarte(Karta_t karta)
  218. {
  219. const char* rangiKart[] = {
  220. "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "Jack", "Queen", "King", "Ace"
  221. };
  222. const char* koloryKart[] = {
  223. "Spade","Heart","Club","Diamond"
  224. };
  225. cout << rangiKart[karta.wartosc] << " " << koloryKart[karta.kolor] << " ";
  226.  
  227. }
  228. void wypiszTalie(Karta_t* karta)
  229. {
  230. const char* rangiKart[] = {
  231. "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "Jack", "Queen", "King", "Ace"
  232. };
  233. const char* koloryKart[] = {
  234. "Spade","Heart","Club","Diamond"
  235. };
  236.  
  237. for (int a = 0; a < ROZMIARTALII; a++)
  238.  
  239. {
  240. cout << rangiKart[talia[a].wartosc] << " " << koloryKart[talia[a].kolor] << endl;
  241.  
  242. }
  243. }
  244. void tasowanie(Karta_t* tablica, int n)
  245. {
  246. if (n > 1)
  247. {
  248. int i;
  249. for (i = 0; i < n - 1; i++)
  250. {
  251. int j = i + rand() / (RAND_MAX / (n - i) + 1);
  252. Karta t = tablica[j];
  253. tablica[j] = tablica[i];
  254. tablica[i] = t;
  255. }
  256. }
  257. }
  258. void generujTalie()
  259. {
  260.  
  261. int i = 0;
  262. for (int k = karo; k >= pik; k--)
  263. for (int w = as; w >= II; w--, i++)
  264. {
  265. talia[i].kolor = k;
  266. talia[i].wartosc = w;
  267.  
  268. }
  269.  
  270. }
  271. void rozdanie(Karta_t reka1[], Karta_t reka2[]) {
  272. int i = 0;
  273. int k = 0;
  274. while (i < ROZMIARTALII / 2) {
  275.  
  276.  
  277. reka1[i] = talia[k];
  278. k++;
  279. ++i;
  280. }
  281.  
  282.  
  283. int j = 0;
  284. while (j < ROZMIARTALII / 2) {
  285. reka2[j] = talia[k];
  286. k++;
  287. ++j;
  288. }
  289.  
  290. }
  291. int warA(Karta_t P1_hand[], Karta_t P2_hand[], Karta_t card_1, Karta_t card_2) {
  292. cout << endl << " War!those 2 card values are the same!" << endl;
  293.  
  294. int p1_count = count_cards(P1_hand);
  295. int p2_count = count_cards(P2_hand);
  296.  
  297. Karta_t table[ROZMIARTALII];
  298.  
  299. q_add(table, card_1);
  300. q_add(table, card_2);
  301.  
  302. int winner = 0; // zmienna sprawdzająca kto jest zwycięzcą wojny
  303. while (winner == 0) {
  304. cout << "Both players now put unknown cards on the table" << endl;
  305. q_add(table, q_remove(P1_hand));
  306. q_add(table, q_remove(P2_hand));
  307.  
  308.  
  309. if (count_cards(P1_hand) == 0) {
  310. cout << "PLAYER 1 RAN OUT OF CARDS PLAYER 2 WINS";
  311. int i = count_cards(table)-1;
  312. for (int j = 0; j <= i; ++j) {
  313. q_add(P2_hand, table[j]);
  314. }
  315.  
  316.  
  317. winner = 2;
  318. clear_table(table, i);
  319. return winner;
  320. }
  321. if (count_cards(P2_hand) == 0) {
  322. cout << "PLAYER 2 RAN OUT OF CARDS PLAYER 1 WINS";
  323. int i = count_cards(table)-1;
  324. for (int j = 0; j <= i; ++j) {
  325. q_add(P1_hand, table[j]);
  326. }
  327.  
  328.  
  329. winner = 1;
  330. clear_table(table, i);
  331. return winner;
  332. }
  333.  
  334.  
  335. cout << "Now they put another card which is visible on the table:" << endl;
  336. Karta_t visible_1 = q_remove(P1_hand);
  337. Karta_t visible_2 = q_remove(P2_hand);
  338.  
  339.  
  340.  
  341. if (count_cards(P1_hand) == 0) {
  342. cout << "PLAYER 1 RAN OUT OF CARDS PLAYER 2 WINS";
  343. int i = count_cards(table)-1;
  344. for (int j = 0; j <= i; ++j) {
  345. q_add(P2_hand, table[j]);
  346. }
  347.  
  348.  
  349. winner = 2;
  350. clear_table(table, i);
  351. return winner;
  352. }
  353. if (count_cards(P2_hand) == 0) {
  354. cout << "PLAYER 2 RAN OUT OF CARDS PLAYER 1 WINS";
  355. int i = count_cards(table) -1;
  356. for (int j = 0; j <= i; ++j) {
  357. q_add(P1_hand, table[j]);
  358. }
  359.  
  360.  
  361. winner = 1;
  362. clear_table(table, i);
  363. return winner;
  364. }
  365.  
  366.  
  367.  
  368. drukujKarte(visible_1); cout << "VS"; drukujKarte(visible_2);
  369. q_add(table, visible_1);
  370. q_add(table, visible_2);
  371.  
  372. int i = count_cards(table) - 1; // i to ostatni indeks pod którym znajduje się karta w tablicy stołu
  373.  
  374. if (table[i].wartosc < table[i - 1].wartosc ) {
  375.  
  376. for (int j = 0; j <= i; ++j) {
  377. if (j % 2 == 0) q_add(P1_hand, table[j]);
  378. }
  379. for (int j = 0; j <= i; ++j) {
  380. if (j % 2 == 1) q_add(P1_hand, table[j]);
  381. }
  382. cout << "Player 1 wins the war and takes all these cards! He now has" << count_cards(P1_hand) << "cards" << endl;
  383. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  384. winner = 1;
  385. clear_table(table, i);
  386. return winner;
  387.  
  388. }
  389. else if (table[i].wartosc > table[i - 1].wartosc) {
  390.  
  391. for (int j = 0; j <= i; ++j) {
  392. if (j % 2 == 1) {
  393. q_add(P2_hand, table[j]);
  394. }
  395. }
  396. for (int j = 0; j <= i; ++j) {
  397. if (j % 2 == 0) {
  398. q_add(P2_hand, table[j]);
  399. }
  400. }
  401. cout << "Player 2 wins the war and takes all these cards! He now has" << count_cards(P2_hand) << "cards" << endl;
  402. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  403. winner = 2;
  404. clear_table(table, i);
  405. return winner;
  406.  
  407. }
  408. else if (table[i + 1].wartosc == table[i].wartosc) {
  409. winner = warA(P1_hand, P2_hand, table[i], table[i + 1]);
  410.  
  411. }
  412.  
  413. }
  414. return winner;
  415. }
  416. void playA(Karta_t P1_hand[], Karta_t P2_hand[]) {
  417.  
  418. Karta_t card_1 = q_remove(P1_hand);
  419. Karta_t card_2 = q_remove(P2_hand);
  420.  
  421. drukujKarte(card_1); cout << " VS "; drukujKarte(card_2); cout << endl;
  422.  
  423. if (card_1.wartosc > card_2.wartosc) {
  424. q_add(P1_hand, card_1);
  425. q_add(P1_hand, card_2);
  426. cout << "Player 1 wins this turn and takes both cards! He now has " << count_cards(P1_hand) << "cards " << endl << endl;
  427. cout << "P1 has " << count_cards(P1_hand) << " cards, and P2 has " << count_cards(P2_hand) << " cards " << endl;
  428. }
  429. else if (card_1.wartosc < card_2.wartosc) {
  430. q_add(P2_hand, card_2);
  431. q_add(P2_hand, card_1);
  432. cout << "Player 2 wins this turn and takes both cards! He now has" << count_cards(P2_hand) << "cards" << endl << endl;
  433. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  434. }
  435.  
  436. else if (card_1.wartosc == card_2.wartosc) {
  437. warA(P1_hand, P2_hand, card_1, card_2);
  438. cout << endl;
  439. }
  440.  
  441.  
  442. }
  443. int warB(Karta_t P1_hand[], Karta_t P2_hand[], Karta_t card_1, Karta_t card_2) {
  444. cout << endl << " War! those 2 card values are the same!" << endl;
  445.  
  446. int p1_count = count_cards(P1_hand);
  447. int p2_count = count_cards(P2_hand);
  448.  
  449. Karta_t table1[ROZMIARTALII];//stos gracza 1
  450. Karta_t table2[ROZMIARTALII];//stos gracza 2
  451. Karta_t table[ROZMIARTALII];
  452. q_add(table1, card_1);
  453. q_add(table2, card_2);
  454. q_add(table, card_1);
  455. q_add(table, card_2);
  456.  
  457. int winner = 0; // zmienna sprawdzająca kto jest zwycięzcą wojny
  458. while (winner == 0) {
  459.  
  460.  
  461. if (count_cards(P1_hand) == 0) {
  462. cout << "PLAYER 1 has started war with only 1 card so PLAYER 2 puts 2 cards for him then 2 for himself" << endl;
  463. q_add(table1, q_remove(P2_hand));//zakryta
  464. Karta_t visible_b1 = q_remove(P2_hand);
  465. q_add(table1,visible_b1);//odkryta
  466.  
  467.  
  468. q_add(table2, q_remove(P2_hand));//zakryta
  469. Karta_t visible_b2 = q_remove(P2_hand);
  470. q_add(table2, visible_b2);//odkryta
  471. drukujKarte(visible_b1); cout << "VS"; drukujKarte(visible_b2);
  472. int a = count_cards(table1) - 1;
  473. int b = count_cards(table2) - 1;
  474.  
  475. if (table1[a].wartosc>table2[b].wartosc) {
  476. for (int j = 0; j <= a; ++j) {
  477. q_add(P1_hand, table1[j]);
  478. q_add(P1_hand, table2[j]);
  479. }
  480. cout << "Player 1 wins the war and takes all these cards! He now has" << count_cards(P1_hand) << "cards" << endl;
  481. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  482. winner = 1;
  483. clear_table(table1, a);
  484. clear_table(table2, b);
  485. return winner;
  486.  
  487. }
  488. else if (table1[a].wartosc < table2[b].wartosc) {
  489. for (int j = 0; j <= a; ++j) {
  490. q_add(P2_hand, table1[j]);
  491. q_add(P2_hand, table2[j]);
  492. }
  493. cout << "Player 2 wins the war and takes all these cards! He now has" << count_cards(P2_hand) << "cards" << endl;
  494. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  495. winner = 2;
  496. clear_table(table1, a);
  497. clear_table(table2, b);
  498. return winner;
  499.  
  500. }
  501.  
  502.  
  503. }
  504.  
  505. if (count_cards(P2_hand) == 0) {
  506. cout << "PLAYER 2 has started war with only 1 card so PLAYER 1 puts 2 cards for him then 2 for himself" << endl;
  507. q_add(table2, q_remove(P1_hand));//zakryta
  508. Karta_t visible_b1 = q_remove(P1_hand);
  509. q_add(table2, visible_b1);//odkryta
  510.  
  511.  
  512. q_add(table1, q_remove(P1_hand));//zakryta
  513. Karta_t visible_b2 = q_remove(P1_hand);
  514. q_add(table1,visible_b2);//odkryta
  515. drukujKarte(visible_b1); cout << "VS"; drukujKarte(visible_b2);
  516.  
  517.  
  518. int a = count_cards(table1) - 1;
  519. int b = count_cards(table2) - 1;
  520.  
  521. if (table1[a].wartosc > table2[b].wartosc) {
  522. for (int j = 0; j <= a; ++j) {
  523. q_add(P1_hand, table1[j]);
  524. q_add(P1_hand, table2[j]);
  525. }
  526. cout << "Player 1 wins the war and takes all these cards! He now has" << count_cards(P1_hand) << "cards" << endl;
  527. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  528. winner = 1;
  529. clear_table(table1, a);
  530. clear_table(table2, b);
  531. return winner;
  532.  
  533. }
  534. else if (table1[a].wartosc < table2[b].wartosc) {
  535. for (int j = 0; j <= a; ++j) {
  536. q_add(P2_hand, table1[j]);
  537. q_add(P2_hand, table2[j]);
  538. }
  539. cout << "Player 2 wins the war and takes all these cards! He now has" << count_cards(P2_hand) << "cards" << endl;
  540. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  541. winner = 2;
  542. clear_table(table1, a);
  543. clear_table(table2, b);
  544. return winner;
  545.  
  546. }
  547. else if (table1[a].wartosc == table2[b].wartosc) {
  548. winner = warB(P1_hand, P2_hand, table1[a], table[b]);
  549. }
  550. }
  551.  
  552. else {
  553. cout << "Both players now put unknown cards on the table" << endl;
  554. q_add(table, q_remove(P1_hand));//zakryta
  555. q_add(table, q_remove(P2_hand));//zakryta
  556.  
  557. cout << "Now they put another card which is visible on the table:" << endl;
  558. Karta_t visible_1 = q_remove(P1_hand);
  559. Karta_t visible_2 = q_remove(P2_hand);
  560. drukujKarte(visible_1); cout << "VS"; drukujKarte(visible_2);
  561. int i = count_cards(table) - 1; // i to ostatni indeks pod którym znajduje się karta w tablicy stołu
  562.  
  563. if (table[i].wartosc < table[i - 1].wartosc) {
  564.  
  565. for (int j = 0; j <= i; ++j) {
  566.  
  567. q_add(P1_hand, table[j]);
  568.  
  569. }
  570. cout << "Player 1 wins the war and takes all these cards! He now has" << count_cards(P1_hand) << "cards" << endl;
  571. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  572. winner = 1;
  573. clear_table(table, i);
  574. return winner;
  575.  
  576. }
  577. else if (table[i].wartosc > table[i - 1].wartosc) {
  578.  
  579. for (int j = 0; j <= i; ++j) {
  580.  
  581. q_add(P2_hand, table[j]);
  582.  
  583. }
  584. cout << "Player 2 wins the war and takes all these cards! He now has" << count_cards(P2_hand) << "cards" << endl;
  585. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  586. winner = 2;
  587. clear_table(table, i);
  588. return winner;
  589.  
  590. }
  591. else if (table[i + 1].wartosc == table[i].wartosc) {
  592. winner = warB(P1_hand, P2_hand, table[i], table[i + 1]);
  593.  
  594. }
  595. }
  596. }
  597. return winner;
  598. }
  599. void playB(Karta_t P1_hand[], Karta_t P2_hand[]) {
  600.  
  601. Karta_t card_1 = q_remove(P1_hand);
  602. Karta_t card_2 = q_remove(P2_hand);
  603.  
  604. drukujKarte(card_1); cout << " VS "; drukujKarte(card_2); cout << endl;
  605.  
  606. if (card_1.wartosc > card_2.wartosc) {
  607. q_add(P1_hand, card_1);
  608. q_add(P1_hand, card_2);
  609. cout << "Player 1 wins this turn and takes both cards! He now has " << count_cards(P1_hand) << "cards " << endl << endl;
  610. cout << "P1 has " << count_cards(P1_hand) << " cards, and P2 has " << count_cards(P2_hand) << " cards " << endl;
  611. }
  612. else if (card_1.wartosc < card_2.wartosc) {
  613. q_add(P2_hand, card_2);
  614. q_add(P2_hand, card_1);
  615. cout << "Player 2 wins this turn and takes both cards! He now has" << count_cards(P2_hand) << "cards" << endl << endl;
  616. cout << "P1 has " << count_cards(P1_hand) << "cards, and P2 has " << count_cards(P2_hand) << "cards" << endl;
  617. }
  618.  
  619. else if (card_1.wartosc == card_2.wartosc) {
  620. warB(P1_hand, P2_hand, card_1, card_2);
  621. cout << endl;
  622. }
  623.  
  624.  
  625. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement