/bike.h |
---|
9,10 → 9,13 |
#include <QHostAddress> |
#include <QThread> |
#include <cmath> |
#include <time.h> |
#include <stdio.h> |
#include <pthread.h> |
using namespace std; |
class Bike : public QThread |
class Bike : public QObject |
{ |
Q_OBJECT |
19,7 → 22,7 |
public: |
Bike(QTcpSocket *sock, int i); |
void draw(QPainter *painter,QList<Bike *> bikes); |
void run(QList<Bike *> bikes); |
void run(); |
bool hasCollided(QList<Bike *> bikes); |
void setText(QString text); |
void reset(); |
35,6 → 38,7 |
int id; |
bool isDisconnected; |
bool hasHadGo; |
QList<Bike *> bikes; |
QColor colour; |
bool collided; |
float abpool; |
/mainwindow.h |
---|
8,6 → 8,7 |
#include <QTimer> |
#include <QGLWidget> |
#include "bike.h" |
class MainWindow : public QGLWidget |
/main.cpp |
---|
7,4 → 7,5 |
MainWindow w; |
w.show(); |
return a.exec(); |
pthread_exit(NULL); |
} |
/bike.cpp |
---|
103,7 → 103,7 |
} |
} |
void Bike::run(QList<Bike *> bikes) |
void Bike::run() |
{ |
for (int i = 0; i < bikes.count(); i++) |
{ |
163,6 → 163,10 |
} |
} |
hasHadGo = true; |
time_t result = time(NULL); |
cout << result << ": Recieved next move from " << name.toStdString().c_str() << endl; |
pthread_exit(NULL); |
} |
int sign(int x){ |
/mainwindow.cpp |
---|
37,6 → 37,12 |
} |
} |
void *runtherun(void *bike){ |
Bike *realbike = (Bike *)bike; |
realbike->run(); |
pthread_exit(NULL); |
} |
void MainWindow::paintEvent(QPaintEvent *e) |
{ |
if (suddenDeath) |
43,7 → 49,7 |
{ |
for (int i = 0; i < bikes.count(); i++) |
{ |
bikes[i]->speed += 0.02; |
bikes[i]->speed *= 1.01; |
} |
} |
63,12 → 69,15 |
if (ready) |
{ |
cout << ":: Sent move request..." << endl; |
pthread_t threads[bikes.count()]; |
for (int i = 0; i < bikes.count(); i++) |
{ |
if (bikes[i]->show) |
{ |
bikes[i]->hasHadGo = false; |
bikes[i]->run(bikes); |
bikes[i]->bikes = bikes; |
pthread_create(&threads[i],NULL,runtherun,(void *)bikes[i]); |
} |
} |
Bike *bike; |