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++/sceneholder.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'pacman-c++/sceneholder.cpp') 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); -- cgit v1.2.3