Advertisement
Guest User

Implementation papi

a guest
Jun 28th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CS_Fundamentals
  4. {
  5.  
  6.     enum HeadsOrTails
  7.     {
  8.         Heads,
  9.         Tails
  10.     }
  11.     class Program
  12.     {
  13.         static void Main()
  14.         {
  15.             HeadsOrTails playerFlip;
  16.             bool valid;
  17.             bool playAgain;
  18.  
  19.             HeadsOrTails coinFlip;
  20.             HeadsOrTails computerFlip;
  21.  
  22.             do
  23.             {
  24.                 Random randomValue = new Random();
  25.  
  26.                 coinFlip = (HeadsOrTails)randomValue.Next(Enum.GetNames(typeof(HeadsOrTails)).Length);
  27.                 computerFlip = = (HeadsOrTails)randomValue.Next(Enum.GetNames(typeof(HeadsOrTails)).Length);
  28.  
  29.                 Console.WriteLine("------------------------------------------------------------------");
  30.                 do
  31.                 {
  32.                     Console.Write("Pick Heads or Tails: ");
  33.                     valid = Enum.TryParse<HeadsOrTails>(Console.ReadLine(), true, out playerFlip);
  34.                 } while (!valid);
  35.  
  36.                 Console.WriteLine("The coin landed on {0}\n", coinFlip);
  37.                 Console.WriteLine("You picked: {0}", playerFlip);
  38.                 Console.WriteLine("Computer picked: {0}\n", computerFlip);
  39.  
  40.                 if (playerFlip != coinFlip && computerFlip != coinFlip)
  41.                 {
  42.                     Console.WriteLine("You both lose");
  43.                 }
  44.                 else if (playerFlip == coinFlip && computerFlip == coinFlip)
  45.                 {
  46.                     Console.WriteLine("It's a tie");
  47.                 }
  48.                 else if (playerFlip == coinFlip && computerFlip != coinFlip)
  49.                 {
  50.                     Console.WriteLine("You won");
  51.                 }
  52.                 else
  53.                 {
  54.                     Console.WriteLine("You lost");
  55.                 }
  56.  
  57.                 Console.Write("press 'y' to play again ");
  58.                 playAgain = (Console.ReadLine() == "y") ? playAgain = true : playAgain = false;
  59.             }
  60.             while (playAgain);
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement