-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathApplication.cpp
More file actions
122 lines (114 loc) · 4.06 KB
/
Application.cpp
File metadata and controls
122 lines (114 loc) · 4.06 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
113
114
115
116
117
118
119
120
121
122
#include "Application.h"
#include "imgui/imgui.h"
#include "classes/TicTacToe.h"
#include "classes/Checkers.h"
#include "classes/Othello.h"
#include "classes/Connect4.h"
#include "classes/Chess.h"
#include "classes/Logger.h"
namespace ClassGame {
//
// our global variables
//
Game *game = nullptr;
bool gameOver = false;
int gameWinner = -1;
//
// game starting point
// this is called by the main render loop in main.cpp
//
Logger* L = Logger::getInstance();
void GameStartUp()
{
game = nullptr;
}
//
// game render loop
// this is called by the main render loop in main.cpp
//
void RenderGame()
{
ImGui::DockSpaceOverViewport();
L->ShowLogWindow();
//ImGui::ShowDemoWindow();
ImGui::Begin("Settings");
if (gameOver) {
ImGui::Text("Game Over!");
ImGui::Text("Winner: %d", gameWinner);
if (ImGui::Button("Reset Game")) {
game->stopGame();
game->setUpBoard();
gameOver = false;
gameWinner = -1;
}
}
if (!game) {
if (ImGui::Button("Start Tic-Tac-Toe")) {
game = new TicTacToe();
game->setUpBoard();
}
if (ImGui::Button("Start Checkers")) {
game = new Checkers();
game->setUpBoard();
}
if (ImGui::Button("Start Othello")) {
game = new Othello();
game->setUpBoard();
}
if (ImGui::Button("Start Connect 4")) {
game = new Connect4();
game->setUpBoard();
}
if (ImGui::Button("Start Chess")) {
game = new Chess();
game->setUpBoard();
}
} else {
ImGui::Text("Current Player Number: %d", game->getCurrentPlayer()->playerNumber());
std::string stateString = game->stateString();
int stride = game->_gameOptions.rowX;
int height = game->_gameOptions.rowY;
for(int y=0; y<height; y++) {
ImGui::Text("%s", stateString.substr(y*stride,stride).c_str());
}
ImGui::Text("Current Board State: %s", game->stateString().c_str());
}
ImGui::End();
ImGui::Begin("GameWindow");
if (game) {
if (game->gameHasAI() && (game->getCurrentPlayer()->isAIPlayer() || game->_gameOptions.AIvsAI))
{
game->updateAI();
}
game->drawFrame();
}
ImGui::End();
}
//
// end turn is called by the game code at the end of each turn
// this is where we check for a winner
//
void EndOfTurn()
{
//L->LogGameEvent("looking for winner...");
Player *winner = game->checkForWinner();
if (winner)
{
//L->LogInfo("there is a winner");
gameOver = true;
gameWinner = winner->playerNumber();
if(gameWinner == 0) {
L->LogGameEvent("White has won.");
} else {
L->LogGameEvent("Black has won.");
}
} else {
//L->LogInfo("no winner returned");
}
if (game->checkForDraw()) {
//L->LogInfo("there is no winner");
gameOver = true;
gameWinner = -1;
}
}
}