forked from yangsheng6810/pvz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
91 lines (74 loc) · 2.39 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
#include <QtGui>
#include "mainwindow.h"
#include "plant.h"
#include "sunflower.h"
#include "backgroundmusic.h"
#include "sunlight.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
createActions();
createMenus();
QPushButton *quit = new QPushButton(tr("Quit"));
connect(quit, SIGNAL(clicked()), this, SLOT(close()));
SunLight *sun = new SunLight();
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(quit);
layout->addWidget(sun);
QGridLayout *grid = new QGridLayout;
layout->addLayout(grid);
Plant *pea = new Plant();
grid->addWidget(pea,0,0);
pea = new Plant();
grid->addWidget(pea,1,0);
Plant *flower = new SunFlower();
grid->addWidget(flower,0,1);
connect(flower,SIGNAL(produceSunLight(int)),sun,SLOT(addSunLight(int)));
flower = new SunFlower();
grid->addWidget(flower,1,1);
connect(flower,SIGNAL(produceSunLight(int)),sun,SLOT(addSunLight(int)));
QWidget *widget = new QWidget;
widget->setLayout(layout);
widget->show();
setWindowTitle(QObject::tr("Plant VS Zombies"));
setCentralWidget(widget);
BackgroundMusic *music = new BackgroundMusic;
music->startPlaying();
}
MainWindow::~MainWindow()
{
//delete ui;
}
void MainWindow::createMenus()
{
gameMenu = menuBar()->addMenu(tr("&Game"));
gameMenu->addAction(newGameAct);
gameMenu->addSeparator();
gameMenu->addAction(exitAct);
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAct);
}
void MainWindow::createActions()
{
newGameAct = new QAction(tr("&New"),this);
newGameAct->setShortcut(tr("Ctrl+N"));
connect(newGameAct, SIGNAL(triggered()), this, SLOT(newGame()));
exitAct = new QAction(tr("E&xit"),this);
exitAct->setShortcut(tr("Ctrl+g"));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
aboutAct = new QAction(tr("&About"), this);
aboutAct->setStatusTip(tr("Show the application's About box"));
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
}
void MainWindow::about()
{
QMessageBox::about(this, tr("About Application"),
tr("The <b>PVZ</b> was written by"
"Yang Sheng <[email protected]>"
" and "
" as a homework"));
}
void MainWindow::newGame()
{
QMessageBox::information(this, tr("Not implemented!"),tr("This function hasn't been implemented!"));
}