summaryrefslogtreecommitdiffstats
path: root/pacman-c++/mainwidget.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-14 20:37:53 +0200
committermanuel <manuel@mausz.at>2011-04-14 20:37:53 +0200
commit001f1d11e977d5586fe8496821b3a1e4bf76f10c (patch)
treed0e344db1bd6791500f8973aad3aea26c350cedd /pacman-c++/mainwidget.cpp
parent197708500f3adaaa50bc1a5a94aec0db8ea621e5 (diff)
downloadfoop-001f1d11e977d5586fe8496821b3a1e4bf76f10c.tar.gz
foop-001f1d11e977d5586fe8496821b3a1e4bf76f10c.tar.bz2
foop-001f1d11e977d5586fe8496821b3a1e4bf76f10c.zip
place actors at random positions
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
-rw-r--r--pacman-c++/mainwidget.cpp46
1 files changed, 24 insertions, 22 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp
index a77daab..1fc7687 100644
--- a/pacman-c++/mainwidget.cpp
+++ b/pacman-c++/mainwidget.cpp
@@ -25,10 +25,12 @@ MainWidget::MainWidget(QWidget *parent)
25 25
26 /* call updateMap after m_color ist set! */ 26 /* call updateMap after m_color ist set! */
27 createGui(); 27 createGui();
28 Transmission::map_t map = Util::createDemoMap(); 28
29 m_scene->updateMap(map); 29 /* wait for the server to send the first map update (initial map)
30 Util::deleteMap(map); 30 * WARNING: this will block the gui
31 map = NULL; 31 */
32 m_socket->waitForReadyRead();
33 tick();
32 34
33 connect(m_socket, SIGNAL(readyRead()), this, SLOT(tick())); 35 connect(m_socket, SIGNAL(readyRead()), this, SLOT(tick()));
34 36
@@ -84,7 +86,7 @@ void MainWidget::createGui()
84 86
85 QGraphicsView *window = new QGraphicsView(m_scene, this); 87 QGraphicsView *window = new QGraphicsView(m_scene, this);
86 window->setFrameStyle(0); 88 window->setFrameStyle(0);
87 window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height); 89 window->setFixedSize(m_scene->sceneRect().size().toSize());
88 window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint); 90 window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint);
89 window->setFocusPolicy(Qt::NoFocus); 91 window->setFocusPolicy(Qt::NoFocus);
90 layout->addWidget(window, 0, Qt::AlignCenter); 92 layout->addWidget(window, 0, Qt::AlignCenter);
@@ -140,27 +142,27 @@ Transmission::field_t MainWidget::translateKey(int key)
140 142
141void MainWidget::tick() 143void MainWidget::tick()
142{ 144{
143 QSharedPointer<QByteArray> data = Util::receivePacket(m_socket); 145 while (m_socket->bytesAvailable() > (qint64)sizeof(qint64))
144 bool worked = m_updatepacket.ParseFromArray(data->data(), data->size());
145 Q_ASSERT(worked);
146 Q_UNUSED(worked);
147 Transmission::map_t map = Util::createUninitialisedMap();
148 Q_ASSERT(m_updatepacket.field_size() == (int) (Constants::map_size.width * Constants::map_size.height));
149 int i = 0;
150 for (unsigned int x = 0; x < Constants::map_size.width; ++x)
151 { 146 {
152 for (unsigned int y = 0; y < Constants::map_size.height; ++y) 147 QSharedPointer<QByteArray> data = Util::receivePacket(m_socket);
148 bool worked = m_updatepacket.ParseFromArray(data->data(), data->size());
149 Q_ASSERT(worked);
150 Q_UNUSED(worked);
151 Transmission::map_t map = Util::createUninitialisedMap();
152 Q_ASSERT(m_updatepacket.field_size() == (int) (Constants::map_size.width * Constants::map_size.height));
153 int i = 0;
154 for (unsigned int x = 0; x < Constants::map_size.width; ++x)
153 { 155 {
154 map[x][y] = m_updatepacket.field(i); 156 for (unsigned int y = 0; y < Constants::map_size.height; ++y)
155 ++i; 157 {
158 map[x][y] = m_updatepacket.field(i);
159 ++i;
160 }
156 } 161 }
162 m_scene->updateMap(map);
163 Util::deleteMap(map);
164 updateScore(m_updatepacket);
157 } 165 }
158 m_scene->updateMap(map);
159 Util::deleteMap(map);
160 updateScore(m_updatepacket);
161
162 if (m_socket->bytesAvailable() > (qint64)sizeof(qint64))
163 tick();
164} 166}
165 167
166void MainWidget::keyPressEvent(QKeyEvent* event) 168void MainWidget::keyPressEvent(QKeyEvent* event)