Chinaunix首页 | 论坛 | 博客
  • 博客访问: 366319
  • 博文数量: 36
  • 博客积分: 2071
  • 博客等级: 大尉
  • 技术积分: 797
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-20 12:08
文章分类
文章存档

2011年(2)

2010年(34)

我的朋友

分类: C/C++

2010-11-23 22:40:45

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
    class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
     int getNum();
     int count;
     int s;
     int cnum;
     int level;
private:
    Ui::Widget *ui;

private slots:
    void on_pushButton_13_clicked();
    void on_pushButton_clicked();
    void on_pushButton_10_clicked();
    void on_pushButton_12_clicked();
    void input();
    void on_pushButton_11_clicked();
};

#endif // WIDGET_H

 

#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QTime>
#include <QMessageBox>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    count = 0;
    s = 0;
    cnum = 0;
    level = 0;
    ui->setupUi(this);
    connect(ui->pushButton_0,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_1,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(input()));
    connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(input()));
}

Widget::~Widget()
{
    delete ui;
}
int Widget::getNum()
{
    int rand = 0;
    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    rand = qrand()%10000;
    return rand;
}
void Widget::input()
{
    count++;
    QString name = this->sender()->objectName();
    qDebug()<<"name = "<<name;
    int num = QString(name.at(11)).toInt();
    ui->label->setText(name+"; num = "+QString::number(num));
    if (1 == count)
    {
        cnum = 1*num;
    }
    if (2 == count)
    {
        cnum = 10*cnum+num;
    }
    if (3 == count)
    {
        cnum = 10*cnum+num;
        ui->lcdNumber->display(cnum);
    }
    if (4 == count)
    {
        cnum = 10*cnum+num;
        count = 0;
    }
    qDebug()<<"count="<<count;
    ui->lcdNumber->display(cnum);
        ui->label->setText(QString::number(cnum));

}
void Widget::on_pushButton_11_clicked()//开始按钮

{
       s = Widget::getNum();
       qDebug()<<s;
       ui->pushButton_10->setEnabled(true);
       ui->pushButton_11->setEnabled(false);
       ui->widget->setEnabled(true);
}

void Widget::on_pushButton_12_clicked()//关闭按钮

{
   this->close();
}

void Widget::on_pushButton_10_clicked()//确定按钮

{
    level++;
    ui->textEdit->clear();
    ui->pushButton_11->setEnabled(true);

    if(cnum == s)
    {
        cnum = 0;

        if(level < 5)
        {
            QMessageBox::information(this,"my infor","you win Game over");
            ui->textEdit->setText("choose level1 You win GAME");
        }
        if(level < 15)
        {
            QMessageBox::information(this,"my infor","you win Game over");
            ui->textEdit->setText("Plese choose level2 You win GAME");
        }
        if(level < 10)
        {
            QMessageBox::information(this,"my infor","you win Game over");
            ui->textEdit->setText("Plese choose level3 You win GAME");
        }
    }
   int anum[4];
    int snum[4];
    char buf[4][10]={"thousand","hundred","ten","one"};
    anum[0] = cnum/1000; snum[0] = s/1000;
    anum[1] = ((cnum/100)%10); snum[1] = ((s/100)%10);
    anum[2] = ((cnum/10)%10); snum[2] = ((s/10)%10);
    anum[3] = ((cnum)%10); snum[3] = ((s)%10);
    int i;
    for( i=0; i<4; i++)
    {
        if(anum[i] < snum[i])
        {
            qDebug()<<"in if < "<<i<<anum[i]<<snum[i];
            ui->textEdit->insertPlainText(QString(buf[i])+"little\n");
           // ui->textEdit->insertPlainText(" little\n");

        }
        if(anum[i] == snum[i])
        {
            ui->textEdit->insertPlainText(buf[i]);
            ui->textEdit->insertPlainText(" equal\n");
        }
        if(anum[i] > snum[i])
        {
            ui->textEdit->insertPlainText(buf[i]);
            ui->textEdit->insertPlainText(" big\n");
        }
    }

    cnum = 0;

    ui->lcdNumber->display(cnum);

}

void Widget::on_pushButton_clicked()
{
    QMessageBox::information(this,"my infor",QString::number(s));
}

void Widget::on_pushButton_13_clicked()
{
    cnum = 0;
    count = 0;

    ui->lcdNumber->display(cnum);

}


#include <QtGui/QApplication>
#include "widget.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
}


阅读(2616) | 评论(0) | 转发(0) |
0

上一篇:Qt信号与槽

下一篇:SOCKET编程

给主人留下些什么吧!~~