-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
70 lines (69 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
#include "game.h"
int main()
{
std::cout << "Welcome to Impasse!\n\nFor game rules enter 'howto' or visit: https://www.marksteeregames.com/Impasse_rules.pdf\n\nEngine and AI implemented by: Balazs Horvath (https://bghorvath.dev)" << std::endl;
bool play = true;
while (play)
{
// if savegame is available from previous session, ask if user wants to continue
std::string answer;
std::ofstream newfile;
newfile.open(".savegame", std::ios::in);
if (newfile.is_open())
{
std::cout << "Do you want to load the last saved game? (yes/no): ";
std::cin >> answer;
if (answer == "yes")
{
Game game = Game();
}
else
{
// otherwise start a new game
goto newgame;
}
}
else
{
newgame:
int player = 0;
// ask to choose player and time limit
while (player == 0)
{
std::cout << "Choose your color (white/black): ";
std::cin >> answer;
if (answer == "white")
{
player = 1;
}
else if (answer == "black")
{
player = -1;
}
else
{
std::cout << "Invalid answer" << std::endl;
};
};
int timemin = 10;
std::cout << "Choose time limit per player (minutes): ";
std::cin >> answer;
try
{
timemin = std::stoi(answer);
}
catch (const std::exception &e)
{
std::cout << "Invalid answer, defaulting to 10 minutes" << std::endl;
};
Game game = Game(player, timemin);
};
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout << "Would you like to play again? (yes/no): ";
std::cin >> answer;
play = answer == "yes";
};
std::cout << "Thank you for playing!" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
return 0;
}