/ui_mainwindow.h |
---|
0,0 → 1,55 |
/******************************************************************************** |
** Form generated from reading UI file 'mainwindow.ui' |
** |
** Created: Tue Jun 1 15:55:16 2010 |
** by: Qt User Interface Compiler version 4.6.2 |
** |
** WARNING! All changes made in this file will be lost when recompiling UI file! |
********************************************************************************/ |
#ifndef UI_MAINWINDOW_H |
#define UI_MAINWINDOW_H |
#include <QtCore/QVariant> |
#include <QtGui/QAction> |
#include <QtGui/QApplication> |
#include <QtGui/QButtonGroup> |
#include <QtGui/QHeaderView> |
#include <QtGui/QMainWindow> |
#include <QtGui/QWidget> |
QT_BEGIN_NAMESPACE |
class Ui_MainWindow |
{ |
public: |
QWidget *centralWidget; |
void setupUi(QMainWindow *MainWindow) |
{ |
if (MainWindow->objectName().isEmpty()) |
MainWindow->setObjectName(QString::fromUtf8("MainWindow")); |
MainWindow->resize(600, 400); |
centralWidget = new QWidget(MainWindow); |
centralWidget->setObjectName(QString::fromUtf8("centralWidget")); |
MainWindow->setCentralWidget(centralWidget); |
retranslateUi(MainWindow); |
QMetaObject::connectSlotsByName(MainWindow); |
} // setupUi |
void retranslateUi(QMainWindow *MainWindow) |
{ |
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8)); |
} // retranslateUi |
}; |
namespace Ui { |
class MainWindow: public Ui_MainWindow {}; |
} // namespace Ui |
QT_END_NAMESPACE |
#endif // UI_MAINWINDOW_H |
/bike.h |
---|
32,11 → 32,11 |
int id; |
bool isDisconnected; |
bool hasHadGo; |
QColor colour; |
private: |
QTcpSocket *socket; |
float velocity; |
QColor colour; |
private slots: |
void readyRead(); |
/QTron.pro |
---|
1,7 → 1,7 |
# ------------------------------------------------- |
# Project created by QtCreator 2010-05-31T15:59:14 |
# ------------------------------------------------- |
QT += network opengl |
QT += network |
TARGET = QTron |
TEMPLATE = app |
SOURCES += main.cpp \ |
9,5 → 9,5 |
bike.cpp |
HEADERS += mainwindow.h \ |
bike.h |
FORMS += |
FORMS += mainwindow.ui |
OTHER_FILES += docs.txt |
/mainwindow.h |
---|
6,12 → 6,16 |
#include <QTcpServer> |
#include <QList> |
#include <QTimer> |
#include <QGLWidget> |
#include "bike.h" |
class MainWindow : public QGLWidget |
namespace Ui |
{ |
class MainWindow; |
} |
class MainWindow : public QMainWindow |
{ |
Q_OBJECT |
public: |
20,9 → 24,11 |
void reset(); |
protected: |
void changeEvent(QEvent *e); |
void paintEvent(QPaintEvent *e); |
private: |
Ui::MainWindow *ui; |
QTcpServer *server; |
QList<Bike *> bikes; |
QTimer *timer; |
/mainwindow.ui |
---|
0,0 → 1,21 |
<?xml version="1.0" encoding="UTF-8"?> |
<ui version="4.0"> |
<class>MainWindow</class> |
<widget class="QMainWindow" name="MainWindow"> |
<property name="geometry"> |
<rect> |
<x>0</x> |
<y>0</y> |
<width>600</width> |
<height>400</height> |
</rect> |
</property> |
<property name="windowTitle"> |
<string>MainWindow</string> |
</property> |
<widget class="QWidget" name="centralWidget"/> |
</widget> |
<layoutdefault spacing="6" margin="11"/> |
<resources/> |
<connections/> |
</ui> |
/bike.cpp |
---|
13,6 → 13,7 |
x = rand() % 800; |
y = rand() % 600; |
linePoints.append(QPoint(x, y)); |
linePoints.append(QPoint(x, y)); |
velocity = 1; |
angle = 0; |
111,19 → 112,11 |
socket->write(QString::number(bike->x).toAscii()); |
socket->write(" "); |
socket->write(QString::number(bike->y).toAscii()); |
socket->write(" "); |
socket->write(QString::number(bike->colour.red()).toAscii()); |
socket->write(" "); |
socket->write(QString::number(bike->colour.green()).toAscii()); |
socket->write(" "); |
socket->write(QString::number(bike->colour.blue()).toAscii()); |
socket->write("\n"); |
} |
} |
} |
linePoints.append(QPoint(x, y)); |
if (dead) |
{ |
show = false; |
149,7 → 142,7 |
dead = true; |
} |
} |
hasHadGo = true; |
hasHadGo = true; |
} |
void Bike::reset() |
159,6 → 152,7 |
linePoints.clear(); |
linePoints.append(QPoint(x, y)); |
linePoints.append(QPoint(x, y)); |
velocity = 1; |
angle = 0; |
179,6 → 173,7 |
if (line == "L") |
{ |
linePoints.append(QPoint(x, y)); |
angle -= 90; |
if (angle >= 360) |
193,6 → 188,7 |
} |
else if (line == "R") |
{ |
linePoints.append(QPoint(x, y)); |
angle += 90; |
if (angle >= 360) |
207,16 → 203,19 |
} |
else if (line == "A") |
{ |
linePoints[linePoints.size() - 1] = QPoint(x, y); |
velocity += 0.1; |
hadGo = true; |
} |
else if (line == "D") |
{ |
linePoints[linePoints.size() - 1] = QPoint(x, y); |
velocity -= 0.2; |
hadGo = true; |
} |
else if (line == "N") |
{ |
linePoints[linePoints.size() - 1] = QPoint(x, y); |
hadGo = true; |
} |
else if (line.startsWith("NAME ")) |
/mainwindow.cpp |
---|
1,10 → 1,16 |
#include "mainwindow.h" |
#include "ui_mainwindow.h" |
MainWindow::MainWindow(QWidget *parent) : |
QGLWidget(parent) |
QMainWindow(parent), |
ui(new Ui::MainWindow) |
{ |
this->setFixedSize(800, 600); |
ui->setupUi(this); |
this->setMinimumSize(800, 600); |
this->resize(800, 600); |
this->setMaximumSize(800, 600); |
server = new QTcpServer(this); |
connect(server, SIGNAL(newConnection()), this, SLOT(newConnection())); |
server->listen(QHostAddress::Any, 4567); |
18,6 → 24,7 |
MainWindow::~MainWindow() |
{ |
delete ui; |
delete server; |
} |
29,12 → 36,24 |
} |
} |
void MainWindow::changeEvent(QEvent *e) |
{ |
QMainWindow::changeEvent(e); |
switch (e->type()) { |
case QEvent::LanguageChange: |
ui->retranslateUi(this); |
break; |
default: |
break; |
} |
} |
void MainWindow::paintEvent(QPaintEvent *e) |
{ |
e->accept(); |
QPainter painter(this); |
painter.fillRect(0, 0, 800, 600, Qt::white); |
painter.setRenderHint(QPainter::Antialiasing, true); |
bool ready = true; |
for (int i = 0; i < bikes.count(); i++) |
51,18 → 70,16 |
{ |
if (bikes[i]->show) |
{ |
bikes[i]->hasHadGo = false; |
bikes[i]->run(bikes); |
bikes[i]->hasHadGo = false; |
bikes[i]->run(bikes); |
bikes[i]->draw(&painter); |
} |
} |
Bike *bike; |
foreach(bike,bikes) |
{ |
while(!bike->hasHadGo) |
{ |
} |
} |
Bike *bike; |
foreach(bike,bikes){ |
while(!bike->hasHadGo){ |
} |
} |
} |
checkClients(); |