-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
152 lines (136 loc) · 3.54 KB
/
Menu.cpp
File metadata and controls
152 lines (136 loc) · 3.54 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "Menu.h"
#include "Questions/Question.hpp"
#include "Questions/Questions.h"
#include <curses.h>
#include <iostream>
#include <string>
#include <unistd.h>
Menu::Menu ()
: StringInput (), IntInput (), Type (-1), Variant (-1), AvailableOptions ()
{
}
void
Menu::Run ()
{
bool running = true;
while (running)
{
Type = GetType ();
if (Type == 0)
{
running = false;
continue;
}
Variant = GetVariant (Type);
QuestionMap.at ({ Type, Variant }) ();
}
Exit ();
}
int
Menu::GetType ()
{
while (true)
{
std::cout << "Choose question type: \n";
for (const auto &[type, variant] : AvailableOptions)
{
std::cout << type << ") " << GetQuestionName (type)
<< std::endl;
}
std::getline (std::cin, StringInput);
Type = GetInteger (StringInput);
if (AvailableOptions.count (Type))
{
break;
}
Clear ();
std::cout << "Invalid type. Try again.\n";
}
return Type;
}
int
Menu::GetVariant (int T)
{
while (true)
{
std::cout << "Choose variant for Type " << Type << std::endl;
std::cout << GetVariants (T) << std::endl;
std::getline (std::cin, StringInput);
Variant = GetInteger (StringInput);
if (AvailableOptions[T].count (Variant))
{
break;
}
Clear ();
std::cout << "Invalid Input. Try again.\n";
}
return Variant;
}
std::string
Menu::GetQuestionName (int id)
{
switch (id)
{
case 0:
return "Exit";
case 1:
return "Electric Charge";
default:
return "Unknown";
}
}
void
Menu::Initialize ()
{
QuestionMap[{ 1, 1 }] = [this] ()
{
std::cout << "Chosen question: Type(1), Variant(1)\n";
bool LoopVariant = true;
CoulombValue solve;
while (LoopVariant)
{
Clear ();
solve.Solve ();
Question::Return action = solve.CallBack ();
if (action == Question::Return::MainMenu)
{
Clear ();
LoopVariant = false;
}
}
};
QuestionMap[{ 1, 2 }] = [this] ()
{
std::cout << "Chosen question: Type(1), Variant(2)\n";
bool LoopVariant = true;
ElectronCharge solve;
while (LoopVariant)
{
Clear ();
solve.Solve ();
Question::Return action = solve.CallBack ();
if (action == Question::Return::MainMenu)
{
Clear ();
LoopVariant = false;
}
}
};
for (const auto &[key, func] : QuestionMap)
{
Type = key.first;
Variant = key.second;
AvailableOptions[Type].insert (Variant);
}
}
std::string
Menu::GetVariants (int id)
{
switch (id)
{
case 1:
return "1) Electron -> Coulomb\n2) Coulomb -> Electron";
default:
return "Unknown Variant";
}
}