-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
145 lines (128 loc) · 3.77 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "easy_mode.h"
#include "medium_mode.h"
#include "jordan_mode.h"
#include "credits.h"
#include "win_screen.h"
/** MainWindow constructor
* @param parent which is an optional QWidget pointer
* @return void
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// set up the normal music
normal_music = new QMediaPlayer();
normal_music->setMedia(QUrl("qrc:/sounds/bensound-jazzyfrenchy.mp3"));
jordan_music = new QMediaPlayer();
jordan_music->setMedia(QUrl("qrc:/sounds/Space Jam Theme Song.mp3"));
}
/** MainWindow destructor
* @return void
*/
MainWindow::~MainWindow()
{
delete ui;
delete normal_music;
delete jordan_music;
}
/** start easy mode function
*
* Brief: builds an easy mode object and sets the mainwindow as its parent, also starts up music
*
* @param void
* @return void
*/
void MainWindow::start_easy_mode()
{
// first let's just get a dude on screen
easy_mode* e = new easy_mode(this); // set parent to be the main window
this->setCentralWidget(e);
// set up the music here!
normal_music->setPosition(0);
normal_music->play();
}
/** start medium mode function
*
* Brief: builds an medium mode object and sets the mainwindow as its parent, also starts up music
*
* @param void
* @return void
*/
void MainWindow::start_medium_mode()
{
// let's now create a medium mode
medium_mode* m = new medium_mode(this);
this->setCentralWidget(m);
// set up music here!
normal_music->setPosition(0);
normal_music->play();
}
/** start jordan mode function
*
* Brief: builds an jordan mode object and sets the mainwindow as its parent, also starts up music
*
* @param void
* @return void
*/
void MainWindow::start_jordan_mode()
{
// let's create a jordan mode
jordan_mode* j = new jordan_mode(this);
this->setCentralWidget(j);
// set up music here!
jordan_music->setPosition(15000);
jordan_music->play();
}
/** start credits function
*
* Brief: builds a credits object and sets the mainwindow as its parent
*
* @param void
* @return void
*/
void MainWindow::start_credits()
{
// opens the credits scene
credits* c = new credits(this);
this->setCentralWidget(c);
}
/** start win function
*
* Brief: Create a win screen and displays the player's points
*
* @param points_scored represents the number of points scored by the player
* @return void
*/
void MainWindow::start_win_screen()
{
// if the music is playing by the time a game is over
if(normal_music->state() == QMediaPlayer::PlayingState){
normal_music->setPosition(0);
normal_music->pause();
}
else if(jordan_music->state() == QMediaPlayer::PlayingState){
jordan_music->setPosition(15000);
jordan_music->pause();
}
QWidget* wid = this->centralWidget(); // now our main screen becomes the central widget again
wid->setParent(NULL); // we want the parent of this main window to be nothing!
win_screen* ws = new win_screen(this); // we then create a win screen
this->setCentralWidget(ws); // and make the wins screen our central widget
}
/** game over function
*
* Brief: destroys the current ui, then resets the main menu/window as the current ui.
*
* @param void
* @return void
*/
void MainWindow::game_over()
{
QWidget* wid = this->centralWidget(); // now our main screen becomes the central widget again
wid->setParent(NULL); // we want the parent of this main window to be nothing!
ui->setupUi(this); // now everything pops up from the desinger... designer... sorry...
}