/bike.h |
---|
9,6 → 9,8 |
#include <QHostAddress> |
#include <QThread> |
#include <cmath> |
#include <time.h> |
#include <stdio.h> |
using namespace std; |
19,7 → 21,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,13 → 37,15 |
int id; |
bool isDisconnected; |
bool hasHadGo; |
QList<Bike *> bikes; |
QColor colour; |
bool collided; |
float abpool; |
float velocity; |
float speed; |
private: |
QTcpSocket *socket; |
float velocity; |
private slots: |
void readyRead(); |
/bike.cpp |
---|
23,6 → 23,7 |
hadGo = false; |
dead = false; |
collided = false; |
speed = 5; |
colour.setBlue(0); |
colour.setRed(0); |
102,7 → 103,7 |
} |
} |
void Bike::run(QList<Bike *> bikes) |
void Bike::run() |
{ |
for (int i = 0; i < bikes.count(); i++) |
{ |
162,6 → 163,9 |
} |
} |
hasHadGo = true; |
time_t result = time(NULL); |
cout << result << ": Recieved next move from " << name.toStdString().c_str() << endl; |
} |
int sign(int x){ |
270,6 → 274,7 |
hadGo = false; |
dead = false; |
collided = false; |
speed = 5; |
socket->write("RESET\n"); |
} |
293,12 → 298,12 |
{ |
angle += 360; |
} |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |
315,12 → 320,12 |
{ |
angle += 360; |
} |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |
329,14 → 334,14 |
{ |
if(abpool > 0){ |
velocity += 0.1; |
abpool -= 0.5; |
abpool -= 0.5; |
} else { |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
} |
hadGo = true; |
} |
347,12 → 352,12 |
abpool -= 0.5; |
} |
else { |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
} |
hadGo = true; |
} |
359,12 → 364,12 |
else if (line == "N") |
{ |
if(velocity < 5) |
if(velocity < speed) |
velocity += 0.3; |
else if(velocity > 5) |
else if(velocity > speed) |
velocity -= 0.3; |
if(abs(5-velocity)<0.3) |
velocity = 5; |
if(abs(speed-velocity)<0.3) |
velocity = speed; |
if(abpool<10) |
abpool += 0.2; |
hadGo = true; |
/mainwindow.cpp |
---|
12,6 → 12,11 |
connect(timer, SIGNAL(timeout()), this, SLOT(update())); |
timer->start(50); |
suddenDeath = false; |
suddenDeathTimer = new QTimer(this); |
connect(suddenDeathTimer, SIGNAL(timeout()), this, SLOT(activateSuddenDeath())); |
suddenDeathTimer->start(300000); |
id = 0; |
} |
22,6 → 27,10 |
void MainWindow::reset() |
{ |
suddenDeathTimer->stop(); |
suddenDeathTimer->start(300000); |
suddenDeath = false; |
for (int i = 0; i < bikes.count(); i++) |
{ |
bikes[i]->reset(); |
30,6 → 39,14 |
void MainWindow::paintEvent(QPaintEvent *e) |
{ |
if (suddenDeath) |
{ |
for (int i = 0; i < bikes.count(); i++) |
{ |
bikes[i]->speed *= 1.01; |
} |
} |
e->accept(); |
QPainter painter(this); |
46,12 → 63,14 |
if (ready) |
{ |
cout << ":: Sent move request..." << endl; |
for (int i = 0; i < bikes.count(); i++) |
{ |
if (bikes[i]->show) |
{ |
bikes[i]->hasHadGo = false; |
bikes[i]->run(bikes); |
bikes[i]->bikes = bikes; |
bikes[i]->start(); |
} |
} |
Bike *bike; |
138,3 → 157,12 |
bikes[i]->setText(packet); |
} |
} |
void MainWindow::activateSuddenDeath() |
{ |
if (!suddenDeath) |
{ |
suddenDeath = true; |
chat("Server", "SUDDEN DEATH ACTIVATED!"); |
} |
} |
/mainwindow.h |
---|
27,11 → 27,14 |
QList<Bike *> bikes; |
QTimer *timer; |
int id; |
QTimer *suddenDeathTimer; |
bool suddenDeath; |
private slots: |
void newConnection(); |
void checkClients(); |
void chat(QString name, QString message); |
void activateSuddenDeath(); |
}; |
#endif // MAINWINDOW_H |