Advertisement
ivan_yosifov

Card_Wars_Better

Dec 4th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.52 KB | None | 0 0
  1.    
  2.  
  3.     using System;
  4.     using System.Numerics;
  5.      
  6.     class Cards
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int N = int.Parse(Console.ReadLine());
  11.             long handStrength1 = 0;
  12.             long handStrength2 = 0;
  13.             BigInteger playerScore1 = 0;
  14.             BigInteger playerScore2 = 0;
  15.             byte wins1 = 0;
  16.             byte wins2 = 0;
  17.             bool winner1 = false, winner2 = false;
  18.      
  19.             for (int turn = 0; turn < N; turn++)
  20.             {
  21.                 handStrength1 = 0; //Set point of current hand to 0, for every new turn
  22.                 handStrength2 = 0; //Same here, for the other player
  23.      
  24.                 string[] firstPlayerCard = new string[3];
  25.                 string[] secondPlayerCard = new string[3];
  26.      
  27.                 for (int card1 = 0; card1 < 3; card1++)
  28.                 {
  29.                     firstPlayerCard[card1] = Console.ReadLine();
  30.      
  31.                     switch (firstPlayerCard[card1]) //check the value of the current card
  32.                     {
  33.                         case "2":
  34.                             handStrength1 += 10;
  35.                             break;
  36.                         case "3":
  37.                             handStrength1 += 9;
  38.                             break;
  39.                         case "4":
  40.                             handStrength1 += 8;
  41.                             break;
  42.                         case "5":
  43.                             handStrength1 += 7;
  44.                             break;
  45.                         case "6":
  46.                             handStrength1 += 6;
  47.                             break;
  48.                         case "7":
  49.                             handStrength1 += 5;
  50.                             break;
  51.                         case "8":
  52.                             handStrength1 += 4;
  53.                             break;
  54.                         case "9":
  55.                             handStrength1 += 3;
  56.                             break;
  57.                         case "10":
  58.                             handStrength1 += 2;
  59.                             break;
  60.                         case "A":
  61.                             handStrength1 += 1;
  62.                             break;
  63.                         case "J":
  64.                             handStrength1 += 11;
  65.                             break;
  66.                         case "Q":
  67.                             handStrength1 += 12;
  68.                             break;
  69.                         case "K":
  70.                             handStrength1 += 13;
  71.                             break;
  72.                         case "Z":
  73.                             playerScore1 *= 2;
  74.                             break;
  75.                         case "Y":
  76.                             playerScore1 -= 200;
  77.                             break;
  78.                         case "X":
  79.                             winner1 = true;
  80.                             break;
  81.                         default:
  82.                             break;
  83.                     }
  84.                 }
  85.      
  86.                 for (int card2 = 0; card2 < 3; card2++)
  87.                 {
  88.                     secondPlayerCard[card2] = Console.ReadLine();
  89.      
  90.                     switch (secondPlayerCard[card2]) //check value of card
  91.                     {
  92.                         case "2":
  93.                             handStrength2 += 10;
  94.                             break;
  95.                         case "3":
  96.                             handStrength2 += 9;
  97.                             break;
  98.                         case "4":
  99.                             handStrength2 += 8;
  100.                             break;
  101.                         case "5":
  102.                             handStrength2 += 7;
  103.                             break;
  104.                         case "6":
  105.                             handStrength2 += 6;
  106.                             break;
  107.                         case "7":
  108.                             handStrength2 += 5;
  109.                             break;
  110.                         case "8":
  111.                             handStrength2 += 4;
  112.                             break;
  113.                         case "9":
  114.                             handStrength2 += 3;
  115.                             break;
  116.                         case "10":
  117.                             handStrength2 += 2;
  118.                             break;
  119.                         case "A":
  120.                             handStrength2 += 1;
  121.                             break;
  122.                         case "J":
  123.                             handStrength2 += 11;
  124.                             break;
  125.                         case "Q":
  126.                             handStrength2 += 12;
  127.                             break;
  128.                         case "K":
  129.                             handStrength2 += 13;
  130.                             break;
  131.                         case "Z":
  132.                             playerScore2 *= 2;
  133.                             break;
  134.                         case "Y":
  135.                             playerScore2 -= 200;
  136.                             break;
  137.                         case "X":
  138.                             winner2 = true;
  139.                             break;
  140.                         default:
  141.                             break;
  142.                     }
  143.                 }
  144.      
  145.                 if (winner1 && winner2) //if both drew X card
  146.                 {
  147.                     playerScore1 += 50;
  148.                     playerScore2 += 50;
  149.                 }
  150.      
  151.                 else if (winner1 && !winner2) //if only one of them => game over => break loop
  152.                 {
  153.                     break;
  154.                 }
  155.      
  156.                 else if (winner2 && !winner1) //same as above for the other player
  157.                 {
  158.                     break;
  159.                 }
  160.      
  161.                 //check which player has a stronger hand and the one with the better wins and adds the points up to the playerScore
  162.      
  163.                 if (handStrength1 > handStrength2)
  164.                 {
  165.                     playerScore1 += handStrength1;
  166.                     wins1++;
  167.                 }
  168.      
  169.                 else if (handStrength2 > handStrength1)
  170.                 {
  171.                     playerScore2 += handStrength2;
  172.                     wins2++;
  173.                 }
  174.      
  175.             }
  176.      
  177.             if (winner1 && !winner2) //X card check
  178.             {
  179.                 Console.WriteLine("X card drawn! Player one wins the match!");
  180.             }
  181.      
  182.             else if (winner2 && !winner1) //X card check
  183.             {
  184.                 Console.WriteLine("X card drawn! Player two wins the match!");
  185.             }
  186.      
  187.             else
  188.             {   //check which player has won it
  189.                 if (playerScore1 > playerScore2)
  190.                 {
  191.                     Console.WriteLine("First player wins!");
  192.                     Console.WriteLine("Score: {0}", playerScore1);
  193.                     Console.WriteLine("Games won: {0}", wins1);
  194.                 }
  195.      
  196.                 else if (playerScore2 > playerScore1)
  197.                 {
  198.                     Console.WriteLine("Second player wins!");
  199.                     Console.WriteLine("Score: {0}", playerScore2);
  200.                     Console.WriteLine("Games won: {0}", wins2);
  201.                 }
  202.      
  203.                 else if ((playerScore1 == playerScore2))
  204.                 {
  205.                     Console.WriteLine("It's a tie!");
  206.                     Console.WriteLine("Score: {0}", playerScore1);
  207.                 }
  208.             }
  209.         }
  210.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement