-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
162 lines (152 loc) · 5 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <iostream>
#include <SFML/Graphics.hpp>
#include "chessGame.h"
#include "mainMenu.h"
#include "help.h"
#include "recent.h"
int main()
{
MainMenu menu;
Recent recent_page;
ChessGame chess(sf::Color(0xf3bc7aff), sf::Color(0xae722bff));
sf::RenderWindow window(sf::VideoMode(768, 512), "Chess Game", sf::Style::Titlebar | sf::Style::Close);
window.setVerticalSyncEnabled(true);
Help help;
bool isHelp = false;
bool isMenu = true;
bool isGame = false;
bool isRecentPage = false;
// MainMenu menu;
// appliaction starts here
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
// For Main Menu
if (isMenu)
{
if (event.type == sf::Event::KeyReleased)
{
if (event.key.code == sf::Keyboard::Up)
{
menu.moveUp();
}
if (event.key.code == sf::Keyboard::Down)
{
menu.moveDown();
}
if (event.key.code == sf::Keyboard::Enter)
{
if (menu.getSelectedMenu() == 0)
{
window.clear();
isMenu = false;
isGame = true;
}
else if (menu.getSelectedMenu() == 2)
{
window.clear();
isHelp = true;
isMenu = false;
}
else if (menu.getSelectedMenu() == 1)
{
window.clear();
isMenu = false;
isRecentPage = true;
}
else
{
window.close();
}
}
}
}
if (isRecentPage)
{
recent_page.loadDetail();
if (event.type == sf::Event::KeyReleased)
{
if (event.key.code == sf::Keyboard::Escape)
{
window.clear();
isRecentPage = false;
isMenu = true;
recent_page.cleanUp();
}
}
}
if (isHelp)
{
if (event.type == sf::Event::KeyReleased)
{
if (event.key.code == sf::Keyboard::Escape)
{
window.clear();
isMenu = true;
isHelp = false;
}
if (event.key.code == sf::Keyboard::Right)
{
help.nextPage();
}
if (event.key.code == sf::Keyboard::Left)
{
help.prevPage();
}
}
}
// For GamePlay
if (isGame)
{
if (event.type == sf::Event::KeyReleased)
{
if (event.key.code == sf::Keyboard::Escape)
{
window.clear();
isGame = false;
isMenu = true;
}
}
if (event.type == sf::Event::MouseButtonPressed)
{
if (event.mouseButton.button == sf::Mouse::Left)
{
if ((0 <= event.mouseButton.x) && (event.mouseButton.x <= 512) && (0 <= event.mouseButton.y) && (event.mouseButton.y <= 512))
{
unsigned int buttonPos{(event.mouseButton.x / 64) + ((event.mouseButton.y / 64) * (8 * (512 / window.getSize().y)))};
if (!chess.getSelected())
chess.selectPiece(buttonPos);
else
chess.moveSelected(buttonPos);
}
else if ((517 <= event.mouseButton.x) && (event.mouseButton.x <= 763) && (5 <= event.mouseButton.y) && (event.mouseButton.y <= 45))
{
chess.restart();
}
}
}
}
}
if (isGame)
{
window.draw(chess);
}
if (isMenu)
{
window.draw(menu);
}
if (isRecentPage)
{
window.draw(recent_page);
}
if (isHelp)
{
window.draw(help);
}
window.display();
}
}