-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathRockPaperScissors.cs
More file actions
105 lines (95 loc) · 3.5 KB
/
RockPaperScissors.cs
File metadata and controls
105 lines (95 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Threading;
namespace RockPaperScissors
{
class Program
{
public static void Main()
{
Console.Clear(); // Clears the console prior to game start
Console.WriteLine("Welcome to Rock | Paper | Scissors!");
Console.WriteLine("When prompted, type either 'Rock', 'Paper', or 'Scissors' without single quotes.");
Thread.Sleep(1000);
Console.WriteLine("Type 'Quit' without single quotes to stop playing");
Console.WriteLine("Enter hand 1: ");
string hand1 = Console.ReadLine();
Console.Clear();
// If the user enters the word quit, terminates the program and clears the console
while (hand1.ToUpper() != "QUIT")
{
// Random number generator for computer turn that is then assigned
Random randNum = new Random();
string hand2 = Convert.ToString(randNum.Next(1, 4));
// Calls the method that checks who the winner is
CompareHands(hand1, hand2);
Thread.Sleep(500);
Console.WriteLine("Type either 'Rock', 'Paper', or 'Scissors' without single quotes to play again!");
Console.WriteLine("Type 'Quit' without single quotes to stop playing");
hand1 = Console.ReadLine();
Console.Clear();
}
Console.Clear();
}
public static string CompareHands(string hand1, string hand2)
{
// Your code here
if (hand2 == "1")
{
hand2 = "Rock";
}
else if (hand2 == "2")
{
hand2 = "Paper";
}
else
{
hand2 = "Scissors";
}
if (hand1.ToUpper() == hand2.ToUpper())
{
Console.WriteLine(hand1 + ' ' + hand2);
Console.WriteLine("It's a tie!");
}
else if (hand1.ToUpper() == "ROCK")
{
if (hand2.ToUpper() == "PAPER")
{
Console.WriteLine(hand1 + ' ' + hand2);
Console.WriteLine("Computer wins!");
}
else if (hand2.ToUpper() == "SCISSORS")
{
Console.WriteLine(hand1 + ' ' + hand2);
Console.WriteLine("Player wins!");
}
}
else if (hand1.ToUpper() == "PAPER")
{
if (hand2.ToUpper() == "ROCK")
{
Console.WriteLine(hand1 + ' ' + hand2);
Console.WriteLine("Player wins!");
}
else if (hand2.ToUpper() == "SCISSORS")
{
Console.WriteLine(hand1 + ' ' + hand2);
Console.WriteLine("Computer wins!");
}
}
else if (hand1.ToUpper() == "SCISSORS")
{
if (hand2.ToUpper() == "ROCK")
{
Console.WriteLine(hand1 + ' ' + hand2);
Console.WriteLine("Computer wins!");
}
else if (hand2.ToUpper() == "PAPER")
{
Console.WriteLine(hand1 + ' ' + hand2);
Console.WriteLine("Player wins!");
}
}
return hand1 + ' ' + hand2;
}
}
}