-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay.cpp
More file actions
62 lines (56 loc) · 1.77 KB
/
Copy pathplay.cpp
File metadata and controls
62 lines (56 loc) · 1.77 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
#include<iostream>
#include<vector>
#include<string>
#include "play.h"
#include "parsing.h"
#include "platform_utils.h"
#include "logging.h"
using namespace std;
size_t showOptions(vector<string> optionsList, string title) {
dbg(LOG_NOTE, "Showing options menu: " + title);
bool optionsActive = true;
size_t selectedIndex = 0;
while (optionsActive) {
cout << "\033[2J\033[H";
cout << title << endl;
for (int i = 0; i < optionsList.size(); i++) {
if (selectedIndex == i) {
cout << "> " + optionsList[i] << endl;
} else {
cout << " " + optionsList[i] << endl;
}
}
int c = PlatformUtils::getch();
if (c == PlatformUtils::KEY_UP) {
selectedIndex = (selectedIndex - 1 + optionsList.size()) % optionsList.size();
} else if (c == PlatformUtils::KEY_DOWN) {
selectedIndex = (selectedIndex + 1) % optionsList.size();
} else if (c == PlatformUtils::KEY_ENTER) {
optionsActive = false;
}
}
return selectedIndex;
}
vector<string> sitOptionsToStrings(Situation sit) {
vector<string> optTemp;
for (Option opt : sit.options) {
optTemp.push_back(opt.optionText);
}
return optTemp;
}
size_t playSit(vector<Situation> sits, size_t sitNum) {
size_t selectedOptReferSitNum = 0;
for (Situation sit : sits) {
if (sit.situationNum == sitNum) {
selectedOptReferSitNum = sit.options[showOptions(sitOptionsToStrings(sit), sit.title)].referSituationNum;
}
}
return selectedOptReferSitNum;
}
void playGame(vector<Situation> game) {
cout << "\033[2J\033[H";
size_t curSitNum = 1;
while (curSitNum != 0) {
curSitNum = playSit(game, curSitNum);
}
}