Subversion Repositories QTron

Compare Revisions

Ignore whitespace Rev 23 → Rev 30

/bike.h
21,6 → 21,7
void draw(QPainter *painter,QList<Bike *> bikes);
void run(QList<Bike *> bikes);
bool hasCollided(QList<Bike *> bikes);
void setText(QString text);
void reset();
bool isReady;
bool dead;
/bike.cpp
15,7 → 15,7
linePoints.append(QPoint(x, y));
 
velocity = 1;
angle = 0;
angle = (rand() % 4) * 90;
abpool = 0;
name = "";
show = false;
81,6 → 81,15
{
x -= velocity;
}
if (angle == 0 || angle == 180)
{
painter->fillRect(x - 5, y - 15, 10, 30, colour);
}
else
{
painter->fillRect(x - 15, y - 5, 30, 10, colour);
}
painter->drawText(x, y - 20, name);
}
else
{
87,16 → 96,9
linePoints.clear();
}
 
if (angle == 0 || angle == 180)
{
painter->fillRect(x - 5, y - 15, 10, 30, colour);
}
else
{
painter->fillRect(x - 15, y - 5, 30, 10, colour);
}
 
painter->drawText(x, y - 20, name);
 
 
}
}
 
107,7 → 109,7
Bike *bike = bikes[i];
if (bike->isReady && bike->show)
{
if (bike->dead || bike->collided)
if (bike->collided)
{
socket->write("DEAD ");
socket->write(bike->name.toAscii());
148,7 → 150,7
socket->flush();
 
hadGo = false;
if (!socket->waitForReadyRead(2000))
if (!socket->waitForReadyRead(10000))
{
socket->disconnectFromHost();
dead = true;
246,6 → 248,12
return false;
}
 
void Bike::setText(QString text)
{
socket->write(text.toAscii().data());
socket->flush();
}
 
void Bike::reset()
{
x = rand() % 800;
286,10 → 294,10
angle += 360;
}
if(velocity < 5)
velocity += 0.5;
velocity += 0.3;
else if(velocity > 5)
velocity -= 0.5;
if(abs(5-velocity)<0.5)
velocity -= 0.3;
if(abs(5-velocity)<0.3)
velocity = 5;
if(abpool<10)
abpool += 0.2;
308,10 → 316,10
angle += 360;
}
if(velocity < 5)
velocity += 0.5;
velocity += 0.3;
else if(velocity > 5)
velocity -= 0.5;
if(abs(5-velocity)<0.5)
velocity -= 0.3;
if(abs(5-velocity)<0.3)
velocity = 5;
if(abpool<10)
abpool += 0.2;
324,10 → 332,10
abpool -= 0.5;
} else {
if(velocity < 5)
velocity += 0.5;
velocity += 0.3;
else if(velocity > 5)
velocity -= 0.5;
if(abs(5-velocity)<0.5)
velocity -= 0.3;
if(abs(5-velocity)<0.3)
velocity = 5;
}
hadGo = true;
340,10 → 348,10
}
else {
if(velocity < 5)
velocity += 0.5;
velocity += 0.3;
else if(velocity > 5)
velocity -= 0.5;
if(abs(5-velocity)<0.5)
velocity -= 0.3;
if(abs(5-velocity)<0.3)
velocity = 5;
}
hadGo = true;
350,11 → 358,12
}
else if (line == "N")
{
 
if(velocity < 5)
velocity += 0.5;
velocity += 0.3;
else if(velocity > 5)
velocity -= 0.5;
if(abs(5-velocity)<0.5)
velocity -= 0.3;
if(abs(5-velocity)<0.3)
velocity = 5;
if(abpool<10)
abpool += 0.2;
/mainwindow.cpp
4,7 → 4,6
QGLWidget(parent)
{
this->setFixedSize(800, 600);
 
server = new QTcpServer(this);
connect(server, SIGNAL(newConnection()), this, SLOT(newConnection()));
server->listen(QHostAddress::Any, 4567);
91,13 → 90,36
 
void MainWindow::checkClients()
{
bool everyoneDied = true;
 
for (int i = bikes.count() - 1; i >= 0; i--)
{
if (bikes[i]->isDisconnected)
{
for (int j = 0; j < bikes.count(); j++)
{
bikes[j]->setText(QString("DISCO ") + bikes[i]->name + QString("\n"));
}
 
delete bikes[i];
bikes.removeAt(i);
cout << ":: Removed Bike: " << i << endl;
}
else
{
if (!bikes[i]->collided)
{
everyoneDied = false;
}
else if (bikes[i]->dead)
{
everyoneDied = false;
}
}
}
 
if (everyoneDied)
{
reset();
}
}