QT 翻金币游戏知识总结

本文总结了QT平台下翻金币游戏的开发技巧,包括窗口大小设置、事件处理、动画效果、音频播放、自定义按钮、界面切换、图片加载、字体设置以及游戏逻辑实现。通过QT的QPropertyAnimation、QSound、QTimer和信号槽机制,展示了如何创建游戏场景、响应用户交互并实现游戏规则。同时,详细解释了如何在二维网格中翻转金币,检查游戏胜利条件,并触发胜利动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

QT 翻金币游戏知识总结

 QT翻金币游戏的资料,下载于b站的黑马程序员QT课程,游戏目标为将金币都翻转为同一个颜色(金色)。

资料下载:https://pan.baidu.com/s/12AvEgy3kMORfM93QFA_PKg
提取码:1256

1void QWidget::setFixedSize(int w, int h)
Sets the width of the widget to w and the height to h.给定窗口固定的宽度和高度
  
2void QWidget::setFixedSize(const QSize &s)
Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking.
可以设置窗口最大与最小尺寸

3connect(ui->actionQuit,&QAction::triggered,[=](){
   this->close();});//此处首先省略了receiver: this,  [=](){this->close();} 用了lambda表达式实现槽函数,lambda表达式知识链接如下,http://c.biancheng.net/view/3741.html

4、MypushButton *startBtn =new MypushButton(":/res/MenuSceneStartButton.png",""); //给按钮添加图片

5、startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);//其将图片的左侧放置于this->width(),this->height()*0.7 位置,所以需要-startBtn->width()*0.5,才可把开始按钮放在中心
6、 QSound *startSound = new QSound(":/res/TapButtonSound.wav",this);
    startSound->play();
//添加及播放音频

7void MypushButton::zoom1()
{
   
  QPropertyAnimation *animation=new QPropertyAnimation(this,"geometry");
  animation->setDuration(200);
  animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
  animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
  animation->setEasingCurve(QEasingCurve::OutBounce);
  animation->start();
 } //动画
   
8QTimer::singleShot(500,this,[=]()   //延时500ms 调用槽函数 此处的槽函数使用lambda表达                                                 式。
        {
   
            this->hide();
            chooseScene->show();
        });


 9connect(chooseScene,&ChooseLevelSence::chooseSceneBack,[=](){
   
        this->show();
    });
signals:
        void chooseSceneBack();
       //自己定义一个信号 在适当的时机发射信号 发射调用emit函数

使用时:
    QTimer::singleShot(<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值