forked from Spebby/CMPM123-Chess
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApplication.cpp
More file actions
71 lines (63 loc) · 1.99 KB
/
Application.cpp
File metadata and controls
71 lines (63 loc) · 1.99 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
#include "Application.h"
#include "imgui/imgui.h"
#include "classes/Chess.h"
namespace ClassGame {
//
// our global variables
//
Chess *game = nullptr;
bool gameOver = false;
int gameWinner = -1;
//
// game starting point
// this is called by the main render loop in main.cpp
//
void GameStartUp()
{
game = new Chess();
game->setUpBoard();
}
//
// game render loop
// this is called by the main render loop in main.cpp
//
void RenderGame()
{
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport());
ImGui::ShowDemoWindow();
ImGui::Begin("Settings");
ImGui::Text("Current Player Number: %d", game->getCurrentPlayer()->playerNumber());
ImGui::Text("Current Board State: %s", game->stateString().c_str());
if (gameOver) {
ImGui::Text("Game Over!");
ImGui::Text("Winner: %d", gameWinner);
if (ImGui::Button("Reset Game")) {
game->stopGame();
game->setUpBoard();
gameOver = false;
gameWinner = -1;
}
}
ImGui::End();
ImGui::Begin("GameWindow");
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()
{
Player *winner = game->checkForWinner();
if (winner)
{
gameOver = true;
gameWinner = winner->playerNumber();
}
if (game->checkForDraw()) {
gameOver = true;
gameWinner = -1;
}
}
}