-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnakewindow.cpp
More file actions
70 lines (53 loc) · 2.02 KB
/
snakewindow.cpp
File metadata and controls
70 lines (53 loc) · 2.02 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
#include "snakewindow.hpp"
using namespace std;
SnakeWindow::SnakeWindow(QWidget *pParent, Qt::WindowFlags flags):QMainWindow(pParent, flags)
{
// Initialisation de la fenêtre
this->setWindowTitle("Snake by Thomas and Bastien");
this->setFixedSize(WINDOW_COL*CASE_SIZE, WINDOW_ROWS*CASE_SIZE);
// Creation du menu principal et ajout au stacked widget
m_stackedWidget = new QStackedWidget(this);
m_mainMenu = new MainMenu(this);
m_stackedWidget->addWidget(m_mainMenu);
m_stackedWidget->setCurrentWidget(m_mainMenu);
setCentralWidget(m_stackedWidget);
// Connexion des signaux du menu principal
connect(m_mainMenu, &MainMenu::playClicked, this, &SnakeWindow::handlePlayClicked);
connect(m_mainMenu, &MainMenu::exitClicked, this, &SnakeWindow::handleExitClicked);
connect(m_mainMenu, &MainMenu::createMapClicked, this, &SnakeWindow::handleCreateMapClicked);
// Initialisation du système de son
initializeSoundSystem();
playBackgroundMusic("./data/Music_Title.mp3");
}
SnakeWindow::~SnakeWindow() {
if(m_game != nullptr)
delete m_game;
}
void SnakeWindow::handlePlayClicked(int level) {
m_game = new Game(level);
m_game->reloadGame();
PlayWindow *playWindow = new PlayWindow(m_game);
m_stackedWidget->addWidget(playWindow);
m_stackedWidget->setCurrentWidget(playWindow);
playWindow->reinit();
playWindow->update();
stopBackgroundMusic();
playBackgroundMusic("./data/Music_Game.mp3");
}
void SnakeWindow::handleExitClicked() {
QCoreApplication::quit();
}
void SnakeWindow::handleCreateMapClicked() {
m_game = new Game(1);
m_game->reloadGame();
EditorWindow *editorWindow = new EditorWindow(m_game);
m_stackedWidget->addWidget(editorWindow);
m_stackedWidget->setCurrentWidget(editorWindow);
editorWindow->reinit();
editorWindow->update();
stopBackgroundMusic();
playBackgroundMusic("./data/Music_Game.mp3");
}
void SnakeWindow::paintEvent(QPaintEvent *event) {
QMainWindow::paintEvent(event);
}