如何用QT做消消乐游戏(简单版羊了个羊)

        基于Qt的widget界面开发的图形消除单机游戏,在规定区域 内从 6 张基础图片中随机选中生成一组若干张 图片(有序堆叠),从表面选中图片到等待区,3 张相同即可消除,若等待区装满 7 张图片即输掉 游戏,全部消除即可通关并积分累加。 使用技术: 使用了 QT 图形界面设计工具; 重写 QT 事件处理函数等。

        图形和背景音乐自选。 

QT       += core gui
QT       += 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 += \
    main.cpp \
    mylabel.cpp \
    widget.cpp

HEADERS += \
    mylabel.h \
    widget.h

FORMS += \
    widget.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 += \
    music.qrc \
    rs.qrc \
    rsback.qrc

 以下是mylabel.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include "mylabel.h"
#include <QMediaPlayer>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    void mouseReleaseEvent(QMouseEvent *event);   //松开鼠标

public slots:
    void pButSlotFun();
    void pBut_2SlotFun();
    void positionChanged(qint64);

private:
    Ui::Widget *ui;
    myLabel  *pMyLabel[50];        //*pMyLabel, *pMyLabel_2, *pMyLabel_3, *pMyLabel_4, *pMyLabel_5, *pMyLabel_6;
    int win;
    int integralVal;
    QMediaPlayer *player;
    QUrl playerQurl;
};
#endif // WIDGET_H

 以下是widget.h

#ifndef MYLABEL_H
#define MYLABEL_H

#include <QMouseEvent>
#include <QLabel>

class myLabel :public QLabel
{
public:
    myLabel(QWidget *parent);
    ~myLabel();


    //重写 父类的 事件处理函数
    void mousePressEvent(QMouseEvent *event);  //按压鼠标
    //void mouseReleaseEvent(QMouseEvent *event);   //松开鼠标
    //void mouseDoubleClickEvent(QMouseEvent *event);    //双击
    void mouseMoveEvent(QMouseEvent *event);    //鼠标移动

    //void wheelEvent(QWheelEvent *event);        //滚轮滑动

    //void keyPressEvent(QKeyEvent *event);       //键盘按下
    //void keyReleaseEvent(QKeyEvent *event);   //键盘松开

    //void enterEvent(QEvent *event);         //鼠标进入
   // void leaveEvent(QEvent *event);         //鼠标离开

    int mouseX,mouseY,can,val,blankval;//鼠标在窗口的坐标X、Y;入框锁定;显示出来的图片对应的编号;入框图片的编号
    static QString pictureName[100];//装图片地址--字符串
    static int pictureVal[100];//使用了的图片地址编号
    static int pictureNum[6];//每种图片计数
    static int picture[100];//同一图片入框数量
    static int blank[8];//框内装图标的图片地址
    static int vali,blanki;//显示出来的图片数量,实际装入框的数量
};

#endif // MYLABEL_H

 以下是mylabel.cpp

#include "mylabel.h"
#include <QDebug>
#include <QMouseEvent>
#include <QMessageBox>


myLabel::myLabel(QWidget 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值