forked from mayerui/sudoku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.cpp
85 lines (70 loc) · 1.8 KB
/
input.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
#include <iostream>
#include <string>
#include "common.h"
#include "i18n.h"
#include "utility.inl"
// return number of grids to be erased
int inputDifficulty()
{
cls();
std::string cmd;
int need_erase_grids = 0;
while (true)
{
message(I18n::Instance().Get(I18n::Key::ASK_DIFFICULTY));
std::cin >> cmd;
try
{
Difficulty difficulty = static_cast<Difficulty>(std::stoi(cmd));
switch (difficulty)
{
case Difficulty::EASY:
need_erase_grids = 20;
break;
case Difficulty::NORMAL:
need_erase_grids = 35;
break;
case Difficulty::HARD:
need_erase_grids = 50;
break;
}
}
catch(...)
{
need_erase_grids = 0;
}
if (need_erase_grids > 0)
break;
message(I18n::Instance().Get(I18n::Key::INPUT_ERROR));
}
return need_erase_grids;
}
KeyMode inputKeyMode() {
std::string mode;
do {
message(I18n::Instance().Get(I18n::Key::ASK_KEY_MAP));
std::cin >> mode;
try {
KeyMode kmd = static_cast<KeyMode>(std::stoi(mode));
return kmd;
} catch (...) {
}
message(I18n::Instance().Get(I18n::Key::INPUT_ERROR));
} while (true);
}
void InputLanguage() {
std::string language;
do {
message("1English 2中文");
std::cin >> language;
try {
auto l = static_cast<Language>(std::stoul(language) - 1);
if (l < Language::MAX) {
I18n::Instance().SetLanguage(l);
return;
}
} catch (...) {
}
message(I18n::Instance().Get(I18n::Key::INPUT_ERROR));
} while (true);
}