-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
127 lines (107 loc) · 2.49 KB
/
Game.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
116
117
118
119
120
121
122
123
124
125
126
127
#include "Game.h"
void Game::start(void)
{
if (_gameState != Uninitialized)
return;
_mainWindow.create(sf::VideoMode(800, 600, 32),"Chess");
_mainWindow.setPosition(sf::Vector2i(0, 0));
//Where we will load all objects then place in gameobjectmanager
VisibleGameObject *boardImage = new VisibleGameObject();
boardImage->Load("images/Board.png");
boardImage->setPostion(0, 0);
VisibleGameObject *Rook = new VisibleGameObject();
Rook->Load("images/WhiteRook.png");
Rook->setPostion(15, 15);
_gameObjectManager.add("Board", boardImage);
_gameObjectManager.add("WR1", Rook);
_gameState = Game::ShowingSplash;
while (!isExiting())
{
loop();
}
_mainWindow.close();
}
bool Game::isExiting()
{
if (_gameState == Game::Exiting)
return true;
else
return false;
}
void Game::loop()
{
switch (_gameState)
{
case Game::ShowingSplash:
{
showSplashScreen();
break;
}
case Game::ShowingMenu:
{
showMenu();
break;
}
case Game::ShowingOptions:
{
//showOptions();
break;
}
case Game::Playing:
{
sf::Event currentEvent;
while (_mainWindow.pollEvent(currentEvent))
{
_mainWindow.clear(sf::Color(0,0,0));
_gameObjectManager.drawAll(_mainWindow);
_mainWindow.display();
//add a loop here that waits for a click
//then launch the handle click function
waitForClick(currentEvent);
}
break;
}
}
}
void Game::showSplashScreen()
{
SplashScreen splash;
splash.show(_mainWindow);
_gameState = Game::ShowingMenu;
}
void Game::showMenu()
{
MenuScreen mainMenu;
MenuScreen::MenuResult result = mainMenu.show(_mainWindow);
switch (result)
{
case MenuScreen::Exit:
_gameState = Game::Exiting;
break;
case MenuScreen::Play:
_gameState = Game::Playing;
break;
case MenuScreen::Options:
_gameState = Game::ShowingOptions;
break;
}
}
void Game::waitForClick(sf::Event ¤tEvent)
{
//closes window if user chooses to quit
if (currentEvent.type == sf::Event::Closed)
{
_gameState = Game::Exiting;
}
else if (currentEvent.type == sf::Event::MouseButtonPressed)
{
//get the coordinate that were clicked on
float x = currentEvent.mouseButton.x;
float y = currentEvent.mouseButton.y;
//check if they are on the board
//check if they are on a chesspiece
}
}
Game::GameState Game::_gameState = Uninitialized;
sf::RenderWindow Game::_mainWindow;
GameObjectManger Game::_gameObjectManager;