From 050e11002cb05586cf0f013b234c6801a9d876c4 Mon Sep 17 00:00:00 2001 From: totycro Date: Tue, 5 Apr 2011 17:50:57 +0200 Subject: Added simple scorebox --- pacman-c++/actor.h | 1 + pacman-c++/mainwidget.cpp | 54 ++++++++++++++++++++++++++++++++++++++++------- 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: Actor(Color color, QGraphicsItem *parent = 0); PixmapItem &getIcon(); + Color getColor() { return m_color; } private: 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() { QVBoxLayout *layout = new QVBoxLayout(this); - QLabel *lbl = new QLabel("da kommt da spielstand hin", this); - layout->addWidget(lbl); + //QLabel *lbl = new QLabel("da kommt da spielstand hin"); + //layout->addWidget(lbl); + + //scoreBox->setLayout(scoreLayout); + QHBoxLayout *m_scoreLayout = new QHBoxLayout(); + + for (unsigned int i=1; i<4; ++i) { + QGroupBox *scoreBoxI = new QGroupBox(QString("Player %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("100", this), 0, 1); + playerLayout->addWidget( new QLabel("1000", this), 1, 1); + + m_playerScoreLayouts.append(playerLayout); + } + + //layout->addWidget(scoreBox); m_scene = new QGraphicsScene(0, 0, 500, 500, this); m_scene->setBackgroundBrush(Qt::black); @@ -20,6 +41,8 @@ MainWidget::MainWidget() window->setAlignment(Qt::AlignLeft | Qt::AlignTop); window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); window->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + layout->addLayout(m_scoreLayout); layout->addWidget(window); setLayout(layout); @@ -28,6 +51,24 @@ MainWidget::MainWidget() loadDummyMap(); } +void MainWidget::updateScore() +{ + QMapIterator i(m_actors); + while (i.hasNext()) { + i.next(); + int id = i.key() - 1; + if (id == 4) { + id = 3; + } + QLabel *turnPointsLbl = + dynamic_cast(m_playerScoreLayouts.at(id)->itemAtPosition(0,1)->widget()); + QLabel *allPointsLbl = + dynamic_cast(m_playerScoreLayouts.at(id)->itemAtPosition(1,1)->widget()); + turnPointsLbl->setText(QString::number(id * 100 * qrand())); + allPointsLbl->setText(QString::number(id * 200 * qrand())); + } +} + // temporary transmission::map_t createDummyMap() { @@ -87,12 +128,8 @@ void MainWidget::loadDummyMap() item = new BonusPoint(); else if (cur & transmission::pacman) { - Actor *actor = 0; - ActorMap::iterator it = m_actors.find(color); - if (it != m_actors.end()) - actor = it->second; - else - { + Actor *actor = m_actors.value(color, 0); + if (actor == 0) { // 0 entspricht NULL ;) qDebug() << "new actor of col" << color; actor = new Actor(color); m_actors[color] = actor; @@ -133,6 +170,7 @@ void MainWidget::loadDummyMap() } } } + updateScore(); } 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 @@ #include "constants.h" #include -#include class Actor; @@ -18,13 +17,15 @@ public: private: void loadDummyMap(); + void updateScore(); + // data conversion QPoint mapPositionToCoord(unsigned int x, unsigned int y); + QList m_playerScoreLayouts; QGraphicsScene *m_scene; - typedef std::map ActorMap; - ActorMap m_actors; + QMap m_actors; }; #endif // MAINWIDGET_H -- cgit v1.2.3