-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cpp
More file actions
112 lines (106 loc) · 2.67 KB
/
settings.cpp
File metadata and controls
112 lines (106 loc) · 2.67 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#pragma once
#include "table.hpp"
/**
* @brief lets user set the table
*
* @param none
*
* @return nothing
*/
void Table::settings()
{
// greeting the users
cout << "Welcome to Othello Game" << endl
<< endl
<< "1 for human vs cpu" << endl
<< "2 for human vs human" << endl
<< "3 for cpu vs cpu" << endl
<< "4 to load a game from a file" << endl
<< endl
<< "Enter your choice: ";
// getting the choice
char temp;
temp = getche();
GameMode choice = (GameMode)stoi(&temp);
cout << endl;
// checking the choice
try
{
if (choice != HUMAN_VS_HUMAN && choice != HUMAN_VS_CPU && choice != CPU_VS_CPU && choice != LOAD_GAME)
{
throw "Invalid game mode\n";
}
}
catch (const char *msg)
{
std::cerr << msg;
sleep(2000);
exit(EXIT_FAILURE);
}
setGameMode((GameMode)choice);
// in case of 1, we let the user choose the side
if (getGameMode() == HUMAN_VS_CPU)
{
cout << "Enter 'b' to play BLACK, 'w' to play WHITE: ";
char side;
side = getche();
cout << endl;
if (side == 'b' || side == 'B')
setUserSide(BLACK);
else if (side == 'w' || side == 'W')
setUserSide(WHITE);
else
{
cout << "Invalid choice!!!";
sleep(2000);
exit(EXIT_FAILURE);
}
}
if (getGameMode() == LOAD_GAME)
{
cout << "Enter the file name: ";
string fileName;
cin >> fileName;
fstream file;
// open the file in read mode
try
{
file.open(fileName, ios::in);
if (!file.is_open())
{
throw "File not found\n";
sleep(2000);
exit(EXIT_FAILURE);
}
}
catch (const char *msg)
{
std::cerr << msg;
sleep(2000);
exit(EXIT_FAILURE);
}
file.close();
// check if the file has valid data
this->moves = loadFromFile(fileName);
try
{
if (!checkFile())
{
throw "Invalid file\n";
}
}
catch (const char *msg)
{
std::cerr << msg;
sleep(2000);
exit(EXIT_FAILURE);
}
}
char guid;
cout << "Would you like guidance? (y/n): ";
guid = getche();
if (guid == 'y' || guid == 'Y')
setGuidance(true);
else
setGuidance(false);
}