-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputParser.cs
More file actions
62 lines (56 loc) · 1.45 KB
/
InputParser.cs
File metadata and controls
62 lines (56 loc) · 1.45 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KnowledgePath
{
public class InputParser
{
public enum Selection
{
Invalid = -1,
Quit = 0,
Subject1 = 1,
Subject2 = 2,
Subject3 = 3,
Restart = 9
}
public bool restart;
public bool quit;
public Selection selection;
public InputParser()
{
selection = Selection.Invalid;
restart = false;
quit = false;
}
/* Choices are 1-3, 'q' returns 0, other entries return -1*/
public void GetUserChoice()
{
char input = Console.ReadKey().KeyChar;
if (char.IsNumber(input))
{
int value = (int)char.GetNumericValue(input);
if (value >= 1 && value <= 3)
{
selection = (Selection) value;
}
else
{
selection = Selection.Invalid;
}
}
else if (input == 'q' || input == 'Q')
{
selection = Selection.Quit;
quit = true;
}
else if (input == 'r' || input == 'R')
{
selection = Selection.Restart;
restart = true;
}
}
}
}