8,6 → 8,10 |
connect(server, SIGNAL(newConnection()), this, SLOT(newConnection())); |
server->listen(QHostAddress::Any, 4567); |
|
respec = new QTcpServer(this); |
connect(respec, SIGNAL(newConnection()), this, SLOT(newSpec())); |
respec->listen(QHostAddress::Any, 4568); |
|
timer = new QTimer(this); |
connect(timer, SIGNAL(timeout()), this, SLOT(update())); |
timer->start(50); |
57,6 → 61,11 |
{ |
bikes[i]->reset(); |
} |
|
foreach (Speccy *spec, specs) |
{ |
spec->reset(); |
} |
} |
|
void MainWindow::paintEvent(QPaintEvent *e) |
90,6 → 99,11 |
// cout << ":: Sent move request..." << endl; |
bool alldone = false; |
time_t start = time(NULL); |
foreach (Speccy *spec, specs) |
{ |
spec->bikes = bikes; |
spec->run(); |
} |
while(!alldone){ |
for (int i = 0; i < bikes.count(); i++) |
{ |
140,10 → 154,26 |
} |
} |
|
void MainWindow::newSpec() |
{ |
while(respec->hasPendingConnections()) |
{ |
QTcpSocket *socket = respec->nextPendingConnection(); |
Speccy *speccy = new Speccy(socket); |
specs.append(speccy); |
cout << ":: RESPEC!!!!!!! " << socket->peerAddress().toString().toStdString() << endl; |
} |
} |
|
void MainWindow::checkClients() |
{ |
bool everyoneDied = true; |
|
foreach (Speccy *spec, specs) |
{ |
if(spec->isDisconnected) |
specs.removeAll(spec); |
} |
for (int i = bikes.count() - 1; i >= 0; i--) |
{ |
if (bikes[i]->isDisconnected) |
150,7 → 180,8 |
{ |
for (int j = 0; j < bikes.count(); j++) |
{ |
bikes[j]->setText(QString("DISCO ") + bikes[i]->name + QString("\n")); |
if(bikes[i]->isReady) |
bikes[j]->setText(QString("DISCO ") + bikes[i]->name + QString("\n")); |
} |
|
delete bikes[i]; |
185,6 → 216,11 |
packet.append(message); |
packet.append("\n"); |
|
foreach (Speccy *spec, specs) |
{ |
spec->setText(packet); |
} |
|
for (int i = 0; i < bikes.count(); i++) |
{ |
bikes[i]->setText(packet); |