From 6dc8b50817fe5da8550c245db755f7014402c62a Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 6 Apr 2011 14:32:09 +0200 Subject: some minor cleanup --- pacman-c++/actor.cpp | 2 +- pacman-c++/actor.h | 6 +++--- pacman-c++/block.cpp | 4 ++-- pacman-c++/block.h | 16 ++++++++++++---- pacman-c++/constants.h | 17 ++++++++++------- pacman-c++/mainwidget.cpp | 36 +++++++++++++++++++----------------- pacman-c++/mainwidget.h | 2 +- 7 files changed, 48 insertions(+), 35 deletions(-) (limited to 'pacman-c++') diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 4f28088..3794b63 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp @@ -11,7 +11,7 @@ static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal return (progress == 1.0) ? end : start; } -Actor::Actor(Color color, QGraphicsItem *parent) +Actor::Actor(Color::Color color, QGraphicsItem *parent) : PixmapItem(parent), m_color(color), m_direction(Actor::None) { m_pix = ":/" + QString("actor%1").arg(m_color); diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h index c94be3c..b9e050d 100644 --- a/pacman-c++/actor.h +++ b/pacman-c++/actor.h @@ -16,13 +16,13 @@ public: Down }; - Actor(Color color, QGraphicsItem *parent = 0); + Actor(Color::Color color, QGraphicsItem *parent = 0); PixmapItem &getIcon(); - Color getColor() { return m_color; } + Color::Color getColor() { return m_color; } private: QPixmap m_pix; - Color m_color; + Color::Color m_color; Movement m_direction; PixmapItem m_icon; }; diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp index 87c69a7..ccb7ade 100644 --- a/pacman-c++/block.cpp +++ b/pacman-c++/block.cpp @@ -2,9 +2,9 @@ #include "constants.h" #include -QMap Block::m_pixmaps; +QMap Block::m_pixmaps; -Block::Block(Color color, QGraphicsItem *parent) +Block::Block(Color::Color color, Neighbour neighbour, QGraphicsItem *parent) : PixmapItem(parent) { if (m_pixmaps.find(color) == m_pixmaps.end()) diff --git a/pacman-c++/block.h b/pacman-c++/block.h index 034a626..40bde51 100644 --- a/pacman-c++/block.h +++ b/pacman-c++/block.h @@ -8,12 +8,20 @@ class Block : public PixmapItem { + enum Neighbour { + None = 0, + Left = (1 << 0), + Right = (1 << 1), + Up = (1 << 2), + Down = (1 << 3) + }; + public: - Block(Color color, QGraphicsItem *parent=0); + Block(Color::Color color, Neighbour neighbour = None, QGraphicsItem *parent = 0); - private: - // map for saving QPixmaps for reuse - static QMap m_pixmaps; +private: + // map for saving QPixmaps for reuse + static QMap m_pixmaps; }; #endif // BLOCK_H diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h index 56d29b7..15d3022 100644 --- a/pacman-c++/constants.h +++ b/pacman-c++/constants.h @@ -8,13 +8,16 @@ const unsigned int map_size[2] = { 20, 20 }; const unsigned int field_size[2] = { 16, 16 }; -enum Color +namespace Color { - noColor = 0, - red = (1 << 0), - blue = (1 << 1), - green = (1 << 2), -}; + enum Color + { + none = 0, + red = (1 << 0), + blue = (1 << 1), + green = (1 << 2), + }; +} // constants for data transmission to client namespace transmission @@ -32,7 +35,7 @@ namespace transmission const field_t direction_up = (1 << 8); const field_t direction_down = (1 << 9); - const mask_t color_mask = noColor | red | blue | green; + const mask_t color_mask = Color::none | Color::red | Color::blue | Color::green; const mask_t type_mask = block | bonuspoint; const mask_t direction_mask = direction_none | direction_left | direction_right | direction_up | direction_down; diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 743b57e..e9b4cc3 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp @@ -11,21 +11,21 @@ MainWidget::MainWidget() setFocusPolicy(Qt::StrongFocus); QVBoxLayout *layout = new QVBoxLayout(this); - QHBoxLayout *m_scoreLayout = new QHBoxLayout(); - for (unsigned int i=1; i<4; ++i) { + for (unsigned int i = 1; i < 4; ++i) + { QGroupBox *scoreBoxI = new QGroupBox(QString("Spieler %1").arg(i), this); m_scoreLayout->addWidget(scoreBoxI); QGridLayout *playerLayout = new QGridLayout(); scoreBoxI->setLayout(playerLayout); - playerLayout->addWidget( new QLabel("Rundenpunkte:", this), 0, 0); - playerLayout->addWidget( new QLabel("Gesamtpunkte:", this), 1, 0); + playerLayout->addWidget(new QLabel("Rundenpunkte:", this), 0, 0); + playerLayout->addWidget(new QLabel("Gesamtpunkte:", this), 1, 0); - playerLayout->addWidget( new QLabel("", this), 0, 1); - playerLayout->addWidget( new QLabel("", this), 1, 1); + playerLayout->addWidget(new QLabel("", this), 0, 1); + playerLayout->addWidget(new QLabel("", this), 1, 1); m_playerScoreLayouts.append(playerLayout); } @@ -50,7 +50,7 @@ MainWidget::MainWidget() void MainWidget::updateScore() { - QMapIterator i(m_actors); + QMapIterator i(m_actors); while (i.hasNext()) { i.next(); int id = i.key() - 1; @@ -83,19 +83,21 @@ transmission::map_t createDummyMap() } } - map[4][3] |= green; - map[4][3] |= transmission::block; + map[0][0] |= Color::none ^ transmission::block; + map[0][1] |= Color::none ^ transmission::block; + map[0][2] |= Color::none ^ transmission::block; + map[1][0] |= Color::none ^ transmission::block; + map[2][0] |= Color::none ^ transmission::block; + + map[4][3] |= Color::green ^ transmission::block; - map[5][3] |= noColor; - map[5][3] |= transmission::block; - map[6][3] |= noColor; - map[6][3] |= transmission::block; - map[7][3] |= red; - map[7][3] |= transmission::block; + map[5][3] |= Color::none ^ transmission::block; + map[6][3] |= Color::none ^ transmission::block; + map[7][3] |= Color::red ^ transmission::block; map[7][5] |= transmission::bonuspoint; - map[5][5] |= blue; + map[5][5] |= Color::blue; map[5][5] |= transmission::pacman; map[5][5] |= transmission::direction_left; @@ -115,7 +117,7 @@ void MainWidget::loadDummyMap() continue; qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; - Color color = static_cast(cur & transmission::color_mask); + Color::Color color = static_cast(cur & transmission::color_mask); qDebug() << "col=" << color; PixmapItem *item = 0; diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index f7113a5..0a97116 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h @@ -33,7 +33,7 @@ private: QGraphicsScene *m_scene; // map of actors in order to keep track of those instances - QMap m_actors; + QMap m_actors; // key currently pressed by user transmission::field_t currentKey; -- cgit v1.2.3