diff options
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index ad11bf2..819088c 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -172,25 +172,23 @@ Transmission::map_t createDummyMap() | |||
| 172 | map[x + 3][y + 2] |= Color::none | Transmission::block; | 172 | map[x + 3][y + 2] |= Color::none | Transmission::block; |
| 173 | x += 5; | 173 | x += 5; |
| 174 | 174 | ||
| 175 | /* | 175 | map[15][16] |= Color::red | Transmission::block; |
| 176 | map[4][3] |= Color::green ^ Transmission::block; | 176 | map[15][17] |= Color::blue | Transmission::block; |
| 177 | 177 | map[15][18] |= Color::green | Transmission::block; | |
| 178 | map[5][3] |= Color::none ^ Transmission::block; | 178 | map[15][19] |= Transmission::bonuspoint; |
| 179 | map[6][3] |= Color::none ^ Transmission::block; | ||
| 180 | map[7][3] |= Color::red ^ Transmission::block; | ||
| 181 | |||
| 182 | map[7][5] |= Transmission::bonuspoint; | ||
| 183 | |||
| 184 | map[5][5] |= Color::blue; | ||
| 185 | map[5][5] |= Transmission::pacman; | ||
| 186 | map[5][5] |= Transmission::direction_left; | ||
| 187 | 179 | ||
| 188 | map[7][5] |= Transmission::bonuspoint;*/ | 180 | map[15][15] |= Color::red; |
| 189 | |||
| 190 | map[15][15] |= Color::blue; | ||
| 191 | map[15][15] |= Transmission::pacman; | 181 | map[15][15] |= Transmission::pacman; |
| 192 | map[15][15] |= Transmission::direction_left; | 182 | map[15][15] |= Transmission::direction_left; |
| 193 | 183 | ||
| 184 | map[16][15] |= Color::blue; | ||
| 185 | map[16][15] |= Transmission::pacman; | ||
| 186 | map[16][15] |= Transmission::direction_left; | ||
| 187 | |||
| 188 | map[17][15] |= Color::green; | ||
| 189 | map[17][15] |= Transmission::pacman; | ||
| 190 | map[17][15] |= Transmission::direction_left; | ||
| 191 | |||
| 194 | return map; | 192 | return map; |
| 195 | } | 193 | } |
| 196 | 194 | ||
| @@ -250,11 +248,15 @@ void MainWidget::createGui() | |||
| 250 | void MainWidget::updateScore() | 248 | void MainWidget::updateScore() |
| 251 | { | 249 | { |
| 252 | QMapIterator<Color::Color, Actor*> i(m_actors); | 250 | QMapIterator<Color::Color, Actor*> i(m_actors); |
| 253 | while (i.hasNext()) { | 251 | while (i.hasNext()) |
| 252 | { | ||
| 254 | i.next(); | 253 | i.next(); |
| 255 | int id = i.key() - 1; | 254 | int id = (i.key() >> 1); |
| 256 | if (id == 4) { | 255 | if (id > (Color::max >> 1)) |
| 257 | id = 3; | 256 | { |
| 257 | /* player #4 isn't supported in score */ | ||
| 258 | Q_ASSERT(false); | ||
| 259 | continue; | ||
| 258 | } | 260 | } |
| 259 | QLabel *turnPointsLbl = | 261 | QLabel *turnPointsLbl = |
| 260 | dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(0,1)->widget()); | 262 | dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(0,1)->widget()); |
| @@ -274,10 +276,10 @@ void MainWidget::updateMap(const Transmission::map_t& map) | |||
| 274 | const Transmission::field_t &cur = map[x][y]; | 276 | const Transmission::field_t &cur = map[x][y]; |
| 275 | if (cur == 0) | 277 | if (cur == 0) |
| 276 | continue; | 278 | continue; |
| 277 | qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; | 279 | //qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; |
| 278 | 280 | ||
| 279 | Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); | 281 | Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); |
| 280 | qDebug() << "col=" << color; | 282 | //qDebug() << "col=" << color; |
| 281 | 283 | ||
| 282 | PixmapItem* item = NULL; | 284 | PixmapItem* item = NULL; |
| 283 | if (cur & Transmission::block) | 285 | if (cur & Transmission::block) |
| @@ -303,7 +305,7 @@ void MainWidget::updateMap(const Transmission::map_t& map) | |||
| 303 | { | 305 | { |
| 304 | Actor *actor = m_actors.value(color, 0); | 306 | Actor *actor = m_actors.value(color, 0); |
| 305 | if (actor == 0) { // 0 entspricht NULL ;) | 307 | if (actor == 0) { // 0 entspricht NULL ;) |
| 306 | qDebug() << "new actor of col" << color; | 308 | //qDebug() << "new actor of col" << color; |
| 307 | actor = new Actor(color); | 309 | actor = new Actor(color); |
| 308 | m_actors[color] = actor; | 310 | m_actors[color] = actor; |
| 309 | m_scene->addItem(actor); | 311 | m_scene->addItem(actor); |
| @@ -342,13 +344,15 @@ void MainWidget::updateMap(const Transmission::map_t& map) | |||
| 342 | item->setPos(mapPositionToCoord(x, y)); | 344 | item->setPos(mapPositionToCoord(x, y)); |
| 343 | PixmapItem* oldItem = visualMap[x][y]; | 345 | PixmapItem* oldItem = visualMap[x][y]; |
| 344 | visualMap[x][y] = item; | 346 | visualMap[x][y] = item; |
| 345 | if (oldItem != NULL) { | 347 | if (oldItem != NULL) |
| 348 | { | ||
| 346 | m_scene->removeItem(item); | 349 | m_scene->removeItem(item); |
| 347 | delete oldItem; | 350 | delete oldItem; |
| 348 | } | 351 | } |
| 349 | } | 352 | } |
| 350 | } | 353 | } |
| 351 | } | 354 | } |
| 355 | |||
| 352 | updateScore(); | 356 | updateScore(); |
| 353 | } | 357 | } |
| 354 | 358 | ||
