#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);
}
|