Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CardWars
- {
- class CardWars
- {
- static int gamesOne = 0;
- static int gamesTwo = 0;
- static List<string> playerOneHand = new List<string>();
- static List<string> playerTwoHand = new List<string>();
- static int playerOneCurrentScore = 0;
- static int playerTwoCurrentScore = 0;
- static int playerOneTotalScore = 0;
- static int playerTwoTotalScore = 0;
- static int Points(string card)
- {
- int points = 0;
- switch (card)
- {
- case "2": points = 10; break;
- case "3": points = 9; break;
- case "4": points = 8; break;
- case "5": points = 7; break;
- case "6": points = 6; break;
- case "7": points = 5; break;
- case "8": points = 4; break;
- case "9": points = 3; break;
- case "10": points = 2; break;
- case "A": points = 1; break;
- case "J": points = 11; break;
- case "Q": points = 12; break;
- case "K": points = 13; break;
- case "X": points += 50; break;
- case "Y":
- for (int i = 0; i < 3; i++)
- {
- if (playerOneHand[i] == "Y")
- {
- playerOneCurrentScore -= 200;
- }
- else if (playerOneHand[i] == "Y")
- {
- playerTwoCurrentScore -= 200;
- };
- }
- break;
- case "Z":
- for (int i = 0; i < 3; i++)
- {
- if (playerOneHand[i] == "Z")
- {
- playerOneCurrentScore *= 2;
- }
- else if (playerOneHand[i] == "Z")
- {
- playerTwoCurrentScore *= 2;
- };
- }
- break;
- default: break;
- }
- return points;
- }
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- for (int k = 0; k < n; k++)
- {
- for (int j = 0; j < 3; j++)
- {
- playerOneHand.Add(Console.ReadLine());
- }
- for (int p = 0; p < 3; p++)
- {
- playerTwoHand.Add(Console.ReadLine());
- }
- bool hasPlayerOneX = playerOneHand.Contains("X");
- bool hasPlayerTwoX = playerTwoHand.Contains("X");
- if (hasPlayerOneX && !hasPlayerTwoX)
- {
- Console.Write("X card drawn! ");
- Console.WriteLine("Player one wins the match!");
- return;
- }
- else if (!hasPlayerOneX && hasPlayerTwoX)
- {
- Console.Write("X card drawn! ");
- Console.WriteLine("Player two wins the match!");
- return;
- }
- else if (hasPlayerOneX && hasPlayerTwoX)
- {
- playerOneCurrentScore += 50;
- playerTwoCurrentScore += 50;
- }
- else
- {
- for (int i = 0; i < 3; i++)
- {
- playerOneCurrentScore += Points(playerOneHand[i]);
- playerTwoCurrentScore += Points(playerTwoHand[i]);
- }
- if (playerOneCurrentScore > playerTwoCurrentScore)
- {
- playerOneTotalScore += playerOneCurrentScore;
- gamesOne++;
- }
- else if (playerOneCurrentScore < playerTwoCurrentScore)
- {
- playerTwoTotalScore += playerTwoCurrentScore;
- gamesTwo++;
- }
- else
- {
- playerOneTotalScore += playerOneCurrentScore;
- playerTwoTotalScore += playerOneCurrentScore;
- }
- playerOneCurrentScore = 0;
- playerTwoCurrentScore = 0;
- playerOneHand.Clear();
- playerTwoHand.Clear();
- }
- }
- if ((playerOneTotalScore > playerTwoTotalScore))
- {
- Console.WriteLine("First player wins!");
- Console.WriteLine("Score: {0}", playerOneTotalScore);
- Console.WriteLine("Games won: {0}", gamesOne);
- return;
- }
- else if ((playerOneTotalScore < playerTwoTotalScore))
- {
- Console.WriteLine("Second player wins!");
- Console.WriteLine("Score: {0}", playerTwoTotalScore);
- Console.WriteLine("Games won: {0}", gamesTwo);
- return;
- }
- else if ((playerOneTotalScore == playerTwoTotalScore))
- {
- Console.WriteLine("It's a tie! ");
- Console.WriteLine("Score: 0");
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement