-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
114 lines (94 loc) · 3.21 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
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
106
107
108
109
110
111
112
113
114
using System;
namespace Rock_Paper_Scissors
{
class Program
{
static void Main(string[] args)
{
string tryAgain = "Would you like to try again? (y/n)";
RoshamboApp app = new RoshamboApp();
bool resume = false;
do
{
try
{
ShowMainMenu();
int input = int.Parse(GetUserInput(""));
if (input == 1)
{
app.SetUserName();
int opponentChoice = AskWhichOpponentToFight();
if (opponentChoice == 1)
{
app.DumbGame();
resume = AskToTryAgain(GetUserInput(tryAgain));
}
else if (opponentChoice == 2)
{
app.Game();
resume = AskToTryAgain(GetUserInput(tryAgain));
}
else if (AskWhichOpponentToFight() != 1 && AskWhichOpponentToFight() != 2)
{
resume = AskToTryAgain(GetUserInput(tryAgain));
}
}
else if (input == 2)
{
resume = false;
}
else if (input != 2 || input != 1)
{
resume = AskToTryAgain(GetUserInput(tryAgain));
}
}
catch (Exception)
{
resume = AskToTryAgain(GetUserInput(tryAgain));
}
} while (resume == true);
}
public static void ShowMainMenu()
{
Console.WriteLine("Welcome to Rock Paper Scissors!");
Console.WriteLine("1. Play");
Console.WriteLine("2. Quit");
}
public static string GetUserInput(string message)
{
Console.WriteLine(message);
return Console.ReadLine();
}
public static bool AskToTryAgain(string input)
{
try
{
if (input.ToLower()[0] == 'y')
return true;
else if (input.ToLower()[0] == 'n')
return false;
else
Console.WriteLine("Wrong input. Would you like to try again? (y/n)");
string input2 = Console.ReadLine();
AskToTryAgain(input2);
}
catch (StackOverflowException)
{
string userError = GetUserInput("That's not right. Try again: 'y' or 'n'");
AskToTryAgain(userError);
}
return true;
}
public static int AskWhichOpponentToFight()
{
try
{
return int.Parse(GetUserInput("Which opponent would you like to fight? \n 1. Rock Guy \n 2. Normal Guy"));
}
catch (Exception)
{
return AskWhichOpponentToFight();
}
}
}
}