diff options
| author | manuel <manuel@mausz.at> | 2011-04-11 17:30:47 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-11 17:30:47 +0200 |
| commit | b695f67ef718724144a3a5c4be42be373b0f691f (patch) | |
| tree | f6035441cc93deff90db0c5ba1686856ec6d03d9 /pacman-c++/sceneholder.cpp | |
| parent | 7667effa9635b0c25088305fe89c15a9805d6dbb (diff) | |
| download | foop-b695f67ef718724144a3a5c4be42be373b0f691f.tar.gz foop-b695f67ef718724144a3a5c4be42be373b0f691f.tar.bz2 foop-b695f67ef718724144a3a5c4be42be373b0f691f.zip | |
implement pointsleft counter
Diffstat (limited to 'pacman-c++/sceneholder.cpp')
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
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); |
