-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
252 lines (220 loc) · 7.75 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include<SFML/Graphics.hpp>
#include<iostream>
#include"Mainpage.h"
#include"BoardGame.h"
#include"GameLogic.h"
#include"Header.h"
#include"Setting.h"
using namespace std;
using namespace sf;
int GameOptions(RenderWindow& window);
int MainPage(RenderWindow& window);
int GoBack1(RenderWindow& window);
bool flag = false;
int main()
{
RenderWindow window(VideoMode(320, 480), "My Game");
MainPage(window);
}
int MainPage(RenderWindow& window)
{
Mainpage Mainpage(static_cast<float>(window.getSize().x), static_cast<float>(window.getSize().y));
//background start
Texture backg;
backg.loadFromFile("images/Background.png");
Sprite back(backg);
back.setPosition(0, 0);
Vector2f bg(0.35f, 0.35f);
back.setScale(bg);
//background end
while (true) {
while (window.isOpen()) {
window.clear();
window.draw(back);
Event event;
while (window.pollEvent(event)) {
if (event.type == Event::Closed) {
flag = false;
GoBack1(window);
break;
}
if (event.type == Event::KeyPressed)
{
if (event.key.code == Keyboard::Up)
{
Mainpage.MoveUp();
}
if (event.key.code == Keyboard::Down)
{
Mainpage.MoveDown();
}
if (event.key.code == Keyboard::Return)
{
switch (Mainpage.GetPressValue())
{
case 0:
cout << "Play button has been Pressed " << endl;
GameOptions(window);
break;
case 1:
cout << "setting button has been Pressed " << endl;
setting(window);
break;
case 2:
flag = false;
GoBack1(window);
break;
}
}
}
/*Vector2i mousePosition = Mouse::getPosition(window);
for (int i = 0; i < MAX_NUMBER_OF_ITEMS; i++) {
if (mainmenu[i].getGlobalBounds().contains(static_cast<float>(mousePosition.x), static_cast<float>(mousePosition.y))) {
hovering[i] = true;
if (Mouse::isButtonPressed(Mouse::Left)) {
switch (i) {
case 0:
cout << "Play button has been Pressed " << endl;
GameOptions(window);
break;
case 1:
cout << "setting button has been Pressed " << endl;
setting(window);
break;
case 2:
flag = false;
GoBack1(window);
break;
}
}
}
else {
hovering[i] = false;
}
}*/
}
Mainpage.draw(window);
window.display();
}
}
}
int GameOptions(RenderWindow& window)
{
Optionspage Optionspage(static_cast<float>(window.getSize().x), static_cast<float>(window.getSize().y));
//background start
Texture backg;
backg.loadFromFile("images/Background.png");
Sprite back(backg);
back.setPosition(0, 0);
Vector2f bg(0.35f, 0.35f);
back.setScale(bg);
//background end
while (true) {
while (window.isOpen()) {
window.clear();
window.draw(back);
Event event;
while (window.pollEvent(event)) {
if (event.type == Event::Closed) {
flag = true;
GoBack1(window);
break;
}
if (event.type == Event::KeyPressed)
{
if (event.key.code == Keyboard::Up)
{
Optionspage.MoveUp1();
}
if (event.key.code == Keyboard::Down)
{
Optionspage.MoveDown1();
}
if (event.key.code == Keyboard::Escape)
{
MainPage(window);
break;
}
if (event.key.code == Keyboard::Return)
{
switch (Optionspage.GetPressValue1())
{
case 0:
cout << "Bingo button has been Pressed " << endl;
Bingo(window);
break;
case 1:
cout << "SM button has been Pressed " << endl;
mainGame(window);
break;
case 2:
boardgame(window);
break;
case 3:
MainPage(window);
break;
}
}
}
}
Optionspage.draw1(window);
window.display();
}
}
}
int GoBack1(RenderWindow& window)
{
RenderWindow windowe(VideoMode(250, 100), "EXIT", Style::None);
EB EB(static_cast<float>(windowe.getSize().x), static_cast<float>(windowe.getSize().y));
while (true) {
while (windowe.isOpen()) {
Event event1;
while (windowe.pollEvent(event1)) {
if (event1.type == Event::Closed) {
windowe.close();
GameOptions(window);
break;
}
if (event1.type == Event::KeyPressed)
{
if (event1.key.code == Keyboard::Left)
{
EB.left();
}
if (event1.key.code == Keyboard::Right)
{
EB.right();
}
if (event1.key.code == Keyboard::Return)
{
switch (EB.GetPressValue1())
{
case 0:
cout << "YES" << endl;
windowe.close();
window.close();
break;
case 1:
cout << "NO" << endl;
if (flag)
{
windowe.close();
GameOptions(window);
}
else
{
windowe.close();
MainPage(window);
}
break;
}
}
}
}
windowe.clear(Color(64, 64, 64));
EB.drawe(windowe);
windowe.display();
}
}
return 0;
}