围住神经猫源码分享

本文分享了一款使用Qt技术实现的围住神经猫游戏的源码,涉及QML、QtQuick和RestartHandler类。游戏包含主界面、开始页、游戏界面和结束面板,使用QProcess实现游戏重启,QML组件定义了猫的行为和玩家操作的圆,通过计算猫的运动方向判断游戏状态。
摘要由CSDN通过智能技术生成
//restarthandler.h:
#ifndef RESTARTHANDLER_H
#define RESTARTHANDLER_H
 
#include <QObject>
 
class RestartHandler : public QObject
{
 
    Q_OBJECT
public:
    explicit RestartHandler(QObject *parent = 0);
    Q_INVOKABLE void restart();
 
signals:
 
public slots:
 
};
 
#endif // RESTARTHANDLER_H
/**********************************************************************************************************************************/
//restarthandler.cpp
#include "restarthandler.h"
#include <QCoreApplication>
RestartHandler::RestartHandler(QObject *parent) :
    QObject(parent)
{
   
}
void RestartHandler::restart()
{
   
    QCoreApplication::instance()->exit(773);
}
/********************************************************************************************************************************/

//main.cpp
#include <QGuiApplication>
#include <QProcess>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include "restarthandler.h"
int main(int argc, char *argv[])
{
   
    QGuiApplication app(argc, argv);
    qmlRegisterType<RestartHandler>("RestartHandler", 1, 0, "RestartHandler");
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
    int ret = app.exec();
    if (ret == 773) {
   
        QProcess::startDetached(qApp->applicationFilePath(), QStringList());
        return 0;
    }
    return ret;
}
/********************************************************************************************************************************/
//Round.qml
import QtQuick 2.0
Rectangle {
  
    id: round
    height: 40
    width:  height
    radius: height / 2
    color: active === true ? 'orangered' : 'lightgrey'
    property int index
    property bool active: Math.random() * 100 < 10 ? true : false
    signal clicked
    MouseArea {
  
        anchors.fill: parent
        onClicked: {
  
            round.active = true;
            round.clicked();
        }
    }
}
/*******************************************************************************************************************************/
//startPage.qml
import QtQuick 2.0
Image {
  
    id: container
    source: "qrc:///images/btn_start.png"
    width: 480
    height: 640
    signal start;
    MouseArea {
  
        width: container.width / 2
        height: container.height / 5
        <
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值