Repository navigation
Expand file tree
/
Copy pathgame_prepare.cpp
More file actions
82 lines (76 loc) · 1.78 KB
/
Copy pathgame_prepare.cpp
File metadata and controls
82 lines (76 loc) · 1.78 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
#include "game_prepare.h"
//TODO add doxygen comments style
//TODO try autoformat tools
bool getMaxValue(const int argc, const char** argv, int &maxValue)
{
const std::string helpMessage = "Start program with --help parametr for more information";
// Let's print this argument
if (argc < 2)
{
maxValue = defMaxValue;
}
else
{
std::string arg1_value{ argv[1] };
if (arg1_value == "--max")
{
// We've detected the '-parameter' argument. And we extect that after this argument there is a value:
// We need to parse the string to the int value
if (argc < 3)
{
std::cout << "Wrong arguments number! " << helpMessage << std::endl;
return 1;
}
else
{
maxValue = std::stoi(argv[2]);
if (maxValue < 0)
{
std::cout << "Number can't be negative" << std::endl;
return 1;
}
}
}
else if (arg1_value == "--help")
{
std::cout<< "suported arguments:" << std::endl
<< "--help" << std::endl
<< "--max NUMBER" << std::endl
<< "--table" << std::endl;
return 1;
}
else if(arg1_value == "--table")
{
printLog ();
return 1;
}
else
{
std::cout << "Wrong parametr name. "<< helpMessage << std::endl;
return 1;
}
}
std::cout << "Max value = " << maxValue << std::endl;
return 0;
}
bool calcRandomNumber(const int maxValue, int &randomNumber)
{
if(maxValue < 0)
{
return 1;
}
else
{
std::srand(std::time(nullptr)); // use current time as seed for random generator
randomNumber = std::rand() % (maxValue+1);
return 0;
}
}
std::string getUser()
{
// Ask about name
std::cout << "Enter your name, please:" << std::endl;
std::string user_name;
std::cin >> user_name; //TODO check user input
return user_name;
}