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++/mainwidget.cpp | 54 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) (limited to 'pacman-c++/mainwidget.cpp') 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) -- cgit v1.2.3