| @@ -1,24 +1,68 @@ | ||
| <?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>400</width> | ||
| <height>300</height> | ||
| </rect> | ||
| </property> | ||
| <property name="windowTitle"> | ||
| <string>MainWindow</string> | ||
| </property> | ||
| <widget class="QWidget" name="centralWidget"> | ||
| <widget class="QPushButton" name="joinToGameButton"> | ||
| <property name="geometry"> | ||
| <rect> | ||
| <x>150</x> | ||
| <y>30</y> | ||
| <width>100</width> | ||
| <height>50</height> | ||
| </rect> | ||
| </property> | ||
| <property name="minimumSize"> | ||
| <size> | ||
| <width>91</width> | ||
| <height>0</height> | ||
| </size> | ||
| </property> | ||
| <property name="text"> | ||
| <string>Dołącz do gry</string> | ||
| </property> | ||
| </widget> | ||
| <widget class="QPushButton" name="pushButton_2"> | ||
| <property name="geometry"> | ||
| <rect> | ||
| <x>150</x> | ||
| <y>110</y> | ||
| <width>100</width> | ||
| <height>50</height> | ||
| </rect> | ||
| </property> | ||
| <property name="text"> | ||
| <string>Opcje</string> | ||
| </property> | ||
| </widget> | ||
| <widget class="QPushButton" name="exitButton"> | ||
| <property name="geometry"> | ||
| <rect> | ||
| <x>150</x> | ||
| <y>190</y> | ||
| <width>100</width> | ||
| <height>50</height> | ||
| </rect> | ||
| </property> | ||
| <property name="text"> | ||
| <string>Wyjście</string> | ||
| </property> | ||
| </widget> | ||
| </widget> | ||
| <widget class="QStatusBar" name="statusBar"/> | ||
| </widget> | ||
| <layoutdefault spacing="6" margin="11"/> | ||
| <resources/> | ||
| <connections/> | ||
| </ui> |
| @@ -0,0 +1,5 @@ | ||
| <RCC> | ||
| <qresource prefix="/"> | ||
| <file>Graphics/tank1.png</file> | ||
| </qresource> | ||
| </RCC> |
| @@ -0,0 +1,8 @@ | ||
| #include "tank.h" | ||
|
|
||
| Tank::Tank(QString playerName):name(playerName) | ||
| { | ||
| czolg = new TankModel; | ||
| czolg->setFocus(); | ||
| } | ||
|
|
| @@ -0,0 +1,37 @@ | ||
| #ifndef TANK_H | ||
| #define TANK_H | ||
| #include <QString> | ||
| #include <QGraphicsPixmapItem> | ||
| #include <QGraphicsView> | ||
| #include "tankmodel.h" | ||
|
|
||
| class Tank | ||
| { | ||
| private: | ||
| int coordinateX; | ||
| int coordinateY; | ||
| int lifes; | ||
| QString name; | ||
|
|
||
|
|
||
|
|
||
| public: | ||
| Tank(QString playerName); | ||
| void updateCoordinates(int x, int y) | ||
| { | ||
| coordinateX+=x; | ||
| coordinateY+=y; | ||
| } | ||
| void updateLife(int life ){lifes=life;} | ||
| TankModel *czolg; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| signals: | ||
|
|
||
| public slots: | ||
| }; | ||
|
|
||
| #endif // TANK_H |
| @@ -0,0 +1,50 @@ | ||
| #include "tankmodel.h" | ||
|
|
||
| TankModel::TankModel(QGraphicsItem *parent): QGraphicsItem(parent) | ||
| { | ||
| setFlag(QGraphicsItem::ItemIsFocusable); | ||
| } | ||
|
|
||
| QRectF TankModel::boundingRect() const | ||
| { | ||
| return QRectF(0,0,70,70); | ||
|
|
||
| } | ||
|
|
||
| void TankModel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
| { | ||
|
|
||
| painter->drawPixmap(10,10, QPixmap(":/Graphics/tank1.png")); | ||
| } | ||
|
|
||
| void TankModel::keyPressEvent(QKeyEvent *event) | ||
| { | ||
| switch(event->key()) | ||
| { | ||
| case Qt::Key_Right: | ||
|
|
||
| moveBy(5,0); | ||
| break; | ||
|
|
||
|
|
||
| case Qt::Key_Left: | ||
|
|
||
| moveBy(-5,0); | ||
| break; | ||
|
|
||
|
|
||
| case Qt::Key_Up: | ||
|
|
||
| moveBy(0,-5); | ||
| break; | ||
|
|
||
|
|
||
| case Qt::Key_Down: | ||
|
|
||
| moveBy(0,5); | ||
|
|
||
| break; | ||
|
|
||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,18 @@ | ||
| #ifndef TANKMODEL_H | ||
| #define TANKMODEL_H | ||
| #include <QGraphicsItem> | ||
| #include <QGraphicsView> | ||
| #include <QKeyEvent> | ||
| class TankModel: public QGraphicsItem | ||
| { | ||
| public: | ||
| virtual void keyPressEvent(QKeyEvent *event); | ||
|
|
||
| TankModel(QGraphicsItem *parent =NULL); | ||
| protected: | ||
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | ||
| QRectF boundingRect() const; | ||
|
|
||
| }; | ||
|
|
||
| #endif // TANKMODEL_H |
| @@ -15,6 +15,7 @@ class client : public QObject | ||
| int connectToServer(QString address, QString port); | ||
| int updatePosition(); | ||
| private: | ||
|
|
||
| QString address,port; | ||
| QTcpSocket socket; | ||
|
|
||