diff options
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/actor.cpp | 2 | ||||
| -rw-r--r-- | pacman-c++/actor.h | 6 | ||||
| -rw-r--r-- | pacman-c++/block.cpp | 4 | ||||
| -rw-r--r-- | pacman-c++/block.h | 16 | ||||
| -rw-r--r-- | pacman-c++/constants.h | 17 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 36 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.h | 2 |
7 files changed, 48 insertions, 35 deletions
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 | |||
| 11 | return (progress == 1.0) ? end : start; | 11 | return (progress == 1.0) ? end : start; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | Actor::Actor(Color color, QGraphicsItem *parent) | 14 | Actor::Actor(Color::Color color, QGraphicsItem *parent) |
| 15 | : PixmapItem(parent), m_color(color), m_direction(Actor::None) | 15 | : PixmapItem(parent), m_color(color), m_direction(Actor::None) |
| 16 | { | 16 | { |
| 17 | m_pix = ":/" + QString("actor%1").arg(m_color); | 17 | 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: | |||
| 16 | Down | 16 | Down |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | Actor(Color color, QGraphicsItem *parent = 0); | 19 | Actor(Color::Color color, QGraphicsItem *parent = 0); |
| 20 | PixmapItem &getIcon(); | 20 | PixmapItem &getIcon(); |
| 21 | Color getColor() { return m_color; } | 21 | Color::Color getColor() { return m_color; } |
| 22 | 22 | ||
| 23 | private: | 23 | private: |
| 24 | QPixmap m_pix; | 24 | QPixmap m_pix; |
| 25 | Color m_color; | 25 | Color::Color m_color; |
| 26 | Movement m_direction; | 26 | Movement m_direction; |
| 27 | PixmapItem m_icon; | 27 | PixmapItem m_icon; |
| 28 | }; | 28 | }; |
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 @@ | |||
| 2 | #include "constants.h" | 2 | #include "constants.h" |
| 3 | #include <QtDebug> | 3 | #include <QtDebug> |
| 4 | 4 | ||
| 5 | QMap<Color, QPixmap> Block::m_pixmaps; | 5 | QMap<Color::Color, QPixmap> Block::m_pixmaps; |
| 6 | 6 | ||
| 7 | Block::Block(Color color, QGraphicsItem *parent) | 7 | Block::Block(Color::Color color, Neighbour neighbour, QGraphicsItem *parent) |
| 8 | : PixmapItem(parent) | 8 | : PixmapItem(parent) |
| 9 | { | 9 | { |
| 10 | if (m_pixmaps.find(color) == m_pixmaps.end()) | 10 | 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 @@ | |||
| 8 | class Block | 8 | class Block |
| 9 | : public PixmapItem | 9 | : public PixmapItem |
| 10 | { | 10 | { |
| 11 | enum Neighbour { | ||
| 12 | None = 0, | ||
| 13 | Left = (1 << 0), | ||
| 14 | Right = (1 << 1), | ||
| 15 | Up = (1 << 2), | ||
| 16 | Down = (1 << 3) | ||
| 17 | }; | ||
| 18 | |||
| 11 | public: | 19 | public: |
| 12 | Block(Color color, QGraphicsItem *parent=0); | 20 | Block(Color::Color color, Neighbour neighbour = None, QGraphicsItem *parent = 0); |
| 13 | 21 | ||
| 14 | private: | 22 | private: |
| 15 | // map for saving QPixmaps for reuse | 23 | // map for saving QPixmaps for reuse |
| 16 | static QMap<Color, QPixmap> m_pixmaps; | 24 | static QMap<Color::Color, QPixmap> m_pixmaps; |
| 17 | }; | 25 | }; |
| 18 | 26 | ||
| 19 | #endif // BLOCK_H | 27 | #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 @@ | |||
| 8 | const unsigned int map_size[2] = { 20, 20 }; | 8 | const unsigned int map_size[2] = { 20, 20 }; |
| 9 | const unsigned int field_size[2] = { 16, 16 }; | 9 | const unsigned int field_size[2] = { 16, 16 }; |
| 10 | 10 | ||
| 11 | enum Color | 11 | namespace Color |
| 12 | { | 12 | { |
| 13 | noColor = 0, | 13 | enum Color |
| 14 | red = (1 << 0), | 14 | { |
| 15 | blue = (1 << 1), | 15 | none = 0, |
| 16 | green = (1 << 2), | 16 | red = (1 << 0), |
| 17 | }; | 17 | blue = (1 << 1), |
| 18 | green = (1 << 2), | ||
| 19 | }; | ||
| 20 | } | ||
| 18 | 21 | ||
| 19 | // constants for data transmission to client | 22 | // constants for data transmission to client |
| 20 | namespace transmission | 23 | namespace transmission |
| @@ -32,7 +35,7 @@ namespace transmission | |||
| 32 | const field_t direction_up = (1 << 8); | 35 | const field_t direction_up = (1 << 8); |
| 33 | const field_t direction_down = (1 << 9); | 36 | const field_t direction_down = (1 << 9); |
| 34 | 37 | ||
| 35 | const mask_t color_mask = noColor | red | blue | green; | 38 | const mask_t color_mask = Color::none | Color::red | Color::blue | Color::green; |
| 36 | const mask_t type_mask = block | bonuspoint; | 39 | const mask_t type_mask = block | bonuspoint; |
| 37 | const mask_t direction_mask = direction_none | direction_left | direction_right | direction_up | direction_down; | 40 | const mask_t direction_mask = direction_none | direction_left | direction_right | direction_up | direction_down; |
| 38 | 41 | ||
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() | |||
| 11 | setFocusPolicy(Qt::StrongFocus); | 11 | setFocusPolicy(Qt::StrongFocus); |
| 12 | 12 | ||
| 13 | QVBoxLayout *layout = new QVBoxLayout(this); | 13 | QVBoxLayout *layout = new QVBoxLayout(this); |
| 14 | |||
| 15 | QHBoxLayout *m_scoreLayout = new QHBoxLayout(); | 14 | QHBoxLayout *m_scoreLayout = new QHBoxLayout(); |
| 16 | 15 | ||
| 17 | for (unsigned int i=1; i<4; ++i) { | 16 | for (unsigned int i = 1; i < 4; ++i) |
| 17 | { | ||
| 18 | QGroupBox *scoreBoxI = new QGroupBox(QString("Spieler %1").arg(i), this); | 18 | QGroupBox *scoreBoxI = new QGroupBox(QString("Spieler %1").arg(i), this); |
| 19 | m_scoreLayout->addWidget(scoreBoxI); | 19 | m_scoreLayout->addWidget(scoreBoxI); |
| 20 | 20 | ||
| 21 | QGridLayout *playerLayout = new QGridLayout(); | 21 | QGridLayout *playerLayout = new QGridLayout(); |
| 22 | scoreBoxI->setLayout(playerLayout); | 22 | scoreBoxI->setLayout(playerLayout); |
| 23 | 23 | ||
| 24 | playerLayout->addWidget( new QLabel("Rundenpunkte:", this), 0, 0); | 24 | playerLayout->addWidget(new QLabel("Rundenpunkte:", this), 0, 0); |
| 25 | playerLayout->addWidget( new QLabel("Gesamtpunkte:", this), 1, 0); | 25 | playerLayout->addWidget(new QLabel("Gesamtpunkte:", this), 1, 0); |
| 26 | 26 | ||
| 27 | playerLayout->addWidget( new QLabel("", this), 0, 1); | 27 | playerLayout->addWidget(new QLabel("", this), 0, 1); |
| 28 | playerLayout->addWidget( new QLabel("", this), 1, 1); | 28 | playerLayout->addWidget(new QLabel("", this), 1, 1); |
| 29 | 29 | ||
| 30 | m_playerScoreLayouts.append(playerLayout); | 30 | m_playerScoreLayouts.append(playerLayout); |
| 31 | } | 31 | } |
| @@ -50,7 +50,7 @@ MainWidget::MainWidget() | |||
| 50 | 50 | ||
| 51 | void MainWidget::updateScore() | 51 | void MainWidget::updateScore() |
| 52 | { | 52 | { |
| 53 | QMapIterator<Color, Actor*> i(m_actors); | 53 | QMapIterator<Color::Color, Actor*> i(m_actors); |
| 54 | while (i.hasNext()) { | 54 | while (i.hasNext()) { |
| 55 | i.next(); | 55 | i.next(); |
| 56 | int id = i.key() - 1; | 56 | int id = i.key() - 1; |
| @@ -83,19 +83,21 @@ transmission::map_t createDummyMap() | |||
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | map[4][3] |= green; | 86 | map[0][0] |= Color::none ^ transmission::block; |
| 87 | map[4][3] |= transmission::block; | 87 | map[0][1] |= Color::none ^ transmission::block; |
| 88 | map[0][2] |= Color::none ^ transmission::block; | ||
| 89 | map[1][0] |= Color::none ^ transmission::block; | ||
| 90 | map[2][0] |= Color::none ^ transmission::block; | ||
| 91 | |||
| 92 | map[4][3] |= Color::green ^ transmission::block; | ||
| 88 | 93 | ||
| 89 | map[5][3] |= noColor; | 94 | map[5][3] |= Color::none ^ transmission::block; |
| 90 | map[5][3] |= transmission::block; | 95 | map[6][3] |= Color::none ^ transmission::block; |
| 91 | map[6][3] |= noColor; | 96 | map[7][3] |= Color::red ^ transmission::block; |
| 92 | map[6][3] |= transmission::block; | ||
| 93 | map[7][3] |= red; | ||
| 94 | map[7][3] |= transmission::block; | ||
| 95 | 97 | ||
| 96 | map[7][5] |= transmission::bonuspoint; | 98 | map[7][5] |= transmission::bonuspoint; |
| 97 | 99 | ||
| 98 | map[5][5] |= blue; | 100 | map[5][5] |= Color::blue; |
| 99 | map[5][5] |= transmission::pacman; | 101 | map[5][5] |= transmission::pacman; |
| 100 | map[5][5] |= transmission::direction_left; | 102 | map[5][5] |= transmission::direction_left; |
| 101 | 103 | ||
| @@ -115,7 +117,7 @@ void MainWidget::loadDummyMap() | |||
| 115 | continue; | 117 | continue; |
| 116 | qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; | 118 | qDebug() << "not 0 at x=" << x << ", y=" << y << ", val=" << cur; |
| 117 | 119 | ||
| 118 | Color color = static_cast<Color>(cur & transmission::color_mask); | 120 | Color::Color color = static_cast<Color::Color>(cur & transmission::color_mask); |
| 119 | qDebug() << "col=" << color; | 121 | qDebug() << "col=" << color; |
| 120 | 122 | ||
| 121 | PixmapItem *item = 0; | 123 | 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: | |||
| 33 | QGraphicsScene *m_scene; | 33 | QGraphicsScene *m_scene; |
| 34 | 34 | ||
| 35 | // map of actors in order to keep track of those instances | 35 | // map of actors in order to keep track of those instances |
| 36 | QMap<Color, Actor*> m_actors; | 36 | QMap<Color::Color, Actor*> m_actors; |
| 37 | 37 | ||
| 38 | // key currently pressed by user | 38 | // key currently pressed by user |
| 39 | transmission::field_t currentKey; | 39 | transmission::field_t currentKey; |
