-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
113 lines (92 loc) · 3.32 KB
/
Copy pathMainWindow.cpp
File metadata and controls
113 lines (92 loc) · 3.32 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
#include "InstructionWindow.h"
#include "MainWindow.h"
#include "GameType.h"
#include "BackgroundMusic.h"
#include <QLabel>
#include <QVBoxLayout>
BackgroundMusic* musicPlayer;
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{
// Initialize music player
musicPlayer = new BackgroundMusic(0);
musicPlayer->moveToThread(musicPlayer);
musicPlayer->start();
// Add title
QLabel* mainTitle = new QLabel("Gravity Flip", this);
QFont f("Arial", 32, QFont::Bold);
mainTitle->setStyleSheet("QLabel {color : white;}");
mainTitle->setFont(f);
mainTitle->setGeometry(380, 50, 350, 50);
// Widget to add buttons
QWidget* wid = new QWidget(this);
// Set wid as the central widget of MainWindow
this->setCentralWidget(wid);
// Create a vertical layout for buttons
QVBoxLayout* layout = new QVBoxLayout();
// Create the required buttons
m_singlePlayer = new CustomButton("Single Player");
m_multiPlayer = new CustomButton("Multi Player");
m_exitGame = new CustomButton("Exit");
// Add buttons to layout
layout->addWidget(m_singlePlayer);
layout->addWidget(m_multiPlayer);
layout->addWidget(m_exitGame);
// Set alignment and spacing of layout
layout->setAlignment(Qt::AlignCenter);
layout->setSpacing(50);
// Set size of buttons
m_singlePlayer->setFixedSize(QSize(200,50));
m_multiPlayer->setFixedSize(QSize(200,50));
m_exitGame->setFixedSize(QSize(200,50));
// Set the layout of the central widget
wid->setLayout(layout);
// Connect the buttons to the appropriate slots
connect(m_singlePlayer,SIGNAL(pressed()),m_singlePlayer,SLOT(changeColor()));
connect(m_multiPlayer,SIGNAL(pressed()),m_multiPlayer,SLOT(changeColor()));
connect(m_exitGame,SIGNAL(pressed()),m_exitGame,SLOT(changeColor()));
connect(m_singlePlayer, SIGNAL(released()), this, SLOT(handleSinglePlayer()));
connect(m_multiPlayer, SIGNAL(released()), this, SLOT(handleMultiPlayer()));
connect(m_exitGame, SIGNAL(released()), this, SLOT(handleExitGame()));
}
void MainWindow::display()
{
// Set palette of MainWindow
QPalette palette;
palette.setBrush(QPalette::Button,Qt::gray);
palette.setBrush(QPalette::Background, QBrush(QImage(":/res/objects/bgrocks.png").scaled(1000,500)));
this->setPalette(palette);
// Resize and show MainWindow
this->resize(1000, 500);
this->setFixedSize(width(), height());
this->move(0, 0);
this->show();
}
void MainWindow::handleSinglePlayer()
{
// Disconnect all button signals
m_singlePlayer->disconnect();
m_multiPlayer->disconnect();
m_exitGame->disconnect();
// Close the main window
this->close();
// Create a new window for instructions
InstructionWindow *instructionWindow = new InstructionWindow(GameType::SINGLEPLAYER, this);
instructionWindow->display();
}
void MainWindow::handleMultiPlayer()
{
// Disconnect all button signals
m_singlePlayer->disconnect();
m_multiPlayer->disconnect();
m_exitGame->disconnect();
// Close the main window
this->close();
// Create a new window for instructions
InstructionWindow *instructionWindow = new InstructionWindow(GameType::MULTIPLAYER, this);
instructionWindow->display();
}
void MainWindow::handleExitGame()
{
// Close the main window
this->close();
}