Advertisement
archangelmihail

CardWars

Nov 27th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. namespace CardWars
  9. {
  10.     class CardWars
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             //using string and integer arrays
  15.             int allGames = int.Parse(Console.ReadLine());
  16.             const int cardsPerGame = 3;
  17.             int[] points = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13 };
  18.             string[] cards = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "A", "J", "Q", "K" };
  19.             BigInteger totalFirst = 0;
  20.             BigInteger totalSecond = 0;
  21.             bool firstX = false;
  22.             bool secondX = false;
  23.             int wonFirst = 0;
  24.             int wonSecond = 0;
  25.             bool gameWon = false;
  26.             for (int k = 0; k < allGames; k++)
  27.             {
  28.                 int scoreFirst = 0;
  29.                 int scoreSecond = 0;
  30.                 string[] firstPlayer = { "0", "0", "0" };
  31.                 string[] secondPlayer = { "0", "0", "0" };
  32.                 for (int i = 0; i < cardsPerGame; i++)
  33.                 {
  34.                     firstPlayer[i] = Console.ReadLine();
  35.                     if (firstPlayer[i] == "X")
  36.                     {
  37.                         firstX = true;
  38.                     }
  39.                     if (firstPlayer[i] == "Y")
  40.                     {
  41.                         totalFirst -= 200;
  42.                     }
  43.                     if (firstPlayer[i] == "Z")
  44.                     {
  45.                         totalFirst *= 2;
  46.                     }
  47.                 }
  48.  
  49.                 for (int i = 0; i < cardsPerGame; i++)
  50.                 {
  51.                     secondPlayer[i] = Console.ReadLine();
  52.                     if (secondPlayer[i] == "X")
  53.                     {
  54.                         secondX = true;
  55.                     }
  56.                     if (secondPlayer[i] == "Y")
  57.                     {
  58.                         totalSecond -= 200;
  59.                     }
  60.                     if (secondPlayer[i] == "Z")
  61.                     {
  62.                         totalSecond *= 2;
  63.                     }
  64.                 }
  65.                 for (int i = 0; i < 13; i++)
  66.                 {
  67.                     for (int j = 0; j < cardsPerGame; j++)
  68.                     {
  69.                         if (firstPlayer[j] == cards[i])
  70.                         {
  71.                             scoreFirst += points[i];
  72.                         }
  73.                         if (secondPlayer[j] == cards[i])
  74.                         {
  75.                             scoreSecond += points[i];
  76.                         }
  77.                     }
  78.  
  79.                 }
  80.  
  81.                 if (firstX && secondX)
  82.                 {
  83.                     totalFirst += 50;
  84.                     totalSecond += 50;
  85.                     firstX = false;
  86.                     secondX = false;
  87.                 }
  88.                 if (scoreFirst > scoreSecond)
  89.                 {
  90.                     totalFirst += scoreFirst;
  91.                     wonFirst++;
  92.                 }
  93.                 else if (scoreSecond > scoreFirst)
  94.                 {
  95.                     totalSecond += scoreSecond;
  96.                     wonSecond++;
  97.                 }
  98.             }
  99.             if (firstX && !secondX)
  100.             {
  101.                 Console.WriteLine("X card drawn! Player one wins the match!");
  102.                 gameWon = true;
  103.             }
  104.             else if (!firstX && secondX)
  105.             {
  106.                 Console.WriteLine("X card drawn! Player two wins the match!");
  107.                 gameWon = true;
  108.             }
  109.             if ((totalFirst > totalSecond) && !gameWon)
  110.             {
  111.                 Console.WriteLine("First player wins!");
  112.                 Console.WriteLine("Score: {0}", totalFirst);
  113.                 Console.WriteLine("Games won: {0}", wonFirst);
  114.             }
  115.             else if ((totalFirst < totalSecond) && !gameWon)
  116.             {
  117.                 Console.WriteLine("Second player wins!");
  118.                 Console.WriteLine("Score: {0}", totalSecond);
  119.                 Console.WriteLine("Games won: {0}", wonSecond);
  120.             }
  121.             else if ((totalFirst == totalSecond) && !gameWon)
  122.             {
  123.                 Console.WriteLine("It's a tie!");
  124.                 Console.WriteLine("Score: {0}", totalFirst);
  125.             }
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement