summaryrefslogtreecommitdiffstats
path: root/pacman-c++/mainwidget.cpp
diff options
context:
space:
mode:
authortotycro <totycro@unknown-horizons.org>2011-04-05 17:50:57 +0200
committertotycro <totycro@unknown-horizons.org>2011-04-05 17:50:57 +0200
commit050e11002cb05586cf0f013b234c6801a9d876c4 (patch)
tree00e54db649f2755f793609be4b59e971736b80b5 /pacman-c++/mainwidget.cpp
parent7a56db7a6e9a21c1e2782f27b2f04ccc387d4efe (diff)
downloadfoop-050e11002cb05586cf0f013b234c6801a9d876c4.tar.gz
foop-050e11002cb05586cf0f013b234c6801a9d876c4.tar.bz2
foop-050e11002cb05586cf0f013b234c6801a9d876c4.zip
Added simple scorebox
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
-rw-r--r--pacman-c++/mainwidget.cpp54
1 files changed, 46 insertions, 8 deletions
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
54void 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
32transmission::map_t createDummyMap() 73transmission::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
138QPoint MainWidget::mapPositionToCoord(unsigned int x, unsigned int y) 176QPoint MainWidget::mapPositionToCoord(unsigned int x, unsigned int y)