Advertisement
Guest User

chuj chuj

a guest
Dec 6th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.40 KB | None | 0 0
  1. int warB(my_deck* player1, my_deck* player2, my_deck* player1_war_stack, my_deck* player2_war_stack, int deck_size) {
  2.     int player1_lenght = getDeckLenght(player1);
  3.     int player2_lenght = getDeckLenght(player2);
  4.     int player1_war_stack_card_power = deck_size/4;
  5.     int player2_war_stack_card_power = deck_size/4;
  6.  
  7.     if (player1_lenght >= 3 && player2_lenght >= 3) {
  8.         for (int i = 0; i < 2; ++i) {
  9.             addToEnd(player1_war_stack, popFirst(player1));
  10.             addToEnd(player2_war_stack, popFirst(player2));
  11.         }
  12.         player1_war_stack_card_power = getCardPower(player1->next->card, deck_size);
  13.         player2_war_stack_card_power = getCardPower(player2->next->card, deck_size);
  14.         addToEnd(player1_war_stack, popFirst(player1));
  15.         addToEnd(player2_war_stack, popFirst(player2));
  16.     }
  17.     else if (player1_lenght == 2) {
  18.         if (player2_lenght >= 4) {
  19.             #ifdef DISPLAYGAME
  20.             cout << "Player 2 lends 1 card to Player 1." << endl;
  21.             _getch();
  22.             #endif // DISPLAYGAME
  23.             addToEnd(player1_war_stack, popFirst(player2));
  24.             addToEnd(player1_war_stack, popFirst(player1));
  25.             player1_war_stack_card_power = getCardPower(player1->next->card, deck_size);
  26.             addToEnd(player1_war_stack, popFirst(player1));
  27.             addToEnd(player2_war_stack, popFirst(player2));
  28.             addToEnd(player2_war_stack, popFirst(player2));
  29.             player2_war_stack_card_power = getCardPower(player2->next->card, deck_size);
  30.             addToEnd(player2_war_stack, popFirst(player2));
  31.         }
  32.         else {
  33.             #ifdef DISPLAYGAME
  34.             cout << "Player 2 ran out of cards! Player 1 wins." << endl;
  35.             _getch();  
  36.             #endif // DISPLAYGAME
  37.             return 1;
  38.         }
  39.     }
  40.     else if (player1_lenght == 1) {
  41.         if (player2_lenght >= 5) {
  42.             #ifdef DISPLAYGAME
  43.             cout << "Player 2 lends 2 cards to Player 1." << endl;
  44.             _getch();
  45.             #endif // DISPLAYGAME
  46.             addToEnd(player1_war_stack, popFirst(player2));
  47.             addToEnd(player1_war_stack, popFirst(player2));
  48.             player1_war_stack_card_power = getCardPower(player1->next->card, deck_size);
  49.             addToEnd(player1_war_stack, popFirst(player1));
  50.             addToEnd(player2_war_stack, popFirst(player2));
  51.             addToEnd(player2_war_stack, popFirst(player2));
  52.             player2_war_stack_card_power = getCardPower(player2->next->card, deck_size);
  53.             addToEnd(player2_war_stack, popFirst(player2));
  54.         }
  55.         else {
  56.             #ifdef DISPLAYGAME
  57.             cout << "Player 2 ran out of cards! Player 1 wins." << endl;
  58.             _getch();
  59.             #endif // DISPLAYGAME
  60.             return 1;
  61.         }
  62.     }
  63.     else if (player1_lenght == 0) {
  64.         #ifdef DISPLAYGAME
  65.         cout << "Player 1 ran out of cards! Player 2 wins." << endl;
  66.         _getch();
  67.         #endif // DISPLAYGAME
  68.         return 2;
  69.     }
  70.     else if (player2_lenght == 2) {
  71.         if (player1_lenght >= 4) {
  72.             #ifdef DISPLAYGAME
  73.             cout << "Player 1 lends 1 card to Player 2." << endl;
  74.             _getch();
  75.             #endif // DISPLAYGAME
  76.             addToEnd(player2_war_stack, popFirst(player1));
  77.             addToEnd(player2_war_stack, popFirst(player2));
  78.             player2_war_stack_card_power = getCardPower(player2->next->card, deck_size);
  79.             addToEnd(player2_war_stack, popFirst(player2));
  80.             addToEnd(player1_war_stack, popFirst(player1));
  81.             addToEnd(player1_war_stack, popFirst(player1));
  82.             player1_war_stack_card_power = getCardPower(player1->next->card, deck_size);
  83.             addToEnd(player1_war_stack, popFirst(player1));
  84.         }
  85.         else {
  86.             #ifdef DISPLAYGAME
  87.             cout << "Player 1 ran out of cards! Player 2 wins." << endl;
  88.             _getch();
  89.             #endif // DISPLAYGAME
  90.             return 2;
  91.         }
  92.     }
  93.     else if (player2_lenght == 1) {
  94.         if (player1_lenght >= 5) {
  95.             #ifdef DISPLAYGAME
  96.             cout << "Player 1 lends 2 cards to Player 2." << endl;
  97.             _getch();
  98.             #endif // DISPLAYGAME
  99.             addToEnd(player2_war_stack, popFirst(player1));
  100.             addToEnd(player2_war_stack, popFirst(player1));
  101.             player2_war_stack_card_power = getCardPower(player2->next->card, deck_size);
  102.             addToEnd(player2_war_stack, popFirst(player2));
  103.             addToEnd(player1_war_stack, popFirst(player1));
  104.             addToEnd(player1_war_stack, popFirst(player1));
  105.             player1_war_stack_card_power = getCardPower(player1->next->card, deck_size);
  106.             addToEnd(player1_war_stack, popFirst(player1));
  107.         }
  108.         else {
  109.             #ifdef DISPLAYGAME
  110.             cout << "Player 1 ran out of cards! Player 2 wins." << endl;
  111.             _getch();
  112.             #endif // DISPLAYGAME
  113.             return 2;
  114.         }
  115.     }
  116.     else if (player2_lenght == 0) {
  117.         #ifdef DISPLAYGAME
  118.         cout << "Player 2 ran out of cards! Player 1 wins." << endl;
  119.         _getch();
  120.         #endif // DISPLAYGAME
  121.         return 1;
  122.     }
  123.  
  124.     if (player1_war_stack_card_power == player2_war_stack_card_power) {
  125.         #ifdef DISPLAYGAME
  126.         cout << "The War continues!" << endl;
  127.         _getch();
  128.         #endif // DISPLAYGAME
  129.         return warB(player1, player2, player1_war_stack, player2_war_stack, deck_size);
  130.     }
  131.     else if (player1_war_stack_card_power < player2_war_stack_card_power) { //p1 wins war
  132.         #ifdef DISPLAYGAME
  133.         cout << "Player 1 won the War!" << endl;
  134.         _getch();
  135.         #endif // DISPLAYGAME
  136.         while (player1_war_stack->next != NULL) {
  137.             addToEnd(player1, popFirst(player1_war_stack));
  138.         }
  139.         while (player2_war_stack->next != NULL) {
  140.             addToEnd(player1, popFirst(player2_war_stack));
  141.         }
  142.         return 0;
  143.     }
  144.     else if (player1_war_stack_card_power > player2_war_stack_card_power) { //p2 wins war
  145.         #ifdef DISPLAYGAME
  146.         cout << "Player 2 won the War!" << endl;
  147.         _getch();
  148.         #endif // DISPLAYGAME
  149.         while (player2_war_stack->next != NULL) {
  150.             addToEnd(player2, popFirst(player2_war_stack));
  151.         }
  152.         while (player1_war_stack->next != NULL) {
  153.             addToEnd(player2, popFirst(player1_war_stack));
  154.         }
  155.         return 0;
  156.     }
  157.     return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement