头文件
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTimer>
//#include<QPixmap>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
static int num;
static int getscore;
// QPixmap pix;
private:
Ui::Widget *ui;
QTimer* timer;
char arr[200][20] ={"化敌为友", "谢天谢地", "行尸走肉", "鸟语花香", "快马加鞭", "守门员", "鬼哭神嚎", "CD", "台球", "腰带", "长颈鹿", "吓一跳", "肌肉注射", "中暑", "比翼双飞", "摩托车", "唐僧", "自行车", "鼓", "保龄球", "电话", "守株待兔", "鸡飞狗跳", "宋丹丹", "饼干", "画龙点睛", "亡羊补牢", "寒战", "唉声叹气", "手舞足蹈", "开瓶器", "一叶知秋", "井底之蛙", "跳水", "钻戒", "一刀两断", "电视", "锄头", "高尔夫", "手表", "两小无猜", "耳机", "洗", "耳环", "见钱眼开", "汽车", "手机", "杯子", "风扇", "香烟", "电视机", "篮球", "猩猩", "书包", "打嗝", "啤酒肚", "鼠标", "害羞", "母鸡", "后裔", "孙尚香", "赵云", "王昭君", "李白", "貂蝉", "挖鼻孔", "翻白眼", "拒绝", "微笑", "祈祷", "抓耳挠腮", "游泳", "打篮球", "刷牙", "握手", "洗脸", "兔子", "大梦初醒", "至死不渝", "情比金坚", "刻舟求剑", "白兔", "猪", "吃饭", "骑车", "读书", "写字", "喝水", "狗狗", "逛街", "拍照", "跳绳", "飞翔", "爬山", "鼓掌", "生气", "潜水", "跳伞", "冲浪", "溜冰", "划船", "攀岩", "蹦极", "跳远", "举重", "拳击", "田径", "跨栏", "排球", "乒乓", "网球", "棒球", "书法", "围棋", "象棋", "斗地主", "打麻将", "踢足球", "打网球", "吃零食", "喝咖啡", "听音乐", "做家务", "背单词", "看小说", "坐飞机", "坐轮船", "骑单车", "打太极", "练气功", "打羽毛球", "踢毽子", "练舞蹈"};
public slots:
void startTimer();
void settimertext();
void startgame();
void right();
void wrong();
};
#endif // WIDGET_H
修改的
源文件
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QString>
int Widget::num = 1;
int Widget:: getscore = 0;
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->r->show();
ui->w->show();
connect(ui->btn,&QPushButton::clicked,this,&Widget::startTimer);
connect(ui->btn,&QPushButton::clicked,this,&Widget::startgame);
connect(ui->r,&QPushButton::clicked,this,&Widget::right);
connect(ui->w,&QPushButton::clicked,this,&Widget::wrong);
}
Widget::~Widget()
{
delete ui;
}
void Widget::startTimer()
{
timer = new QTimer(this);
connect(timer,&QTimer::timeout,this,&Widget::settimertext);
timer->start(1000);
}
void Widget::settimertext()
{
static int num = 300;
num--;
if(num <= 0)
{
timer->stop();
}
ui->time->setText(QString::number(num));
}
void Widget::startgame()
{
ui->btn->hide();
ui->r->show();
ui->w->show();
ui->label2->setText(arr[0]);
}
void Widget::right()
{
ui->ti->setText(QString::number(num));
if(num < 200)
{
ui->label2->setText(arr[num]);
}
else
{
num=0;
}
num++;
getscore++;
ui->score->setText(QString::number(getscore));
}
void Widget::wrong()
{
ui->ti->setText(QString::number(num));
if(num < 200)
{
ui->label2->setText(arr[num]);
}
else
{
num=0;
}
ui->score->setText(QString::number(getscore));
num++;
}
修改的
界面文件
widget.ui
资源