diff options
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 16 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 7 | ||||
| -rw-r--r-- | pacman-c++/server.h | 4 |
3 files changed, 14 insertions, 13 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index bdc2da1..b69e0c0 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -9,8 +9,6 @@ | |||
| 9 | MainWidget::MainWidget(QWidget *parent) | 9 | MainWidget::MainWidget(QWidget *parent) |
| 10 | : SceneHolder(parent), m_currentKey(0), m_running(false) | 10 | : SceneHolder(parent), m_currentKey(0), m_running(false) |
| 11 | { | 11 | { |
| 12 | createGui(); | ||
| 13 | |||
| 14 | m_color = connectToServer(); | 12 | m_color = connectToServer(); |
| 15 | if (m_color == Color::none) | 13 | if (m_color == Color::none) |
| 16 | { | 14 | { |
| @@ -24,6 +22,7 @@ MainWidget::MainWidget(QWidget *parent) | |||
| 24 | } | 22 | } |
| 25 | 23 | ||
| 26 | /* call updateMap after m_color ist set! */ | 24 | /* call updateMap after m_color ist set! */ |
| 25 | createGui(); | ||
| 27 | updateMap(Util::createDemoMap()); | 26 | updateMap(Util::createDemoMap()); |
| 28 | 27 | ||
| 29 | if (m_socket != NULL) | 28 | if (m_socket != NULL) |
| @@ -42,16 +41,14 @@ void MainWidget::createGui() | |||
| 42 | { | 41 | { |
| 43 | setFocusPolicy(Qt::StrongFocus); | 42 | setFocusPolicy(Qt::StrongFocus); |
| 44 | 43 | ||
| 45 | QVBoxLayout *layout = new QVBoxLayout(this); | 44 | /* first one is always the own score */ |
| 46 | QHBoxLayout *scoreLayout = new QHBoxLayout(); | 45 | QHBoxLayout *scoreLayout = new QHBoxLayout(); |
| 47 | |||
| 48 | for (unsigned int i = 0; Color::order[i] != Color::none ; ++i) | 46 | for (unsigned int i = 0; Color::order[i] != Color::none ; ++i) |
| 49 | { | 47 | { |
| 50 | QGroupBox *scoreBox = new QGroupBox(QString("Spieler %1").arg(i + 1), this); | 48 | QGroupBox *scoreBox = new QGroupBox(QString("Spieler %1").arg(i + 1), this); |
| 51 | scoreBox->setObjectName(QString("actor%1").arg(i + 1)); | 49 | scoreBox->setObjectName(QString("actor%1").arg(i + 1)); |
| 52 | scoreBox->setCheckable(true); | 50 | scoreBox->setCheckable(true); |
| 53 | connect(scoreBox, SIGNAL(clicked()), this, SLOT(playerScoreClicked())); | 51 | connect(scoreBox, SIGNAL(clicked()), this, SLOT(playerScoreClicked())); |
| 54 | scoreLayout->addWidget(scoreBox); | ||
| 55 | 52 | ||
| 56 | QGridLayout *playerLayout = new QGridLayout(); | 53 | QGridLayout *playerLayout = new QGridLayout(); |
| 57 | scoreBox->setLayout(playerLayout); | 54 | scoreBox->setLayout(playerLayout); |
| @@ -62,17 +59,22 @@ void MainWidget::createGui() | |||
| 62 | playerLayout->addWidget(new QLabel("", this), 0, 1); | 59 | playerLayout->addWidget(new QLabel("", this), 0, 1); |
| 63 | playerLayout->addWidget(new QLabel("", this), 1, 1); | 60 | playerLayout->addWidget(new QLabel("", this), 1, 1); |
| 64 | 61 | ||
| 62 | if (Color::order[i] == m_color) | ||
| 63 | scoreLayout->insertWidget(0, scoreBox); | ||
| 64 | else | ||
| 65 | scoreLayout->addWidget(scoreBox); | ||
| 65 | m_playerScoreLayouts.append(playerLayout); | 66 | m_playerScoreLayouts.append(playerLayout); |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 69 | QVBoxLayout *layout = new QVBoxLayout(this); | ||
| 70 | layout->addLayout(scoreLayout); | ||
| 71 | |||
| 68 | QGraphicsView *window = new QGraphicsView(m_scene, this); | 72 | QGraphicsView *window = new QGraphicsView(m_scene, this); |
| 69 | window->setFrameStyle(0); | 73 | window->setFrameStyle(0); |
| 70 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); | 74 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 71 | window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height); | 75 | window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height); |
| 72 | window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint); | 76 | window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint); |
| 73 | window->setFocusPolicy(Qt::NoFocus); | 77 | window->setFocusPolicy(Qt::NoFocus); |
| 74 | |||
| 75 | layout->addLayout(scoreLayout); | ||
| 76 | layout->addWidget(window); | 78 | layout->addWidget(window); |
| 77 | 79 | ||
| 78 | QFile css(":/stylesheet"); | 80 | QFile css(":/stylesheet"); |
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 4715ec6..e7dd943 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -118,12 +118,11 @@ void Server::waitForClientConnections() | |||
| 118 | 118 | ||
| 119 | #define SINGLE | 119 | #define SINGLE |
| 120 | 120 | ||
| 121 | Color::Color playerColors[3] = { Color::red, Color::blue, Color::green }; | ||
| 122 | #ifdef SINGLE | 121 | #ifdef SINGLE |
| 123 | for (unsigned int i=0; i < 1; ++i) | 122 | for (unsigned int i = 0; i < 1; ++i) |
| 124 | { | 123 | { |
| 125 | #else | 124 | #else |
| 126 | for (unsigned int i=0; i < Color::max; ++i) | 125 | for (unsigned int i = 0; Color::order[i] != Color::none; ++i) |
| 127 | { | 126 | { |
| 128 | #endif | 127 | #endif |
| 129 | bool connectionAvailable = tcpSrv->waitForNewConnection(-1); | 128 | bool connectionAvailable = tcpSrv->waitForNewConnection(-1); |
| @@ -132,7 +131,7 @@ void Server::waitForClientConnections() | |||
| 132 | connect(socket, SIGNAL(readyRead()), this, SLOT(keyPressUpdate())); | 131 | connect(socket, SIGNAL(readyRead()), this, SLOT(keyPressUpdate())); |
| 133 | 132 | ||
| 134 | // assign color | 133 | // assign color |
| 135 | Color::Color color = playerColors[i]; | 134 | Color::Color color = Color::order[i]; |
| 136 | m_clientConnections[color] = socket; | 135 | m_clientConnections[color] = socket; |
| 137 | // notify player of color | 136 | // notify player of color |
| 138 | ProtoBuf::WhoAmI packet; | 137 | ProtoBuf::WhoAmI packet; |
diff --git a/pacman-c++/server.h b/pacman-c++/server.h index 6ffbb35..8d73d24 100644 --- a/pacman-c++/server.h +++ b/pacman-c++/server.h | |||
| @@ -33,9 +33,9 @@ protected: | |||
| 33 | QSharedPointer<ProtoBuf::MapUpdate> createUpdatePacket(Transmission::map_t); | 33 | QSharedPointer<ProtoBuf::MapUpdate> createUpdatePacket(Transmission::map_t); |
| 34 | 34 | ||
| 35 | // update client maps | 35 | // update client maps |
| 36 | void sendUpdate(QSharedPointer< ProtoBuf::MapUpdate > ); | 36 | void sendUpdate(QSharedPointer<ProtoBuf::MapUpdate>); |
| 37 | 37 | ||
| 38 | QMap<Color::Color, QTcpSocket*> m_clientConnections; | 38 | QMap<Color::Color, QTcpSocket *> m_clientConnections; |
| 39 | 39 | ||
| 40 | // current movements. required to make pacmans continue their movement. | 40 | // current movements. required to make pacmans continue their movement. |
| 41 | QMap<Color::Color, Actor::Movement> m_actorMovements; | 41 | QMap<Color::Color, Actor::Movement> m_actorMovements; |
