From b695f67ef718724144a3a5c4be42be373b0f691f Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 11 Apr 2011 17:30:47 +0200 Subject: implement pointsleft counter --- pacman-c++/gameentity.cpp | 3 --- pacman-c++/sceneholder.cpp | 27 ++++++++++++++++++++++----- pacman-c++/sceneholder.h | 15 +++++++++++---- 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 @@ - #include "gameentity.h" - GameEntity::GameEntity() : m_eaten(false) { } - 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 @@ #include "util.h" SceneHolder::SceneHolder(QWidget* parent) - : QWidget(parent), m_color(Color::none) + : QWidget(parent), m_color(Color::none), m_pointsLeft(0) { m_scene = new QGraphicsScene(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height, this); m_scene->setBackgroundBrush(Qt::black); @@ -33,10 +33,11 @@ void SceneHolder::updateMap(const Transmission::map_t& map) PixmapItem* item = NULL; if (cur & Transmission::empty) - { // special handling for purging field - PixmapItem* oldItem = visualMap[x][y]; - // remove elements (in case it's not an actor) - if (oldItem != NULL && dynamic_cast(item) == NULL) + { + /* special handling for purging field */ + PixmapItem *oldItem = visualMap[x][y]; + /* remove elements (in case it's not an actor) */ + if (oldItem != NULL && dynamic_cast(item) == NULL) { m_scene->removeItem(oldItem); visualMap[x][y] = NULL; @@ -79,7 +80,12 @@ void SceneHolder::updateMap(const Transmission::map_t& map) else if (cur & Transmission::bonuspoint) item = new BonusPoint(); else if (cur & Transmission::point) + { + qDebug() << "new point"; item = new Point(); + connect(item, SIGNAL(destroyed()), this, SLOT(decrementPoints())); + ++m_pointsLeft; + } else if (cur & Transmission::pacman) { Actor *actor = m_actors.value(color, NULL); @@ -125,6 +131,17 @@ void SceneHolder::updateMap(const Transmission::map_t& map) } +unsigned int SceneHolder::pointsLeft() +{ + return m_pointsLeft; +} + +void SceneHolder::decrementPoints() +{ + --m_pointsLeft; + qDebug() << "points left=" << m_pointsLeft; +} + QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) { 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: SceneHolder(QWidget* parent = 0); virtual ~SceneHolder() {}; + unsigned int pointsLeft(); + +private slots: + void decrementPoints(); protected: virtual void updateMap(const Transmission::map_t& map); - // data conversion + /* data conversion */ QPoint mapPositionToCoord(unsigned int x, unsigned int y); QPoint mapPositionToCoord(QPoint point); QPoint CoordToMapPosition(unsigned int x, unsigned int y); QPoint CoordToMapPosition(QPoint point); - // map of all pixmap instances + /* map of all pixmap instances */ QVector< QVector > visualMap; - // map of actors in order to keep track of those instances + /* map of actors in order to keep track of those instances */ QMap m_actors; - /* my color */ + /* my local color */ Color::Color m_color; + /* points left before round ends */ + unsigned int m_pointsLeft; + QGraphicsScene *m_scene; }; 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: protected slots: void tick(); - // receive updates of client + /* receive updates of client */ void keyPressUpdate(); protected: - - // block until we have connections from all clients + /* block until we have connections from all clients */ void waitForClientConnections(); - // calculate updates of current tick for sending to client + /* calculate updates of current tick for sending to client */ Transmission::map_t calculateUpdates(); QSharedPointer createUpdatePacket(Transmission::map_t); - // update client maps + /* update client maps */ void sendUpdate(QSharedPointer); QMap m_clientConnections; - // current movements. required to make pacmans continue their movement. + /* current movements. required to make pacmans continue their movement */ QMap m_actorMovements; }; -- cgit v1.2.3