Advertisement
ivan_yosifov

Card_Wars_Fixed

Nov 16th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.82 KB | None | 0 0
  1.  
  2.  
  3. using System;
  4. using System.Numerics;
  5.  
  6. class CardWarsBatka
  7. {
  8.     static void Main()
  9.     {
  10.         BigInteger playerOneFinalScore = 0;
  11.         BigInteger playerTwoFinalScore = 0;
  12.         int playerOneGameScore = 0;
  13.         int playerTwoGameScore = 0;
  14.         int playerOneGamesWin = 0;
  15.         int playerTwoGamseWin = 0;
  16.         string currentCard;
  17.         int intCard;
  18.         bool playerOneXCardDrawn = false;
  19.         bool playerTwoXCardDrawn = false;
  20.  
  21.         int numberOfGames = int.Parse(Console.ReadLine());
  22.  
  23.         for (int i = 1; i <= numberOfGames; i++)
  24.         {
  25.             for (int j = 0; j < 3; j++)
  26.             {
  27.                 currentCard = Console.ReadLine();
  28.                 switch (currentCard)
  29.                 {
  30.                     case "A":
  31.                         playerOneGameScore += 1;
  32.                         break;
  33.                     case "J":
  34.                         playerOneGameScore += 11;
  35.                         break;
  36.                     case "Q":
  37.                         playerOneGameScore += 12;
  38.                         break;
  39.                     case "K":
  40.                         playerOneGameScore += 13;
  41.                         break;
  42.                     case "Z":
  43.                         playerOneFinalScore *= 2;
  44.                         break;
  45.                     case "Y":
  46.                         playerOneFinalScore -= 200;
  47.                         break;
  48.                     case "X":
  49.                         playerOneXCardDrawn = true;
  50.                         break;
  51.                     default:
  52.                         intCard = int.Parse(currentCard);
  53.                         playerOneGameScore += (12 - intCard);
  54.                         break;
  55.                 }
  56.             }
  57.  
  58.             for (int k = 0; k < 3; k++)
  59.             {
  60.                 currentCard = Console.ReadLine();
  61.                 switch (currentCard)
  62.                 {
  63.                     case "A":
  64.                         playerTwoGameScore += 1;
  65.                         break;
  66.                     case "J":
  67.                         playerTwoGameScore += 11;
  68.                         break;
  69.                     case "Q":
  70.                         playerTwoGameScore += 12;
  71.                         break;
  72.                     case "K":
  73.                         playerTwoGameScore += 13;
  74.                         break;
  75.                     case "Z":
  76.                         playerTwoFinalScore *= 2;
  77.                         break;
  78.                     case "Y":
  79.                         playerTwoFinalScore -= 200;
  80.                         break;
  81.                     case "X":
  82.                         playerTwoXCardDrawn = true;
  83.                         break;
  84.                     default:
  85.                         intCard = int.Parse(currentCard);
  86.                         playerTwoGameScore += (12 - intCard);
  87.                         break;
  88.                 }
  89.             }
  90.  
  91.             if (playerOneXCardDrawn && !playerTwoXCardDrawn)
  92.             {
  93.                 Console.WriteLine("X card drawn! Player one wins the match!");
  94.                 return;
  95.             }
  96.             if (!playerOneXCardDrawn && playerTwoXCardDrawn)
  97.             {
  98.                 Console.WriteLine("X card drawn! Player two wins the match!");
  99.                 return;
  100.             }
  101.  
  102.            
  103.  
  104.             if (playerOneGameScore > playerTwoGameScore)
  105.             {
  106.                 playerOneFinalScore += playerOneGameScore;
  107.                 playerOneGamesWin++;
  108.             }
  109.  
  110.             if (playerTwoGameScore > playerOneGameScore)
  111.             {
  112.                 playerTwoFinalScore += playerTwoGameScore;
  113.                 playerTwoGamseWin++;
  114.             }
  115.  
  116.             playerOneGameScore = 0;
  117.             playerTwoGameScore = 0;
  118.  
  119.             if (playerOneXCardDrawn && playerTwoXCardDrawn)
  120.             {
  121.                 playerOneFinalScore += 50;
  122.                 playerTwoFinalScore += 50;
  123.                 playerOneGameScore = 0;
  124.                 playerTwoGameScore = 0;
  125.                 playerOneXCardDrawn = false;
  126.                 playerTwoXCardDrawn = false;
  127.                 continue;
  128.             }
  129.         }
  130.  
  131.         if (playerOneFinalScore > playerTwoFinalScore)
  132.         {
  133.             Console.WriteLine("First player wins!");
  134.             Console.WriteLine("Score: {0}", playerOneFinalScore);
  135.             Console.WriteLine("Games won: {0}", playerOneGamesWin);
  136.         }
  137.         else if (playerTwoFinalScore > playerOneFinalScore)
  138.         {
  139.             Console.WriteLine("Second player wins!");
  140.             Console.WriteLine("Score: {0}", playerTwoFinalScore);
  141.             Console.WriteLine("Games won: {0}", playerTwoGamseWin);
  142.  
  143.         }
  144.         else
  145.         {
  146.             Console.WriteLine("It's a tie!");
  147.             Console.WriteLine("Score: {0}", playerTwoFinalScore);
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement