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(); while (PlayAgain()) { GameStats.rounds++; Console.WriteLine("Round " + GameStats.rounds); GameStats.score += PlayRound(); Console.WriteLine("\n\nPlay again? Y| N: "); } GameStats.ToConsole(); GameStats.ExtendedToConsole(); 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) { switch (PlayYesNo) { case "Y": { Console.WriteLine("\nPug: \"OK Let's play! Boof!\"\n\n"); inputIsValid = true; playAgain = true; break; } case "N": { Console.WriteLine("\nPug: \"No? I go sleep sleep.\""); inputIsValid = true; playAgain = false; break; } default: { Console.WriteLine("\n\nPug: *Head tilt*\n\n \"Got a treat?\""); Console.Write("\n\n\nPlay? Y|N: "); PlayYesNo = TakeInput(); break; } } } 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 //Update game stats switch (player1) { case "D": GameStats.domes++; break; case "W": GameStats.wrinkles++; break; case "C": GameStats.curls++; break; } if (player1.Equals(pug)) //tie game { Console.WriteLine("\nTIE!"); GameStats.ties++; return "tie"; } else if ((player1.Equals("D") && pug.Equals("C")) || (player1.Equals("C") && pug.Equals("W"))) //player wins { switch (player1) { case "D": Console.WriteLine("Dome straightens curl."); break; case "W": Console.WriteLine("Wrinkles cover dome."); break; case "C": Console.WriteLine("Curl wags away wrinkles."); break; } Console.WriteLine("\nYou win!"); GameStats.wins++; return "win"; } else //computer wins { Console.WriteLine("\nPug: \"Pug wins again!\""); GameStats.losses++; 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!\"\n"); 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); switch (result) { case "win": { roundscore = 1; break; } case "lose": { roundscore = -1; break; } case "tie": { roundscore = 0; break; } } validMove = true; } else { Console.Write("\n\nRau! You have to enter a D, W, or C. Try again: "); playerMove = TakeInput(); } } return roundscore; } private static class GameStats { public static int score; // current score public static int highscore; // all-time high score public static int wins; // wins tally public static int losses; // losses tally public static int ties; // rounds tally public static int rounds; // number of rounds played public static int domes; // number of Dome moves played public static int wrinkles; // number of Wrinkles moves played public static int curls; // number of Curls moves played public static void ToConsole() { Console.WriteLine("\nGame Stats:\n"); Console.WriteLine("Rounds played: " + rounds); Console.WriteLine("Score :" + score); Console.WriteLine("Wins: " + wins); Console.WriteLine("Losses: " + losses); Console.WriteLine("Ties: " + ties); } public static void ExtendedToConsole() { Console.WriteLine("You played Dome " + domes + " times"); Console.WriteLine("You played Wrinkles " + wrinkles + " times"); Console.WriteLine("You played Curl " + curls + " times"); } } } }