diff options
| author | totycro <totycro@unknown-horizons.org> | 2011-04-10 01:31:55 +0200 |
|---|---|---|
| committer | totycro <totycro@unknown-horizons.org> | 2011-04-10 01:31:55 +0200 |
| commit | 0f111967d746b5d9d74f62ad5f1415ab156ff449 (patch) | |
| tree | 52b591bdb5d81c70cf49445dd71b26417544949c /pacman-c++ | |
| parent | 18ca65a550c25ed69dcf8b75e7b8862458e11025 (diff) | |
| download | foop-0f111967d746b5d9d74f62ad5f1415ab156ff449.tar.gz foop-0f111967d746b5d9d74f62ad5f1415ab156ff449.tar.bz2 foop-0f111967d746b5d9d74f62ad5f1415ab156ff449.zip | |
transmit game score
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/actor.cpp | 5 | ||||
| -rw-r--r-- | pacman-c++/actor.h | 8 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 46 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.h | 14 | ||||
| -rw-r--r-- | pacman-c++/pacman.proto | 6 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 20 | ||||
| -rw-r--r-- | pacman-c++/util.cpp | 4 |
7 files changed, 62 insertions, 41 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 51d3818..bd50a3c 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -11,7 +11,8 @@ static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal | |||
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | 13 | Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) |
| 14 | : PixmapItem(parent), m_color(color), m_direction(Actor::None), m_local(local) | 14 | : PixmapItem(parent), m_color(color), m_direction(Actor::None), m_local(local), |
| 15 | m_roundPoints(0), m_gamePoints(0) | ||
| 15 | { | 16 | { |
| 16 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); | 17 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); |
| 17 | /* DON'T set any pixmap here. we've a pixmap in the animation | 18 | /* DON'T set any pixmap here. we've a pixmap in the animation |
| @@ -186,7 +187,7 @@ bool Actor::isMoving() | |||
| 186 | } | 187 | } |
| 187 | 188 | ||
| 188 | void Actor::enqueue() | 189 | void Actor::enqueue() |
| 189 | { | 190 | { |
| 190 | if (isMoving()) | 191 | if (isMoving()) |
| 191 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); | 192 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); |
| 192 | } | 193 | } |
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h index 77a5b34..965d240 100644 --- a/pacman-c++/actor.h +++ b/pacman-c++/actor.h | |||
| @@ -33,6 +33,12 @@ public: | |||
| 33 | void die(); | 33 | void die(); |
| 34 | void eatingCherry(); | 34 | void eatingCherry(); |
| 35 | 35 | ||
| 36 | unsigned int getRoundPoints() { return m_roundPoints; } | ||
| 37 | unsigned int getGamePoints() { return m_gamePoints; } | ||
| 38 | |||
| 39 | void addRoundPoints(unsigned int amount) { m_roundPoints += amount; } | ||
| 40 | void finishRound() { m_gamePoints += m_roundPoints; m_roundPoints = 0; } | ||
| 41 | |||
| 36 | private slots: | 42 | private slots: |
| 37 | void enqueue(); | 43 | void enqueue(); |
| 38 | 44 | ||
| @@ -43,6 +49,8 @@ private: | |||
| 43 | PixmapItem m_icon; | 49 | PixmapItem m_icon; |
| 44 | bool m_local; | 50 | bool m_local; |
| 45 | 51 | ||
| 52 | unsigned int m_roundPoints, m_gamePoints; | ||
| 53 | |||
| 46 | QList<PixmapItem *> m_images; | 54 | QList<PixmapItem *> m_images; |
| 47 | QList<QSequentialAnimationGroup *> m_eating; | 55 | QList<QSequentialAnimationGroup *> m_eating; |
| 48 | QParallelAnimationGroup *m_moving; | 56 | QParallelAnimationGroup *m_moving; |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index b140871..c21e81d 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -65,6 +65,7 @@ void MainWidget::createGui() | |||
| 65 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); | 65 | window->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
| 66 | window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height); | 66 | window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height); |
| 67 | window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint); | 67 | window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint); |
| 68 | window->setFocusPolicy(Qt::NoFocus); | ||
| 68 | 69 | ||
| 69 | layout->addLayout(scoreLayout); | 70 | layout->addLayout(scoreLayout); |
| 70 | layout->addWidget(window); | 71 | layout->addWidget(window); |
| @@ -76,35 +77,27 @@ void MainWidget::createGui() | |||
| 76 | setLayout(layout); | 77 | setLayout(layout); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | void MainWidget::updateScore() | 80 | void MainWidget::updateScore(const ProtoBuf::MapUpdate& packet) |
| 80 | { | 81 | { |
| 81 | QMapIterator<Color::Color, Actor*> i(m_actors); | 82 | QLabel *turnPointsLbl; |
| 82 | while (i.hasNext()) | 83 | QLabel *allPointsLbl; |
| 83 | { | 84 | |
| 84 | i.next(); | 85 | turnPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(0)->itemAtPosition(0,1)->widget()); |
| 85 | if (i.key() > Color::max) | 86 | allPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(0)->itemAtPosition(1,1)->widget()); |
| 86 | { | 87 | turnPointsLbl->setText(QString::number(packet.round_points_red())); |
| 87 | /* player #4 isn't supported in score */ | 88 | allPointsLbl->setText(QString::number(packet.game_points_red())); |
| 88 | Q_ASSERT(false); | 89 | |
| 89 | continue; | 90 | turnPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(1)->itemAtPosition(0,1)->widget()); |
| 90 | } | 91 | allPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(1)->itemAtPosition(1,1)->widget()); |
| 91 | int id = (i.key() >> 1); | 92 | turnPointsLbl->setText(QString::number(packet.round_points_blue())); |
| 92 | QLabel *turnPointsLbl = | 93 | allPointsLbl->setText(QString::number(packet.game_points_blue())); |
| 93 | dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(0,1)->widget()); | 94 | |
| 94 | QLabel *allPointsLbl = | 95 | turnPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(2)->itemAtPosition(0,1)->widget()); |
| 95 | dynamic_cast<QLabel*>(m_playerScoreLayouts.at(id)->itemAtPosition(1,1)->widget()); | 96 | allPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(2)->itemAtPosition(1,1)->widget()); |
| 96 | turnPointsLbl->setText(QString::number(id)); | 97 | turnPointsLbl->setText(QString::number(packet.round_points_green())); |
| 97 | allPointsLbl->setText(QString::number(id)); | 98 | allPointsLbl->setText(QString::number(packet.game_points_green())); |
| 98 | } | ||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void MainWidget::updateMap(const Transmission::map_t& map) | ||
| 102 | { | ||
| 103 | SceneHolder::updateMap(map); | ||
| 104 | updateScore(); | ||
| 105 | } | ||
| 106 | |||
| 107 | |||
| 108 | Transmission::field_t MainWidget::translateKey(int key, int def) | 101 | Transmission::field_t MainWidget::translateKey(int key, int def) |
| 109 | { | 102 | { |
| 110 | switch(key) | 103 | switch(key) |
| @@ -166,6 +159,7 @@ void MainWidget::tick() | |||
| 166 | } | 159 | } |
| 167 | } | 160 | } |
| 168 | updateMap(map); | 161 | updateMap(map); |
| 162 | updateScore(packet); | ||
| 169 | } | 163 | } |
| 170 | } | 164 | } |
| 171 | 165 | ||
diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index 266f329..bd83d5f 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include "sceneholder.h" | 4 | #include "sceneholder.h" |
| 5 | #include "constants.h" | 5 | #include "constants.h" |
| 6 | #include "pixmapitem.h" | 6 | #include "pixmapitem.h" |
| 7 | #include "pacman.pb.h" | ||
| 7 | #include <QtGui> | 8 | #include <QtGui> |
| 8 | #include <QtCore> | 9 | #include <QtCore> |
| 9 | #include <QTcpSocket> | 10 | #include <QTcpSocket> |
| @@ -23,21 +24,18 @@ protected: | |||
| 23 | virtual void keyPressEvent(QKeyEvent* ); | 24 | virtual void keyPressEvent(QKeyEvent* ); |
| 24 | virtual void keyReleaseEvent(QKeyEvent* ); | 25 | virtual void keyReleaseEvent(QKeyEvent* ); |
| 25 | 26 | ||
| 26 | virtual void updateMap(const Transmission::map_t& map); | 27 | private slots: |
| 28 | void startGame(); | ||
| 29 | void playerScoreClicked(); | ||
| 30 | void tick(); | ||
| 27 | 31 | ||
| 28 | private: | 32 | private: |
| 29 | void createGui(); | 33 | void createGui(); |
| 30 | void createMenu(); | 34 | void createMenu(); |
| 31 | void updateScore(); | 35 | void updateScore(const ProtoBuf::MapUpdate&); |
| 32 | bool isRunning(); | 36 | bool isRunning(); |
| 33 | Color::Color connectToServer(); | 37 | Color::Color connectToServer(); |
| 34 | 38 | ||
| 35 | private slots: | ||
| 36 | void startGame(); | ||
| 37 | void playerScoreClicked(); | ||
| 38 | void tick(); | ||
| 39 | |||
| 40 | private: | ||
| 41 | // GUI elements needed in the progress of the game | 39 | // GUI elements needed in the progress of the game |
| 42 | QList<QGridLayout*> m_playerScoreLayouts; | 40 | QList<QGridLayout*> m_playerScoreLayouts; |
| 43 | 41 | ||
diff --git a/pacman-c++/pacman.proto b/pacman-c++/pacman.proto index ae8f966..129d07f 100644 --- a/pacman-c++/pacman.proto +++ b/pacman-c++/pacman.proto | |||
| @@ -6,6 +6,12 @@ message KeyPressUpdate { | |||
| 6 | 6 | ||
| 7 | message MapUpdate { | 7 | message MapUpdate { |
| 8 | repeated uint32 field = 1 [packed=true]; | 8 | repeated uint32 field = 1 [packed=true]; |
| 9 | required uint32 round_points_red = 2; | ||
| 10 | required uint32 round_points_green = 3; | ||
| 11 | required uint32 round_points_blue = 4; | ||
| 12 | required uint32 game_points_red = 5; | ||
| 13 | required uint32 game_points_green = 6; | ||
| 14 | required uint32 game_points_blue = 7; | ||
| 9 | } | 15 | } |
| 10 | 16 | ||
| 11 | message WhoAmI { | 17 | message WhoAmI { |
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 7e467e5..0a84561 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -52,8 +52,11 @@ Transmission::map_t Server::calculateUpdates() | |||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | // <t3h g4m3 10gic> | 54 | // <t3h g4m3 10gic> |
| 55 | if(dynamic_cast<Block*>(visualMap[newMapPosition.x()][newMapPosition.y()]) != 0) { | 55 | if (0 <= newMapPosition.x() && newMapPosition.x() < visualMap.size() && |
| 56 | continue; | 56 | 0 <= newMapPosition.y() && newMapPosition.y() < visualMap[newMapPosition.x()].size()) { |
| 57 | if(dynamic_cast<Block*>(visualMap[newMapPosition.x()][newMapPosition.y()]) != 0) { | ||
| 58 | continue; | ||
| 59 | } | ||
| 57 | } | 60 | } |
| 58 | // </t3h g4m2 10gic> | 61 | // </t3h g4m2 10gic> |
| 59 | 62 | ||
| @@ -75,6 +78,12 @@ QSharedPointer< ProtoBuf::MapUpdate > Server::createUpdatePacket(Transmission::m | |||
| 75 | updatePacket->add_field(map[x][y]); | 78 | updatePacket->add_field(map[x][y]); |
| 76 | } | 79 | } |
| 77 | } | 80 | } |
| 81 | updatePacket->set_round_points_red(m_actors.value(Color::red)->getRoundPoints()); | ||
| 82 | updatePacket->set_game_points_red(m_actors.value(Color::red)->getGamePoints()); | ||
| 83 | updatePacket->set_round_points_green(m_actors.value(Color::green)->getRoundPoints()); | ||
| 84 | updatePacket->set_game_points_green(m_actors.value(Color::green)->getGamePoints()); | ||
| 85 | updatePacket->set_round_points_blue(m_actors.value(Color::blue)->getRoundPoints()); | ||
| 86 | updatePacket->set_game_points_blue(m_actors.value(Color::blue)->getGamePoints()); | ||
| 78 | //qDebug() << "field sz "<< updatePacket->field_size(); | 87 | //qDebug() << "field sz "<< updatePacket->field_size(); |
| 79 | return updatePacket; | 88 | return updatePacket; |
| 80 | } | 89 | } |
| @@ -85,9 +94,14 @@ void Server::waitForClientConnections() | |||
| 85 | // server must stay alive as long as sockets (qt parent mem mechanism) | 94 | // server must stay alive as long as sockets (qt parent mem mechanism) |
| 86 | tcpSrv->listen(QHostAddress::Any, Constants::port); | 95 | tcpSrv->listen(QHostAddress::Any, Constants::port); |
| 87 | 96 | ||
| 97 | #define SINGLE | ||
| 98 | |||
| 88 | Color::Color playerColors[3] = { Color::red, Color::blue, Color::green }; | 99 | Color::Color playerColors[3] = { Color::red, Color::blue, Color::green }; |
| 89 | //for (unsigned int i=0; i<Color::max; ++i) { | 100 | #ifdef SINGLE |
| 90 | for (unsigned int i=0; i<1; ++i) { | 101 | for (unsigned int i=0; i<1; ++i) { |
| 102 | #else | ||
| 103 | for (unsigned int i=0; i<Color::max; ++i) { | ||
| 104 | #endif | ||
| 91 | bool connectionAvailable = tcpSrv->waitForNewConnection(-1); | 105 | bool connectionAvailable = tcpSrv->waitForNewConnection(-1); |
| 92 | Q_ASSERT(connectionAvailable); | 106 | Q_ASSERT(connectionAvailable); |
| 93 | QTcpSocket *socket = tcpSrv->nextPendingConnection(); | 107 | QTcpSocket *socket = tcpSrv->nextPendingConnection(); |
diff --git a/pacman-c++/util.cpp b/pacman-c++/util.cpp index ceba2b8..23826f7 100644 --- a/pacman-c++/util.cpp +++ b/pacman-c++/util.cpp | |||
| @@ -67,8 +67,8 @@ namespace Util { | |||
| 67 | 67 | ||
| 68 | map[0][0] |= Transmission::bonuspoint; | 68 | map[0][0] |= Transmission::bonuspoint; |
| 69 | map[1][0] |= Color::red | Transmission::pacman | Transmission::direction_right; | 69 | map[1][0] |= Color::red | Transmission::pacman | Transmission::direction_right; |
| 70 | //map[2][0] |= Color::blue | Transmission::pacman | Transmission::direction_up; | 70 | map[23][0] = Color::blue | Transmission::pacman | Transmission::direction_none; |
| 71 | //map[3][0] |= Color::green | Transmission::pacman | Transmission::direction_down; | 71 | map[24][0] = Color::green | Transmission::pacman | Transmission::direction_none; |
| 72 | 72 | ||
| 73 | /* auto place normal points*/ | 73 | /* auto place normal points*/ |
| 74 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) | 74 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) |
