/
main.cpp
99 lines (94 loc) · 2.22 KB
/
main.cpp
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
#include <random>
#include <functional>
#include "GameScreen.h"
#include "HelpScreen.h"
#include "Prompt.h"
template<class T = std::mt19937, std::size_t N = T::state_size>
auto ProperlySeededRandomEngine()->typename std::enable_if<!!N, T>::type
{
typename T::result_type random_data[N];
std::random_device source;
std::generate(std::begin(random_data), std::end(random_data), std::ref(source));
std::seed_seq seeds(std::begin(random_data), std::end(random_data));
T seededEngine(seeds);
return seededEngine;
}
int main()
{
LIBCARD::Deck d;
d.RemoveCard(LIBCARD::JOCKER_CARD);
auto rng = ProperlySeededRandomEngine();
d.Shuffle(rng);
FREECELL::Board b;
b.Place(d);
GameScreen g;
g.Update(b);
g.Draw();
HelpScreen h;
Prompt in;
while (true)
{
std::string input;
do
{
g.ShowPrompt();
in.GetString(input);
} while (input.empty());
if (input[0] == 'q' || input[0] == 'e')
{
break;
}
else if (input[0] == 'h' || input[0] == '?')
{
h.Draw();
}
else if (input[0] == 'n')
{
b.Clear();
d.Recreate();
d.RemoveCard(LIBCARD::JOCKER_CARD);
d.Shuffle(rng);
b.Place(d);
g.Update(b);
g.Draw();
}
else if (input[0] == 's')
{
g.Draw();
}
else if (input[0] == 'm')
{
std::string err_msg;
bool success = b.Process(input, err_msg);
if (success)
{
g.Update(b);
g.Draw();
}
else
{
g.ShowStatus(err_msg);
}
}
else if (input[0] == 'c')
{
std::string err_msg;
bool success = b.AutoCheck(err_msg);
if (success)
{
g.Update(b);
g.Draw();
}
else
{
g.ShowStatus(err_msg);
}
}
else
{
g.ShowStatus("Unknown command");
}
}
g.ShowStatus("Thank you!");
return 0;
}