Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 91 additions & 11 deletions RockPaperScissors/RockPaperScissors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,104 @@

namespace RockPaperScissors
{
class Program
class Program
{
public static int score1 = 0;
public static int score2 = 0; //default values

public String getUserHand(){
String input = Console.ReadLine().ToLower();
if(input != "rock" && input != "scissors" && input != "paper") {
throw new Exception("Bad hand...");
}
return input;
}

public static void Main()

{
Console.WriteLine("Enter hand 1:");
string hand1 = Console.ReadLine().ToLower();
Console.WriteLine("Enter hand 2:");
string hand2 = Console.ReadLine().ToLower();
Console.WriteLine("Hello");
Console.WriteLine("Enter Rock, Paper or Scissors");
//string hand1 = Console.ReadLine().ToLower();
string hand1 = null;
try{
hand1 = getUserHand();
} catch(Exception){
Main();
}


string hand2 = null;
Random rnd = new Random();
int rps = rnd.Next(0,3); //hand2 is played by computer random

//defines hand2 response to hand1 entry
if (rps == 0)
{
hand2 = "rock";
}
else if (rps == 1)
{
hand2 = "paper";
}
else if (rps == 2)
{
hand2 = "scissors";
}



Console.WriteLine(CompareHands(hand1, hand2));
Console.WriteLine("Your Score:" + score1);
Console.WriteLine("Computer Score:" + score2);
Console.WriteLine("Play again Yes or No");
string hand = Console.ReadLine().ToLower();
if (hand=="yes")
{
Main(); //recurssion
}
else
{
Console.Read();
}

// leave this command at the end so your program does not close automatically
Console.ReadLine();
}

public static string CompareHands(string hand1, string hand2)
{
// Your code here
return hand1 + ' ' + hand2;
{
//all possibilities for palys, with win answer
string win = null;
if (hand1 == hand2)
{
Console.WriteLine("Computer played:");
Console.WriteLine(hand2.ToString());
win = "TIE!";
}
else if (hand1 == "paper" && hand2 == "rock" || hand1 == "rock" && hand2 == "scissors" || hand1 == "scissors" && hand2 == "paper")
{
Console.WriteLine("Computer played:");
Console.WriteLine(hand2.ToString());
score1++;
win = "You Win!";
}

else if (hand1 == "rock" && hand2 == "paper" || hand1 == "scissors" && hand2 == "rock" || hand1 == "paper" && hand2 == "scissors")
{
Console.WriteLine("Computer played:");
Console.WriteLine(hand2.ToString());
score2++;
win = "Computer Wins!";
}
else
{
//returns line without computer play
Console.WriteLine("Invalid Selection");
Main();
}

return win;


}
}
}
}