From fae7c3377c8995b217e620c5cf1e963b3ab1e84a Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 12 Apr 2011 16:22:19 +0200 Subject: finding out which actor has eaten which element didn't work correctly. instead of checking that on client side the server now just sends the id of the actor withing the explicit empty id data field --- pacman-c++/sceneholder.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'pacman-c++/sceneholder.cpp') diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index b788a49..fc638f7 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp @@ -33,25 +33,28 @@ void SceneHolder::updateMap(const Transmission::map_t& map) 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 + * remove elements (in case it's not an actor) + */ + if (oldItem != NULL && dynamic_cast(oldItem) == NULL) { removeItem(oldItem); visualMap[x][y] = NULL; Actor *actor = NULL; - foreach (Actor *i, m_actors) + foreach (Actor *tmp, m_actors) { - if (CoordToMapPosition(i->pos().toPoint()) == QPoint(x, y)) + if (cur & tmp->color()) { - actor = i; + actor = tmp; break; } } + + /* no actor removed that item */ + if (actor == NULL) + Q_ASSERT(false); oldItem->onDie(actor); - delete oldItem; - //qDebug() << "deleting " << x << y; } } @@ -112,11 +115,14 @@ void SceneHolder::updateMap(const Transmission::map_t& map) Q_ASSERT(false); } + /* add new created item to scene + * remove old item on that location if there's one + */ if (item != NULL) { addItem(item); item->setPos(mapPositionToCoord(x, y)); - PixmapItem* oldItem = visualMap[x][y]; + PixmapItem *oldItem = visualMap[x][y]; visualMap[x][y] = item; if (oldItem != NULL) { @@ -126,7 +132,6 @@ void SceneHolder::updateMap(const Transmission::map_t& map) } } } - } void SceneHolder::setColor(Color::Color color) @@ -147,7 +152,6 @@ unsigned int SceneHolder::pointsLeft() void SceneHolder::decrementPoints() { --m_pointsLeft; - qDebug() << "points left=" << m_pointsLeft; } QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) -- cgit v1.2.3