diff options
| -rw-r--r-- | pacman-c++/actor.h | 1 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 54 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.h | 7 |
3 files changed, 51 insertions, 11 deletions
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h index 5e9ed72..c94be3c 100644 --- a/pacman-c++/actor.h +++ b/pacman-c++/actor.h | |||
| @@ -18,6 +18,7 @@ public: | |||
| 18 | 18 | ||
| 19 | Actor(Color color, QGraphicsItem *parent = 0); | 19 | Actor(Color color, QGraphicsItem *parent = 0); |
| 20 | PixmapItem &getIcon(); | 20 | PixmapItem &getIcon(); |
| 21 | Color getColor() { return m_color; } | ||
| 21 | 22 | ||
| 22 | private: | 23 | private: |
| 23 | QPixmap m_pix; | 24 | QPixmap m_pix; |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 9fdf125..1179a81 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -9,8 +9,29 @@ MainWidget::MainWidget() | |||
| 9 | { | 9 | { |
| 10 | QVBoxLayout *layout = new QVBoxLayout(this); | 10 | QVBoxLayout *layout = new QVBoxLayout(this); |
| 11 | 11 | ||
| 12 | QLabel *lbl = new QLabel("da kommt da spielstand hin", this); | 12 | //QLabel *lbl = new QLabel("da kommt da spielstand hin"); |
| 13 | layout->addWidget(lbl); | 13 | //layout->addWidget(lbl); |
| 14 | |||
| 15 | //scoreBox->setLayout(scoreLayout); | ||
| 16 | QHBoxLayout *m_scoreLayout = new QHBoxLayout(); | ||
| 17 | |||
| 18 | for (unsigned int i=1; i<4; ++i) { | ||
| 19 | QGroupBox *scoreBoxI = new QGroupBox(QString("Player %1").arg(i), this); | ||
| 20 | m_scoreLayout->addWidget(scoreBoxI); | ||
| 21 | |||
| 22 | QGridLayout *playerLayout = new QGridLayout(); | ||
| 23 | scoreBoxI->setLayout(playerLayout); | ||
| 24 | |||
| 25 | playerLayout->addWidget( new QLabel("Rundenpunkte:", this), 0, 0); | ||
| 26 | playerLayout->addWidget( new QLabel("Gesamtpunkte:", this), 1, 0); | ||
| 27 | |||
| 28 | playerLayout->addWidget( new QLabel("100", this), 0, 1); | ||
| 29 | playerLayout->addWidget( new QLabel("1000", this), 1, 1); | ||
| 30 | |||
| 31 | m_playerScoreLayouts.append(playerLayout); | ||
| 32 | } | ||
| 33 | |||
| 34 | //layout->addWidget(scoreBox); | ||
| 14 | 35 | ||
| 15 | m_scene = new QGraphicsScene(0, 0, 500, 500, this); | 36 | m_scene = new QGraphicsScene(0, 0, 500, 500, this); |
| 16 | m_scene->setBackgroundBrush(Qt::black); | 37 | m_scene->setBackgroundBrush(Qt::black); |
| @@ -20,6 +41,8 @@ MainWidget::MainWidget() | |||
| 20 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); | 41 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 21 | window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 42 | window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 22 | window->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 43 | window->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 44 | |||
| 45 | layout->addLayout(m_scoreLayout); | ||
| 23 | layout->addWidget(window); | 46 | layout->addWidget(window); |
| 24 | 47 | ||
| 25 | setLayout(layout); | 48 | setLayout(layout); |
| @@ -28,6 +51,24 @@ MainWidget::MainWidget() | |||
| 28 | loadDummyMap(); | 51 | loadDummyMap(); |
| 29 | } | 52 | } |
| 30 | 53 | ||
| 54 | void MainWidget::updateScore() | ||
| 55 | { | ||
| 56 | QMapIterator<Color, Actor*> i(m_actors); | ||
| 57 | while (i.hasNext()) { | ||
| 58 | i.next(); | ||
| 59 | int id = i.key() - 1; | ||
| 60 | if (id == 4) { | ||
| 61 | id = 3; | ||
| 62 | } | ||
| 63 | QLabel *turnPointsLbl = | ||
| 64 | dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(0,1)->widget()); | ||
| 65 | QLabel *allPointsLbl = | ||
| 66 | dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(1,1)->widget()); | ||
| 67 | turnPointsLbl->setText(QString::number(id * 100 * qrand())); | ||
| 68 | allPointsLbl->setText(QString::number(id * 200 * qrand())); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 31 | // temporary | 72 | // temporary |
| 32 | transmission::map_t createDummyMap() | 73 | transmission::map_t createDummyMap() |
| 33 | { | 74 | { |
| @@ -87,12 +128,8 @@ void MainWidget::loadDummyMap() | |||
| 87 | item = new BonusPoint(); | 128 | item = new BonusPoint(); |
| 88 | else if (cur & transmission::pacman) | 129 | else if (cur & transmission::pacman) |
| 89 | { | 130 | { |
| 90 | Actor *actor = 0; | 131 | Actor *actor = m_actors.value(color, 0); |
| 91 | ActorMap::iterator it = m_actors.find(color); | 132 | if (actor == 0) { // 0 entspricht NULL ;) |
| 92 | if (it != m_actors.end()) | ||
| 93 | actor = it->second; | ||
| 94 | else | ||
| 95 | { | ||
| 96 | qDebug() << "new actor of col" << color; | 133 | qDebug() << "new actor of col" << color; |
| 97 | actor = new Actor(color); | 134 | actor = new Actor(color); |
| 98 | m_actors[color] = actor; | 135 | m_actors[color] = actor; |
| @@ -133,6 +170,7 @@ void MainWidget::loadDummyMap() | |||
| 133 | } | 170 | } |
| 134 | } | 171 | } |
| 135 | } | 172 | } |
| 173 | updateScore(); | ||
| 136 | } | 174 | } |
| 137 | 175 | ||
| 138 | QPoint MainWidget::mapPositionToCoord(unsigned int x, unsigned int y) | 176 | QPoint MainWidget::mapPositionToCoord(unsigned int x, unsigned int y) |
diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index f98cc42..dc20d75 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | 3 | ||
| 4 | #include "constants.h" | 4 | #include "constants.h" |
| 5 | #include <QtGui> | 5 | #include <QtGui> |
| 6 | #include <map> | ||
| 7 | 6 | ||
| 8 | class Actor; | 7 | class Actor; |
| 9 | 8 | ||
| @@ -18,13 +17,15 @@ public: | |||
| 18 | private: | 17 | private: |
| 19 | void loadDummyMap(); | 18 | void loadDummyMap(); |
| 20 | 19 | ||
| 20 | void updateScore(); | ||
| 21 | |||
| 21 | // data conversion | 22 | // data conversion |
| 22 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); | 23 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); |
| 23 | 24 | ||
| 25 | QList<QGridLayout*> m_playerScoreLayouts; | ||
| 24 | QGraphicsScene *m_scene; | 26 | QGraphicsScene *m_scene; |
| 25 | 27 | ||
| 26 | typedef std::map<Color, Actor*> ActorMap; | 28 | QMap<Color, Actor*> m_actors; |
| 27 | ActorMap m_actors; | ||
| 28 | }; | 29 | }; |
| 29 | 30 | ||
| 30 | #endif // MAINWIDGET_H | 31 | #endif // MAINWIDGET_H |
