-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFireUtils.cs
104 lines (85 loc) · 2.93 KB
/
FireUtils.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
using System;
using System.Text;
namespace FireUtils
{
class Input
{
public static dynamic checkInput(string query, string check, string errorMsg, dynamic max, dynamic min)
{
bool goodInput = false;
while(goodInput == false)
{
// Question
Console.Write(query);
string inp = Console.ReadLine();
// Check type of answer wanted
switch (check)
{
case "num":
// Check if number
int result;
bool numberTrue = int.TryParse(inp, out result); // Try to parse as int
dynamic mingood = null;
dynamic maxgood = null;
if (numberTrue == true)
{
if (max != null)
{
if (result < max)
{
maxgood = true;
}
else
{
maxgood = false;
}
}
if (min != null)
{
if (result > min)
{
mingood = true;
}
else
{
mingood = false;
}
}
if (mingood != false && maxgood != false)
{
goodInput=true;
return result;
}
}
break;
case "bool":
// Check if y or n
inp = inp.ToLower();
switch (inp)
{
case "y":
goodInput = true;
return true;
case "n":
goodInput = true;
return false;
default:
goodInput = false;
break;
}
break;
default:
// No correct answer type given
Console.WriteLine("ERROR - Bad function call");
break;
}
if (goodInput == false)
{
// Bad answer
Console.WriteLine(errorMsg);
}
}
return true;
}
}
}