static void Main(string[] args) { //get scoring string Cards = "2 3 4 5 6 7 8 9 10 A J Q K Y Z X"; string Points = "10 9 8 7 6 5 4 3 2 1 11 12 13 -200 2 50"; string[] cardsToDictionary = Cards.Split(' '); string[] pointsToDictionary = Points.Split(' '); Dictionary<string, int> Score = new Dictionary<string, int>(); for (int i = 0; i < cardsToDictionary.Length; i++) { Score.Add(cardsToDictionary[i], Convert.ToInt32(pointsToDictionary[i])); } //Console.WriteLine( Score["2"]); //input int matchLength = int.Parse(Console.ReadLine()); Player Pesho = new Player(); Player Gosho = new Player(); for (int round = 0; round < matchLength; round++) { //reset Pesho.zCounter = 0; Pesho.hasX = false; Pesho.currHand = 0; Gosho.zCounter = 0; Gosho.hasX = false; Gosho.currHand = 0; //Pesho goes 1st for (int i = 0; i < 3; i++) { Pesho.currCard = Console.ReadLine().ToUpper(); if (Pesho.currCard == "X") { Pesho.hasX = true; } else if (Pesho.currCard == "Z") { Pesho.zCounter++; } else if (Pesho.currCard == "Y") { Pesho.score += Score[Pesho.currCard]; } else { Pesho.currHand += Score[Pesho.currCard]; } } //Gosho 2nd for (int i = 0; i < 3; i++) { Gosho.currCard = Console.ReadLine().ToUpper(); if (Gosho.currCard == "X") { Gosho.hasX = true; } else if (Gosho.currCard == "Z") { Gosho.zCounter++; } else if (Gosho.currCard == "Y") { Gosho.score += Score[Gosho.currCard]; } else { Gosho.currHand += Score[Gosho.currCard]; } } //apply zCounter Pesho.score *= (int)Math.Pow(2, Pesho.zCounter); Gosho.score *= (int)Math.Pow(2, Gosho.zCounter); //Determine current round winner ///check for X cards first if (Pesho.hasX && Gosho.hasX) { Pesho.score += Score["X"]; Gosho.score += Score["X"]; } else if (Pesho.hasX && !Gosho.hasX) { Console.WriteLine("X card drawn! Player one wins the match!"); return; } else if (!Pesho.hasX && Gosho.hasX) { Console.WriteLine("X card drawn! Player two wins the match!"); return; } //test if (Pesho.currHand > Gosho.currHand) { Pesho.gamesWon++; Pesho.score += Pesho.currHand; } else if (Pesho.currHand < Gosho.currHand) { Gosho.gamesWon++; Gosho.score += Gosho.currHand; } else if (Pesho.currHand == Gosho.currHand) { //do nothing } } //get winner and print if (Pesho.score > Gosho.score) { Console.WriteLine("First player wins!\nScore: {0}\nGames won: {1}", Pesho.score, Pesho.gamesWon); } else if (Pesho.score < Gosho.score) { Console.WriteLine("Second player wins!\nScore: {0}\nGames won: {1}", Gosho.score, Gosho.gamesWon); } else if (Pesho.score == Gosho.score) { Console.WriteLine("It's a tie!\nScore: {0}", Pesho.score); } }
public static void Main(string[] args) { int numberOfAllGames = int.Parse(Console.ReadLine()); const int CardsToPlayer = 3; Player playerOne = new Player(); Player playerTwo = new Player(); for (int i = 0; i < numberOfAllGames; i++) { playerOne.LocalScore = 0; playerTwo.LocalScore = 0; for (int j = 0; j < CardsToPlayer; j++) { string currentCard = Console.ReadLine(); playerOne.ProccessCard(currentCard); } for (int j = 0; j < CardsToPlayer; j++) { string currentCard = Console.ReadLine(); playerTwo.ProccessCard(currentCard); } if (playerOne.XCardDrawn && playerTwo.XCardDrawn) { playerTwo.GlobalScore += 50; playerOne.GlobalScore += 50; playerOne.XCardDrawn = false; playerTwo.XCardDrawn = false; } else if (playerOne.XCardDrawn) { break; } else if (playerTwo.XCardDrawn) { break; } if (playerOne.LocalScore > playerTwo.LocalScore) { playerOne.GlobalScore += playerOne.LocalScore; playerOne.GamesWon++; } else if (playerOne.LocalScore < playerTwo.LocalScore) { playerTwo.GlobalScore += playerTwo.LocalScore; playerTwo.GamesWon++; } } if (playerOne.XCardDrawn) { Console.WriteLine("X card drawn! Player one wins the match!"); } else if (playerTwo.XCardDrawn) { Console.WriteLine("X card drawn! Player two wins the match!"); } else if (playerOne.GlobalScore > playerTwo.GlobalScore) { Console.WriteLine("First player wins!"); Console.WriteLine("Score: {0}", playerOne.GlobalScore); Console.WriteLine("Games won: {0}", playerOne.GamesWon); } else if (playerOne.GlobalScore < playerTwo.GlobalScore) { Console.WriteLine("Second player wins!"); Console.WriteLine("Score: {0}", playerTwo.GlobalScore); Console.WriteLine("Games won: {0}", playerTwo.GamesWon); } else { Console.WriteLine("It's a tie!"); Console.WriteLine("Score: {0}", playerOne.GlobalScore); } }