主要功能已完成
This commit is contained in:
+73
-34
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user