Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
142 lines (117 loc) · 3.53 KB
/
Copy pathmain.cpp
File metadata and controls
142 lines (117 loc) · 3.53 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
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
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include "globalVar.hpp"
#include "Themes/themesRead.h"
#include "Themes/Themes.hpp"
#include "MainMenu/MainMenu.hpp"
#include "PlayScreen/PlayScreen.hpp"
#include "Profile/playerData.hpp"
#include "Learn/learn.hpp"
#include "LeaderBoard/leaderboard.hpp"
#include "Settings/settings.hpp"
#include "AI/AIPlayer.hpp"
#include "lang/Translations.hpp"
// variabila globala folosita in tot proiectul
int interfata = 1;
std::string Music = "";
std::string soundEffects = "";
std::string fps = "";
std::string language = "EN";
sf::Music bgMusic;
int main()
{
LoadPlayerData();
InitTranslations();
if (language == "RO") {
SetTranslationLanguage(Romanian);
} else {
SetTranslationLanguage(English);
}
Themes();
if (!bgMusic.openFromFile("Themes/song.mp3")) {
std::cerr << "Error loading Themes/song.mp3" << std::endl;
}
else {
bgMusic.setLooping(true);
bgMusic.setVolume(30.f);
if (Music == "ON") {
bgMusic.play();
}
}
sf::VideoMode desktopMode = sf::VideoMode::getDesktopMode();
sf::RenderWindow window;
window.create(desktopMode, "Razboi in 8", sf::Style::Default, sf::State::Fullscreen);
window.setFramerateLimit(60);
// Initializeaza seed-ul pentru generatorul de numere pseudo-aleatoare al calculatorului.
// Folosesc adrese (care de obicei difera intre rulari datorita ASLR) + dimensiunea ferestrei
{
std::uint32_t s = (std::uint32_t)(
(std::uintptr_t)&window ^
(std::uintptr_t)&interfata ^
((std::uint32_t)window.getSize().x << 16) ^
(std::uint32_t)window.getSize().y
);
if (s == 0) s = 1;
AI_Seed(s);
}
GameMenu menu;
GameThemes themePage;
SettingsMenu settings;
LeaderboardMenu leaderboard;
LearnMenu learn;
// initializeaza modulul de joc (Play)
Play_Init();
int lastInterfata = interfata;
while (window.isOpen()) {
while (auto event = window.pollEvent()) {
if (event->is<sf::Event::Closed>()) {
window.close();
}
if (interfata == 1) {
menu.handleInput(*event, window);
}
else if (interfata == 2) {
Play_HandleEvent(*event, window);
}
else if (interfata == 3) {
learn.handleInput(*event, window);
}
else if (interfata == 5) {
leaderboard.handleInput(*event, window);
}
else if (interfata == 7) {
themePage.handleInput(*event, window);
}
else if (interfata == 8) {
settings.handleInput(*event, window);
}
}
// daca tocmai am intrat in Play, reseteaza jocul
if (interfata == 2 && lastInterfata != 2) {
Play_Reset();
}
lastInterfata = interfata;
window.clear(themes[0].color_bg);
if (interfata == 1) {
menu.draw(window);
}
else if (interfata == 2) {
Play_Draw(window);
}
else if (interfata == 3) {
learn.draw(window);
}
else if (interfata == 5) {
leaderboard.draw(window);
}
else if (interfata == 7) {
themePage.draw(window);
}
else if (interfata == 8) {
settings.draw(window);
}
window.display();
}
return 0;
}