Skip to content
This repository has been archived by the owner on Apr 10, 2022. It is now read-only.

Commit

Permalink
V2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BackMountainDevil authored Mar 13, 2020
1 parent 28c1b5e commit 56f9bfc
Show file tree
Hide file tree
Showing 39 changed files with 1,661 additions and 0 deletions.
44 changes: 44 additions & 0 deletions source/9-CoinFlip V2.1/9-CoinFlip.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
QT += core gui multimedia

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
chooselevelscene.cpp \
dataconfig.cpp \
main.cpp \
mainscene.cpp \
mycoin.cpp \
mypushbutton.cpp \
playscene.cpp

HEADERS += \
chooselevelscene.h \
dataconfig.h \
mainscene.h \
mycoin.h \
mypushbutton.h \
playscene.h

FORMS += \
mainscene.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
res.qrc
319 changes: 319 additions & 0 deletions source/9-CoinFlip V2.1/9-CoinFlip.pro.user

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions source/9-CoinFlip V2.1/chooselevelscene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "chooselevelscene.h"
#include <QSound>
#include <QMenuBar>
#include <QPainter>
#include "mypushbutton.h"
#include <QDebug>
#include <QTimer>
#include <QLabel>

ChooseLevelScene::ChooseLevelScene(QWidget *parent) : QMainWindow(parent)
{
//配置选择关卡场景
this->setFixedSize(320,588);

//设置图标
this->setWindowIcon(QPixmap(":/res/Coin0001.png"));

//设置标题
//this->setWindowTitle("选择关卡场景");
this->setWindowTitle("金币连连看");
//创建菜单栏
QMenuBar * bar = menuBar();
setMenuBar(bar);

//创建开始菜单
QMenu * startMenu = bar->addMenu("开始");

//创建退出 菜单项
QAction * quitAction = startMenu->addAction("退出");

//点击退出 实现退出游戏
connect(quitAction,&QAction::triggered,[=](){
this->close();
});
QSound *chooseSound = new QSound(":/res/TapButtonSound.wav",this);
QSound *backSound = new QSound(":/res/BackButtonSound.wav",this);
//返回按钮
MyPushButton * backBtn = new MyPushButton(":/res/BackButton.png" , ":/res/BackButtonSelected.png");
backBtn->setParent(this);
backBtn->move(this->width() - backBtn->width() , this->height() - backBtn->height());

//点击返回
connect(backBtn,&MyPushButton::clicked,[=](){
//qDebug() << "点击了返回按钮";
//告诉主场景 我返回了,主场景监听ChooseLevelScene的返回按钮
//延时返回
backSound->play();
QTimer::singleShot(500,this,[=](){
emit this->chooseSceneBack();
});

});

//创建选择关卡的按钮
for( int i = 0 ; i < 20 ;i ++)
{
MyPushButton * menuBtn = new MyPushButton(":/res/LevelIcon.png");
menuBtn->setParent(this);
menuBtn->move( 25 + i%4 * 70 , 130 + i/4 * 70 );

//监听每个按钮的点击事件
connect(menuBtn,&MyPushButton::clicked,[=](){
chooseSound->play();
QString str = QString("您选择的是第 %1 关 ").arg( i + 1);
qDebug() <<str;

//进入到游戏场景
this->hide(); //将选关场景隐藏掉
play = new PlayScene(i+1); //创建游戏场景
play->setGeometry(this->geometry());
play->show();//显示游戏场景

connect(play,&PlayScene::chooseSceneBack,[=](){
this->setGeometry(play->geometry());
this->show();
delete play;
play = NULL;
qDebug("Back Test from chooselevelscene") ;
});

});

QLabel * label = new QLabel;
label->setParent(this);
label->setFixedSize(menuBtn->width(),menuBtn->height());
label->setText(QString::number(i+1));
label->move(25 + i%4 * 70 , 130 + i/4 * 70 );

//设置 label上的文字对齐方式 水平居中和 垂直居中
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
//设置让鼠标进行穿透 51号属性
label->setAttribute(Qt::WA_TransparentForMouseEvents);
}


}

void ChooseLevelScene::paintEvent(QPaintEvent *)
{
//加载背景
QPainter painter(this);
QPixmap pix;
pix.load(":/res/OtherSceneBg.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);

//加载标题
pix.load(":/res/Title.png");
painter.drawPixmap( (this->width() - pix.width())*0.5,30,pix.width(),pix.height(),pix);
}
23 changes: 23 additions & 0 deletions source/9-CoinFlip V2.1/chooselevelscene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef CHOOSELEVELSCENE_H
#define CHOOSELEVELSCENE_H

#include <QMainWindow>
#include "playscene.h"
class ChooseLevelScene : public QMainWindow
{
Q_OBJECT
public:
explicit ChooseLevelScene(QWidget *parent = nullptr);
//重写绘图事件
void paintEvent(QPaintEvent *);

//游戏场景对象指针
PlayScene * play = NULL;

signals:
//写一个自定义信号,告诉主场景 点击了返回
void chooseSceneBack();

};

#endif // CHOOSELEVELSCENE_H
Loading

0 comments on commit 56f9bfc

Please sign in to comment.