-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
120 lines (101 loc) · 2.65 KB
/
Copy pathmainwindow.cpp
File metadata and controls
120 lines (101 loc) · 2.65 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include"gamecontroller.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),timer(new QTimer(this))
, ui(new Ui::MainWindow),controller(new GameController(this))
{
ui->setupUi(this);
setFixedSize(800,600);
player.setMedia(QUrl("qrc:/sounds/bgm"));
player.setVolume(10);
player.play();
ui->ResumeBtn->setVisible(false);
ui->PauseBtn->setVisible(false);
}
MainWindow::~MainWindow()
{
delete ui;
delete controller;
delete timer;
}
void MainWindow::paintEvent(QPaintEvent *event){
QPainter painter(this);
controller->paint(painter);
//qDebug()<<geometry().width()<<geometry().height();
}
void MainWindow::paintall(){
update();
}
void MainWindow::on_StartBtn_clicked()
{
timer->start(1000/33);
connect(timer,SIGNAL(timeout()),controller,SLOT(advance()));
connect(timer,SIGNAL(timeout()),this,SLOT(paintall()));
this->installEventFilter(controller);
hideall();
}
QPushButton* MainWindow::getStartBtn(){
return ui->StartBtn;
}
QTimer* MainWindow::getTimer(){
return timer;
}
QLabel* MainWindow::getScore(){
return ui->score_label;
}
QLabel* MainWindow::getHScore(){
return ui->hscore_label;
}
void MainWindow::on_PauseBtn_clicked()
{
controller->pause();
ui->ResumeBtn->setVisible(true);
}
void MainWindow::on_ResumeBtn_clicked()
{
connect(timer,SIGNAL(timeout()),controller,SLOT(advance()));
connect(timer,SIGNAL(timeout()),this,SLOT(paintall()));
this->installEventFilter(controller);
hideall();
}
void MainWindow::showall(){
ui->StartBtn->setVisible(true);
ui->mode1btn->setVisible(true);
ui->mode_label->setVisible(true);
ui->mode2btn->setVisible(true);
ui->PauseBtn->setVisible(false);
}
void MainWindow::hideall(){
ui->ResumeBtn->setVisible(false);
ui->mode1btn->setVisible(false);
ui->mode_label->setVisible(false);
ui->mode2btn->setVisible(false);
ui->StartBtn->setVisible(false);
ui->PauseBtn->setVisible(true);
}
void MainWindow::on_mode1btn_clicked()
{
if(controller->get_mode()!=DANCING){
controller->set_mode(DANCING);
ui->mode_label->setText("LET'S DANCING!");
}
else{
controller->set_mode(NORMAL);
ui->mode_label->setText("NORMAL MODE");
}
}
QPushButton* MainWindow::getResumeBtn(){
return ui->ResumeBtn;
}
void MainWindow::on_mode2btn_clicked()
{
if(controller->get_mode()!=WEIGHTLESS){
controller->set_mode(WEIGHTLESS);
ui->mode_label->setText("Wightless Now");
}else{
controller->set_mode(NORMAL);
ui->mode_label->setText("NORMAL MODE");
}
}