主要功能已完成

This commit is contained in:
2021-02-09 01:10:53 +08:00
parent 633cbc0428
commit 36cc78b047
13 changed files with 160 additions and 387 deletions
+2 -4
View File
@@ -17,12 +17,10 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
widget.cpp \
workthread.cpp
widget.cpp
HEADERS += \
widget.h \
workthread.h
widget.h
FORMS += \
widget.ui
+73 -34
View File
@@ -5,35 +5,62 @@
#include <QBrush>
#include <QTimer>
#include <QDebug>
#include "WorkThread.h"
extern care car[5][5];
extern struct touch t;
care car[5][5];
int car_num=0;
void car_init()
{
int car_rand_buff[26];
int car_rand_int=0;
int car_rand=0;
int while_buff=0;
car_num=0;
for(int y=0;y<5;y++)
{
for(int x=0;x<5;x++)
{
do
{
while_buff=0;
car_rand=(rand()%25)+1;
for(int z=0;z<car_rand_int;z++)
{
if(car_rand_buff[z]==car_rand)
{
while_buff=1;
}
}
}while(while_buff);
car[y][x].num=car_rand;
car[y][x].color=0xffffff;
car_rand_buff[car_rand_int]=car_rand;
car_rand_int++;
}
}
}
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
QTimer *mainrun;
//QTimer *mainrun;
srand(time(NULL));
car_init();
for(int y=0;y<10;y++)
{
for(int x=0;x<10;x++)
{
car[y][x].color=0xffffff;
car[y][x].num=0;
}
}
/*
mainrun = new QTimer(this);
connect(mainrun,&QTimer::timeout,this,&Widget::mainrun_timeout);
mainrun->start(1);
WorkThread *workthread = new WorkThread;
workthread->start();
*/
}
Widget::~Widget()
@@ -44,8 +71,6 @@ Widget::~Widget()
void Widget::paintEvent(QPaintEvent *)
{
//QPainter p(this); //方法1 创建画家对象 并指定绘图设备
/*
*方法2 创建画家对象
*通过bggin指定绘图设备
@@ -60,23 +85,11 @@ void Widget::paintEvent(QPaintEvent *)
//定义画笔
QPen pen;
QBrush brush;//创建笔刷
pen.setWidth(1);//设置线宽
pen.setColor(QColor(28,28,28)); //常用颜色
pen.setStyle(Qt::SolidLine); //设置风格
p.setPen(pen); //将画笔给画家
brush.setStyle(Qt::SolidPattern);//设定笔刷样式
for(int y=0;y<5;y++)
{
for(int x=0;x<5;x++)
@@ -100,17 +113,43 @@ void Widget::paintEvent(QPaintEvent *)
void Widget::mousePressEvent(QMouseEvent *event)
{
int y,x;
if (event->button() == Qt::LeftButton)
{
t.flag=1;
t.x=event->x();
t.y=event->y();
if(event->x()>car_size*5||event->y()>car_size*5)
{
}else
{
y=(event->y()/car_size);
x=(event->x()/car_size);
if(car[y][x].num==car_num+1)
{
car[y][x].color=0x00db00;
car_num++;
}else
{
if(car[y][x].color==0xffffff)
{
car[y][x].color=0xea0000;
}
}
}
}
Widget::update();
}
void Widget::mainrun_timeout()
{
//Widget::update();
}
void Widget::on_pushButton_clicked()
{
car_init();
Widget::update();
}
+14 -1
View File
@@ -6,7 +6,7 @@
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
#define car_size 110
class Widget : public QWidget
{
Q_OBJECT
@@ -21,7 +21,20 @@ protected:
//绘图事件内部会自动调用,窗口需要重绘的时候(状态改变)
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *event);//------------------鼠标按下事件
private slots:
void on_pushButton_clicked();
private:
Ui::Widget *ui;
};
//****************************************************c
struct care
{
int num;
long color;
};
#endif // WIDGET_H
+13
View File
@@ -13,6 +13,19 @@
<property name="windowTitle">
<string>Widget</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>584</x>
<y>40</y>
<width>181</width>
<height>121</height>
</rect>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
-72
View File
@@ -1,72 +0,0 @@
#include "workthread.h"
#include <time.h>
#include <QDebug>
care car[5][5];
struct touch t;
void car_init()
{
int car_rand_buff[26];
int car_rand_int=0;
int car_rand=0;
int while_buff=0;
for(int y=0;y<5;y++)
{
for(int x=0;x<5;x++)
{
do
{
while_buff=0;
car_rand=(rand()%25)+1;
for(int z=0;z<car_rand_int;z++)
{
if(car_rand_buff[z]==car_rand)
{
while_buff=1;
}
}
}while(while_buff);
car[y][x].num=car_rand;
car_rand_buff[car_rand_int]=car_rand;
car_rand_int++;
}
}
}
int chack_car(int y,int x)
{
int a,b,c=0;
a=(x/car_size);
b=((y/car_size)*5);
c=a+b+1;
return c;
}
void w()
{
int t_car_flag=0;
srand(time(NULL));
car_init();
while(1)
{
if(t.flag)
{
t.flag=0;
t_car_flag=chack_car(t.y,t.x);
qDebug()<<t.y<<" "<<t.x<<" "<<t_car_flag;
}else{t_car_flag=0;}
}
}
void WorkThread::run()
{
w();
}
-34
View File
@@ -1,34 +0,0 @@
#ifndef WORKTHREAD_H
#define WORKTHREAD_H
#include <QWidget>
#include <QThread>
#define car_size 110
class WorkThread : public QThread
{
protected:
void run();
};
//****************************************************c
struct care
{
int num;
long color;
};
struct touch
{
char flag;
int y;
int x;
};
#endif // WORKTHREAD_H
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_Widget_t {
QByteArrayData data[1];
char stringdata0[7];
QByteArrayData data[3];
char stringdata0[30];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@@ -32,10 +32,12 @@ struct qt_meta_stringdata_Widget_t {
)
static const qt_meta_stringdata_Widget_t qt_meta_stringdata_Widget = {
{
QT_MOC_LITERAL(0, 0, 6) // "Widget"
QT_MOC_LITERAL(0, 0, 6), // "Widget"
QT_MOC_LITERAL(1, 7, 21), // "on_pushButton_clicked"
QT_MOC_LITERAL(2, 29, 0) // ""
},
"Widget"
"Widget\0on_pushButton_clicked\0"
};
#undef QT_MOC_LITERAL
@@ -45,21 +47,32 @@ static const uint qt_meta_data_Widget[] = {
8, // revision
0, // classname
0, 0, // classinfo
0, 0, // methods
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 0, 19, 2, 0x08 /* Private */,
// slots: parameters
QMetaType::Void,
0 // eod
};
void Widget::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
Q_UNUSED(_o);
Q_UNUSED(_id);
Q_UNUSED(_c);
if (_c == QMetaObject::InvokeMetaMethod) {
auto *_t = static_cast<Widget *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->on_pushButton_clicked(); break;
default: ;
}
}
Q_UNUSED(_a);
}
@@ -89,6 +102,17 @@ void *Widget::qt_metacast(const char *_clname)
int Widget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
}
return _id;
}
QT_WARNING_POP
@@ -11,6 +11,7 @@
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
@@ -18,12 +19,16 @@ QT_BEGIN_NAMESPACE
class Ui_Widget
{
public:
QPushButton *pushButton;
void setupUi(QWidget *Widget)
{
if (Widget->objectName().isEmpty())
Widget->setObjectName(QString::fromUtf8("Widget"));
Widget->resize(800, 600);
pushButton = new QPushButton(Widget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(584, 40, 181, 121));
retranslateUi(Widget);
@@ -33,6 +38,7 @@ public:
void retranslateUi(QWidget *Widget)
{
Widget->setWindowTitle(QCoreApplication::translate("Widget", "Widget", nullptr));
pushButton->setText(QCoreApplication::translate("Widget", "Reset", nullptr));
} // retranslateUi
};