diff options
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/gameentity.cpp | 3 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 27 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.h | 15 | ||||
| -rw-r--r-- | pacman-c++/server.h | 11 |
4 files changed, 38 insertions, 18 deletions
diff --git a/pacman-c++/gameentity.cpp b/pacman-c++/gameentity.cpp index ec43d93..8711ebe 100644 --- a/pacman-c++/gameentity.cpp +++ b/pacman-c++/gameentity.cpp | |||
| @@ -1,9 +1,6 @@ | |||
| 1 | |||
| 2 | #include "gameentity.h" | 1 | #include "gameentity.h" |
| 3 | 2 | ||
| 4 | |||
| 5 | GameEntity::GameEntity() | 3 | GameEntity::GameEntity() |
| 6 | : m_eaten(false) | 4 | : m_eaten(false) |
| 7 | { | 5 | { |
| 8 | } | 6 | } |
| 9 | |||
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index c9bcbf9..b3ff588 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include "util.h" | 9 | #include "util.h" |
| 10 | 10 | ||
| 11 | SceneHolder::SceneHolder(QWidget* parent) | 11 | SceneHolder::SceneHolder(QWidget* parent) |
| 12 | : QWidget(parent), m_color(Color::none) | 12 | : QWidget(parent), m_color(Color::none), m_pointsLeft(0) |
| 13 | { | 13 | { |
| 14 | m_scene = new QGraphicsScene(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height, this); | 14 | m_scene = new QGraphicsScene(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height, this); |
| 15 | m_scene->setBackgroundBrush(Qt::black); | 15 | m_scene->setBackgroundBrush(Qt::black); |
| @@ -33,10 +33,11 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 33 | PixmapItem* item = NULL; | 33 | PixmapItem* item = NULL; |
| 34 | 34 | ||
| 35 | if (cur & Transmission::empty) | 35 | if (cur & Transmission::empty) |
| 36 | { // special handling for purging field | 36 | { |
| 37 | PixmapItem* oldItem = visualMap[x][y]; | 37 | /* special handling for purging field */ |
| 38 | // remove elements (in case it's not an actor) | 38 | PixmapItem *oldItem = visualMap[x][y]; |
| 39 | if (oldItem != NULL && dynamic_cast<Actor*>(item) == NULL) | 39 | /* remove elements (in case it's not an actor) */ |
| 40 | if (oldItem != NULL && dynamic_cast<Actor *>(item) == NULL) | ||
| 40 | { | 41 | { |
| 41 | m_scene->removeItem(oldItem); | 42 | m_scene->removeItem(oldItem); |
| 42 | visualMap[x][y] = NULL; | 43 | visualMap[x][y] = NULL; |
| @@ -79,7 +80,12 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 79 | else if (cur & Transmission::bonuspoint) | 80 | else if (cur & Transmission::bonuspoint) |
| 80 | item = new BonusPoint(); | 81 | item = new BonusPoint(); |
| 81 | else if (cur & Transmission::point) | 82 | else if (cur & Transmission::point) |
| 83 | { | ||
| 84 | qDebug() << "new point"; | ||
| 82 | item = new Point(); | 85 | item = new Point(); |
| 86 | connect(item, SIGNAL(destroyed()), this, SLOT(decrementPoints())); | ||
| 87 | ++m_pointsLeft; | ||
| 88 | } | ||
| 83 | else if (cur & Transmission::pacman) | 89 | else if (cur & Transmission::pacman) |
| 84 | { | 90 | { |
| 85 | Actor *actor = m_actors.value(color, NULL); | 91 | Actor *actor = m_actors.value(color, NULL); |
| @@ -125,6 +131,17 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 125 | 131 | ||
| 126 | } | 132 | } |
| 127 | 133 | ||
| 134 | unsigned int SceneHolder::pointsLeft() | ||
| 135 | { | ||
| 136 | return m_pointsLeft; | ||
| 137 | } | ||
| 138 | |||
| 139 | void SceneHolder::decrementPoints() | ||
| 140 | { | ||
| 141 | --m_pointsLeft; | ||
| 142 | qDebug() << "points left=" << m_pointsLeft; | ||
| 143 | } | ||
| 144 | |||
| 128 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) | 145 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) |
| 129 | { | 146 | { |
| 130 | return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); | 147 | return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); |
diff --git a/pacman-c++/sceneholder.h b/pacman-c++/sceneholder.h index 1ca991e..ccb2a42 100644 --- a/pacman-c++/sceneholder.h +++ b/pacman-c++/sceneholder.h | |||
| @@ -17,25 +17,32 @@ public: | |||
| 17 | SceneHolder(QWidget* parent = 0); | 17 | SceneHolder(QWidget* parent = 0); |
| 18 | virtual ~SceneHolder() | 18 | virtual ~SceneHolder() |
| 19 | {}; | 19 | {}; |
| 20 | unsigned int pointsLeft(); | ||
| 21 | |||
| 22 | private slots: | ||
| 23 | void decrementPoints(); | ||
| 20 | 24 | ||
| 21 | protected: | 25 | protected: |
| 22 | virtual void updateMap(const Transmission::map_t& map); | 26 | virtual void updateMap(const Transmission::map_t& map); |
| 23 | 27 | ||
| 24 | // data conversion | 28 | /* data conversion */ |
| 25 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); | 29 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); |
| 26 | QPoint mapPositionToCoord(QPoint point); | 30 | QPoint mapPositionToCoord(QPoint point); |
| 27 | QPoint CoordToMapPosition(unsigned int x, unsigned int y); | 31 | QPoint CoordToMapPosition(unsigned int x, unsigned int y); |
| 28 | QPoint CoordToMapPosition(QPoint point); | 32 | QPoint CoordToMapPosition(QPoint point); |
| 29 | 33 | ||
| 30 | // map of all pixmap instances | 34 | /* map of all pixmap instances */ |
| 31 | QVector< QVector<PixmapItem *> > visualMap; | 35 | QVector< QVector<PixmapItem *> > visualMap; |
| 32 | 36 | ||
| 33 | // map of actors in order to keep track of those instances | 37 | /* map of actors in order to keep track of those instances */ |
| 34 | QMap<Color::Color, Actor*> m_actors; | 38 | QMap<Color::Color, Actor*> m_actors; |
| 35 | 39 | ||
| 36 | /* my color */ | 40 | /* my local color */ |
| 37 | Color::Color m_color; | 41 | Color::Color m_color; |
| 38 | 42 | ||
| 43 | /* points left before round ends */ | ||
| 44 | unsigned int m_pointsLeft; | ||
| 45 | |||
| 39 | QGraphicsScene *m_scene; | 46 | QGraphicsScene *m_scene; |
| 40 | }; | 47 | }; |
| 41 | 48 | ||
diff --git a/pacman-c++/server.h b/pacman-c++/server.h index 8d73d24..d791c15 100644 --- a/pacman-c++/server.h +++ b/pacman-c++/server.h | |||
| @@ -19,25 +19,24 @@ public: | |||
| 19 | protected slots: | 19 | protected slots: |
| 20 | void tick(); | 20 | void tick(); |
| 21 | 21 | ||
| 22 | // receive updates of client | 22 | /* receive updates of client */ |
| 23 | void keyPressUpdate(); | 23 | void keyPressUpdate(); |
| 24 | 24 | ||
| 25 | protected: | 25 | protected: |
| 26 | 26 | /* block until we have connections from all clients */ | |
| 27 | // block until we have connections from all clients | ||
| 28 | void waitForClientConnections(); | 27 | void waitForClientConnections(); |
| 29 | 28 | ||
| 30 | // calculate updates of current tick for sending to client | 29 | /* calculate updates of current tick for sending to client */ |
| 31 | Transmission::map_t calculateUpdates(); | 30 | Transmission::map_t calculateUpdates(); |
| 32 | 31 | ||
| 33 | QSharedPointer<ProtoBuf::MapUpdate> createUpdatePacket(Transmission::map_t); | 32 | QSharedPointer<ProtoBuf::MapUpdate> createUpdatePacket(Transmission::map_t); |
| 34 | 33 | ||
| 35 | // update client maps | 34 | /* update client maps */ |
| 36 | void sendUpdate(QSharedPointer<ProtoBuf::MapUpdate>); | 35 | void sendUpdate(QSharedPointer<ProtoBuf::MapUpdate>); |
| 37 | 36 | ||
| 38 | QMap<Color::Color, QTcpSocket *> m_clientConnections; | 37 | QMap<Color::Color, QTcpSocket *> m_clientConnections; |
| 39 | 38 | ||
| 40 | // current movements. required to make pacmans continue their movement. | 39 | /* current movements. required to make pacmans continue their movement */ |
| 41 | QMap<Color::Color, Actor::Movement> m_actorMovements; | 40 | QMap<Color::Color, Actor::Movement> m_actorMovements; |
| 42 | }; | 41 | }; |
| 43 | 42 | ||
