-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
90 lines (81 loc) · 2.23 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
#include ".\controls\Resourcepack.h"
#include ".\controls\2048_Brick.h"
#include ".\controls\2048_Classic.h"
using namespace sf;
int main() {
srand(time(NULL));
RenderWindow window(VideoMode(950, 720), "2048", Style::Titlebar | Style::Close);
Resourcepack res;
Music music;
G2048::Skin skin;
G2048::Classic classic;
G2048::Brick brick;
Picture background;
Button classicButton, brickButton, resouButton;
bool isMainmenu = 0;
// Game::initialization
skin.init(&window, &res, &music);
classic.init(&window, &res, &music);
brick.init(&window, &res, &music);
// Game::loadResourcepack
classic.loadResourcepack();
brick.loadResourcepack();
background.setTexture(res.getTexture("mainmenu"));
res.setButton(classicButton, "classic");
res.setButton(brickButton, "brick");
res.setButton(resouButton, "newskin");
// Game::start
music.play();
while (window.isOpen()) {
if (music.getStatus() == sf::Sound::Status::Stopped) {
music.openFromFile(res.getNextSound("music"));
music.play();
}
if (isMainmenu == 0) {
window.clear();
background.draw(&window);
classicButton.draw(&window);
brickButton.draw(&window);
resouButton.draw(&window);
window.display();
isMainmenu = 1;
}
Event e;
while (window.pollEvent(e)) {
if (e.type == Event::Closed || (e.type == Event::KeyPressed && e.key.code == Keyboard::Escape)) {
window.close();
}
else if (e.type == Event::MouseButtonReleased) {
if (classicButton.clicked(&window)) {
// play 2048::classic
classic.start();
}
else if (brickButton.clicked(&window)) {
// play 2048::brick
brick.start();
}
else if (resouButton.clicked(&window)) {
// make window background
window.clear();
background.draw(&window);
classicButton.draw(&window);
brickButton.draw(&window);
resouButton.draw(&window);
// change resourcepack
skin.open();
// Game::loadResourcepack
classic.loadResourcepack();
brick.loadResourcepack();
background.setTexture(res.getTexture("mainmenu"));
res.setButton(classicButton, "classic");
res.setButton(brickButton, "brick");
res.setButton(resouButton, "newskin");
}
else continue;
isMainmenu = 0;
}
}
}
music.stop();
return 0;
}