From 295dc08be39b80cb837a3c7ec1732e45accf0a9e Mon Sep 17 00:00:00 2001 From: Michael Rich Date: Sun, 14 Oct 2018 17:19:53 -0500 Subject: [PATCH 1/2] created Rock Paper Scissors game --- RockPaperScissors/RockPaperScissors.cs | 57 +++++++++++++++++++++----- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 470ae756..19b22b9e 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -6,20 +6,57 @@ class Program { public static void Main() { - Console.WriteLine("Enter hand 1:"); + //user input + Console.WriteLine("Enter your move:"); string hand1 = Console.ReadLine().ToLower(); - Console.WriteLine("Enter hand 2:"); - string hand2 = Console.ReadLine().ToLower(); - Console.WriteLine(CompareHands(hand1, hand2)); - // leave this command at the end so your program does not close automatically + //random computer input + string hand2; + Random rnd = new Random(); + int computerMove = rnd.Next(1,3); + + if (computerMove == 1){ + hand2 = "rock"; + } + else if (computerMove == 2){ + hand2 = "paper"; + } + else{ + hand2 = "scissors"; + } + Console.WriteLine("Computer chose " + hand2); + + //logic to decide outcome + int wincon = CompareHands(hand1,hand2); + + if(wincon == 0){ + Console.WriteLine("it's a Tie!"); + } + else if(wincon == 1){ + Console.WriteLine("You Win!"); + } + else{ + Console.WriteLine("You Lose!"); + } + + //prevents program from closing Console.ReadLine(); } - - public static string CompareHands(string hand1, string hand2) + + private static int CompareHands(string hand1, string hand2) { - // Your code here - return hand1 + ' ' + hand2; - } + //Tie condition + if(hand1 == hand2){ + return 0; + } + //Win Condition + else if ((hand1 == "rock" && hand2 == "scissors")||(hand1 == "paper" && hand2 == "rock")||(hand1 == "scissors" && hand2 == "paper")){ + return 1; + } + //Loss Condition + else{ + return 2; + } + } } } From 49b079d47871052403672b0ee427e6a59b4c4fb8 Mon Sep 17 00:00:00 2001 From: Michael Rich Date: Wed, 17 Oct 2018 21:48:51 -0500 Subject: [PATCH 2/2] fixed bug where computer wouldn't chose scissors --- RockPaperScissors/RockPaperScissors.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 19b22b9e..d7907ac7 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -13,7 +13,7 @@ public static void Main() //random computer input string hand2; Random rnd = new Random(); - int computerMove = rnd.Next(1,3); + int computerMove = rnd.Next(1,4); if (computerMove == 1){ hand2 = "rock";