-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (52 loc) · 1.7 KB
/
main.cpp
File metadata and controls
62 lines (52 loc) · 1.7 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 "game.h"
using std::cout;
using std::cin;
using std::string;
int main(int argc, char **argv) {
string high_scores_filename = "high_scores.txt";
int maxNumber = 100;
std::map<string, int> arrScore = readScoreTable(high_scores_filename);
if (argc > 3) {
cout << "Error! Use one parametr." << std::endl;
cout << "[-max xxx] [-table] [-level [1..3]]" << std::endl;
} else if (argc > 1) {
if (string(argv[1]) == "-max") {
if (argc == 3) {
maxNumber = std::stoi(argv[2]);
}
} else if (string(argv[1]) == "-level") {
if (argc == 3) {
int level = std::stoi(argv[2]);
switch (level) {
case 1:
maxNumber = 10;
break;
case 2:
maxNumber = 50;
break;
case 3:
maxNumber = 100;
break;
default:
cout << "Level value from 1 to 3" << std::endl;
return 0;
}
}
} else if (string(argv[1]) == "-table") {
showScoreTable(arrScore);
return 0;
}
}
string gamerName;
cout << "Hi! Enter your name, please:";
cin >> gamerName;
int hiddenNumber = getRandomNumber(maxNumber);
int attempt = startGame(hiddenNumber);
if (arrScore[gamerName] == 0 || attempt < arrScore[gamerName]) {
arrScore[gamerName] = attempt;
}
showScoreTable(arrScore);
writeSoreTable(high_scores_filename, arrScore);
return 0;
}