using System; using System.Collections.Generic; using System.Text; namespace DomeWrinklesCurlc // A pug-themed version of rock|paper|scissors { class Program { static void Main(string[] args) { Greeting(); //TODO: implement a static gamestats object with these variables as properties int result = 0; // Result of this round. 1 = win 0 = tie -1 = lose int score = 0; // Score = wins - losses int wins = 0; //Number of times the player has won a round int rounds = 0; // Number of rounds played while (PlayAgain()) { rounds++; Console.WriteLine("Round " + rounds); result = PlayRound(); score = score + result; //Console.WriteLine("score so far: " + score); if (result == 1) { wins = wins + 1; } //Console.WriteLine("Wins so far: " + wins); Console.WriteLine("\n\nPlay again? Y| N: "); } Console.WriteLine("\n\n\nYou played " + rounds + " games."); Console.WriteLine("Your score: " + score + "."); Console.WriteLine("You won " + wins + " games."); Console.WriteLine("\n\n\nI like pugs."); Console.WriteLine("\n\nPress Enter to quit."); Console.ReadLine(); } private static string SanitizeInput(string s) { //returns the first character of the input string, in upper case if (s.Length > 0) //rewrite to use proper exception handling; throws exception if empty string. { s = s.ToUpper().Substring(0, 1); } else { s = " "; } return s; } private static void Greeting() { //Greet player Console.WriteLine("A cute little puggy appears!\n\n"); Console.WriteLine("Pug: \"I am Pug!\"\n *wag* *wag*\n *pant* *pant*\n \"Want to play Dome Wrinkles Curl?\"\n"); Console.Write("Play? Y|N: "); } private static string TakeInput() { string input = Console.ReadLine(); input = SanitizeInput(input); return input; } private static string ComputerMove() //Generates a random move for the AI to play { Random r = new Random(); int n = (r.Next() % 3); //plays a Dome move for the AI string move = ""; Console.WriteLine(""); if (n == 0) { Console.WriteLine("Pug: \"Dome!\""); move = "D"; } //plays a Wrinkle move for the AI if (n == 1) { Console.WriteLine("Pug: \"Rub my wrinkles!\""); move = "W"; } //plays a Curl move for the AI if (n == 2) { Console.WriteLine("Pug: \"Whirl my curl!\""); move = "C"; } return move; } private static bool PlayAgain() { bool inputIsValid = false; bool playAgain = false; string PlayYesNo = TakeInput(); while (inputIsValid == false) { if (PlayYesNo.Equals("Y")) { Console.WriteLine("\nPug: \"OK Let's play! Boof!\"\n\n"); inputIsValid = true; playAgain = true; } else if (PlayYesNo.Equals("N")) { Console.WriteLine("\nPug: \"No? I go sleep sleep.\""); inputIsValid = true; playAgain = false; } else { Console.WriteLine("\n\nPug: *Head tilt*\n\n \"Got a treat?\""); Console.Write("\n\n\nPlay? Y|N: "); PlayYesNo = TakeInput(); } } return playAgain; } private static string DetermineWinner(string player1, string pug) { //Rules: //Game plays like rock|paper|scissors // //Wrinkles covers Dome //Dome straightens Curl //Curl smooths out Wrinkles if (player1.Equals(pug)) //tie game { Console.WriteLine("\nTIE!"); return "tie"; } else if ((player1.Equals("D") && pug.Equals("C")) || (player1.Equals("C") && pug.Equals("W"))) //player wins { if (player1.Equals("D")) { Console.WriteLine("Dome straightens curl.");} if (player1.Equals("W")) { Console.WriteLine("Wrinkles cover dome."); } if (player1.Equals("C")) { Console.WriteLine("Curl wags away wrinkles."); } Console.WriteLine("\nYou win!"); return "win"; } else //computer wins { Console.WriteLine("\nPug: \"Pug wins again!\""); return "lose"; } } private static int PlayRound() //returns score for ongoing tally after each round { int roundscore = 0; Console.WriteLine("\n\nPug: \"OK, u play ur move. Rau!\""); Console.Write("(D)ome|(W)rinkles|(C)url: "); string playerMove = TakeInput(); //validate your move bool validMove = false; while (validMove == false) { if (playerMove.Equals("D") || playerMove.Equals("W") || playerMove.Equals("C")) { //calculate winner string pugMove = ComputerMove(); string result = DetermineWinner(playerMove, pugMove); if (result == "win") { roundscore = 1; } if (result == "lose") { roundscore = -1; } if (result == "tie") { roundscore = 0; } validMove = true; } else { Console.Write("\n\nRau! You have to enter a D, W, or C. Try again: "); playerMove = TakeInput(); } } return roundscore; } } }