-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
115 lines (96 loc) · 2.45 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
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
113
114
115
#include "GomokuDraw.h"
#include <iostream>
#include "Game.h"
#include "gtest/gtest.h"
int main()
{
#ifdef ENABLE_TEST
testing::InitGoogleTest();
(void)RUN_ALL_TESTS();
#endif
try
{
Gomoku::Game game{};
if (!GomokuDraw::Init())
{
std::cerr << "Cannot init GomokuDraw" << std::endl;
return (-1);
}
// Draw loop
while (GomokuDraw::Go())
{
if (game.state_ == Gomoku::Game::State::Start)
{
// Отрисовать какие-то менюшки, туториалы и прочее.
}
// Экран ожидания
else if (game.state_ == Gomoku::Game::State::Main
|| game.state_ == Gomoku::Game::State::GameInPause)
{
GomokuDraw::DrawSome();
GomokuDraw::DrawStones(game.board_);
GomokuDraw::DrawGameMenu(game);
GomokuDraw::DrawGameMoves(game.board_);
ImGui::End();
}
// Экран игры
else if (game.state_ == Gomoku::Game::State::GameInProcess)
{
GomokuDraw::DrawSome();
GomokuDraw::DrawStones(game.board_);
auto w = game.whitePlayer->Ping();
auto b = game.blackPlayer->Ping();
bool wt = game.clock_.WhiteTimeLeft();
bool bt = game.clock_.BlackTimeLeft();
if (Gomoku::Board::MoveResult::WhiteWin == w
|| !bt)
{
game.state_ = Gomoku::Game::State::GameEndedWhiteWin;
game.clock_.Pause();
}
else if (Gomoku::Board::MoveResult::Draw == w)
{
game.state_ = Gomoku::Game::State::GameEndedDraw;
game.clock_.Pause();
}
if (Gomoku::Board::MoveResult::BlackWin == b
|| !wt)
{
game.state_ = Gomoku::Game::State::GameEndedBlackWin;
game.clock_.Pause();
}
else if (Gomoku::Board::MoveResult::Draw == b)
{
game.state_ = Gomoku::Game::State::GameEndedDraw;
game.clock_.Pause();
}
GomokuDraw::DrawGameMenu(game);
GomokuDraw::DrawGameMoves(game.board_);
ImGui::End();
}
else if (game.state_ == Gomoku::Game::State::GameEndedWhiteWin
|| game.state_ == Gomoku::Game::State::GameEndedBlackWin
|| game.state_ == Gomoku::Game::State::GameEndedDraw)
{
GomokuDraw::DrawSome();
GomokuDraw::DrawStones(game.board_);
GomokuDraw::DrawGameMenu(game);
GomokuDraw::DrawGameMoves(game.board_);
ImGui::End();
}
// Render
GomokuDraw::Render();
}
// Cleanup
GomokuDraw::Cleanup();
}
catch (const std::exception &e)
{
std::cerr << e.what() << std::endl;
}
catch (...)
{
std::cerr << "Unknown exception, exit()" << std::endl;
}
return 0;
}