出现了bug

This commit is contained in:
2021-02-09 00:40:12 +08:00
parent bc931112fc
commit 633cbc0428
7 changed files with 53 additions and 10 deletions
+5 -2
View File
@@ -9,6 +9,7 @@
extern care car[5][5];
extern struct touch t;
Widget::Widget(QWidget *parent)
: QWidget(parent)
@@ -75,7 +76,7 @@ void Widget::paintEvent(QPaintEvent *)
#define car_size 110
for(int y=0;y<5;y++)
{
for(int x=0;x<5;x++)
@@ -101,7 +102,9 @@ void Widget::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton)
{
qDebug() << event->x();
t.flag=1;
t.x=event->x();
t.y=event->y();
}
+38 -8
View File
@@ -1,15 +1,16 @@
#include "workthread.h"
#include <time.h>
#include <QDebug>
care car[5][5];
int car_rand_buff[26];
int car_rand_int=0;
int car_rand=0;
int while_buff=0;
struct touch t;
void WorkThread::run()
void car_init()
{
srand(time(NULL));
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++)
@@ -35,8 +36,37 @@ void WorkThread::run()
}
}
while (true)
}
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();
}
+10
View File
@@ -4,6 +4,8 @@
#include <QWidget>
#include <QThread>
#define car_size 110
class WorkThread : public QThread
{
@@ -21,4 +23,12 @@ struct care
};
struct touch
{
char flag;
int y;
int x;
};
#endif // WORKTHREAD_H