-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (51 loc) · 1.41 KB
/
Copy pathmain.cpp
File metadata and controls
58 lines (51 loc) · 1.41 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
#include <iostream>
#include <vector>
#include <string>
#include "functions.hpp"
int main() {
int player = 1;
bool is_game_over = false;
int game = 1;
int maximum_games = 3;
int player_1_wins = 0;
int player_2_wins = 0;
reset_grid();
while (!is_game_over) {
print_grid();
get_user_input(player);
if (is_winner()) {
if (player == 1) {
player_1_wins++;
}
else {
player_2_wins++;
}
if (player_1_wins == 2) {
std::cout << "Player 1 wins!" << std::endl;
is_game_over = true;
}
else if (player_2_wins == 2) {
std::cout << "Player 2 wins!" << std::endl;
is_game_over = true;
}
else {
player = (player == 1) ? 2 : 1;
if (player == 1) {
std::cout << "Player 1 wins this round!" << std::endl;
} else {
std::cout << "Player 2 wins this round!" << std::endl;
}
show_score(player_1_wins, player_2_wins);
reset_grid();
}
}
else if (is_draw()) {
std::cout << "It's a draw!" << std::endl;
reset_grid();
}
else {
player = (player == 1) ? 2 : 1;
}
}
return 0;
}