Subversion Repositories QTron

Compare Revisions

Ignore whitespace Rev 43 → Rev 44

/QTron.pro
6,8 → 6,10
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp \
bike.cpp
bike.cpp \
speccy.cpp
HEADERS += mainwindow.h \
bike.h
bike.h \
speccy.h
FORMS +=
OTHER_FILES += docs.txt
/mainwindow.h
11,6 → 11,7
 
 
#include "bike.h"
#include "speccy.h"
 
class MainWindow : public QGLWidget
{
26,7 → 27,9
 
private:
QTcpServer *server;
QTcpServer *respec;
QList<Bike *> bikes;
QList<Speccy *> specs;
QTimer *timer;
int id;
QTimer *suddenDeathTimer;
35,6 → 38,7
 
private slots:
void newConnection();
void newSpec();
void checkClients();
void chat(QString name, QString message);
void activateSuddenDeath();
/bike.cpp
35,7 → 35,7
{
socket->disconnectFromHost();
show = false;
isReady = true;
//isReady = true;
hadGo = false;
}
}
310,6 → 310,8
{
QByteArray data = socket->readLine();
QString line = data.trimmed();
std::cout << "Bike " << name.toStdString() << " " << line.toStdString()
<< std::endl;
couldReadLine = true;
 
if (line == "L")
/mainwindow.cpp
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);