-
Notifications
You must be signed in to change notification settings - Fork 556
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (62 loc) · 2.59 KB
/
Program.cs
File metadata and controls
78 lines (62 loc) · 2.59 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
class Program
{
static void Main(string[] args)
{
List<Game> gameHistory = new List<Game>();
while (true) {
Console.WriteLine("\t====== Math Game ======\nPick an Option:");
Console.WriteLine("[1] Addition \n[2] Subtraction \n[3] Multiplication \n[4] Division \n[5] History \n[0] Exit");
Console.Write("=> ");
int userChoice;
if (!(int.TryParse(Console.ReadLine(), out userChoice)))
{
Console.WriteLine("Invalid Input!");
}
if ((MenuOption)userChoice == MenuOption.History)
{
Console.WriteLine("\t=== Game History ===");
for (int i = 0; i <= gameHistory.Count - 1; i++)
{
Console.WriteLine($"\n[Game {i + 1}] (Score: {gameHistory[i].score})");
Console.WriteLine($"{"Problem".PadRight(12)}{"Your Answer".PadRight(12)}{"Correct Answer".PadRight(12)}{"Status".PadLeft(10)}");
foreach (Problem p in gameHistory[i].problemSet)
{
Console.WriteLine(p.ToString());
}
}
Console.WriteLine("Press any key to go back to main menu => ");
Console.ReadKey();
continue;
} else if ((MenuOption)userChoice == MenuOption.Exit)
{
Console.WriteLine("Goodbye!");
Environment.Exit(0);
}
int score = 0;
List<Problem> ProblemSet = new List<Problem>();
for (int i = 0; i <= 4; i++)
{
// cast the userChoice to it's corresponding enum option
Problem generatedProblem = ProblemGenerator.GenerateProblem((MenuOption)userChoice);
ProblemSet.Add(generatedProblem);
Console.WriteLine($"\t == Problem {i}: ==");
Console.WriteLine($"{generatedProblem.Text}");
Console.Write("=> ");
int.TryParse(Console.ReadLine(), out int userAnswer);
generatedProblem.SetUserAnswer(userAnswer);
if (userAnswer == generatedProblem.Answer)
{
Console.WriteLine("Correct!");
generatedProblem.CorrectlyAnswered = true;
score++;
} else
{
Console.WriteLine("Wrong!");
generatedProblem.CorrectlyAnswered = false;
}
}
Game currentGame = new Game(score, ProblemSet);
gameHistory.Add(currentGame);
}
}
}