Advertisement
Absend

CardWards

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