-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathProgram.cs
50 lines (48 loc) · 1.25 KB
/
Program.cs
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
using System;
using static Move;
int wins = 0;
int draws = 0;
int losses = 0;
while (true)
{
Console.Clear();
Console.WriteLine("Rock, Paper, Scissors");
Console.WriteLine();
GetInput:
Console.Write("Choose [r]ock, [p]aper, [s]cissors, or [e]xit:");
Move playerMove;
switch ((Console.ReadLine() ?? "").Trim().ToLower())
{
case "r" or "rock": playerMove = Rock; break;
case "p" or "paper": playerMove = Paper; break;
case "s" or "scissors": playerMove = Scissors; break;
case "e" or "exit": Console.Clear(); return;
default: Console.WriteLine("Invalid Input. Try Again..."); goto GetInput;
}
Move computerMove = (Move)Random.Shared.Next(3);
Console.WriteLine($"The computer chose {computerMove}.");
switch (playerMove, computerMove)
{
case (Rock, Paper) or (Paper, Scissors) or (Scissors, Rock):
Console.WriteLine("You lose.");
losses++;
break;
case (Rock, Scissors) or (Paper, Rock) or (Scissors, Paper):
Console.WriteLine("You win.");
wins++;
break;
default:
Console.WriteLine("This game was a draw.");
draws++;
break;
}
Console.WriteLine($"Score: {wins} wins, {losses} losses, {draws} draws");
Console.WriteLine("Press Enter To Continue...");
Console.ReadLine();
}
enum Move
{
Rock = 0,
Paper = 1,
Scissors = 2,
}