From b6fec20dadaf71fc28961a4a6d720d1d665508e8 Mon Sep 17 00:00:00 2001 From: totycro Date: Tue, 19 Apr 2011 19:48:26 +0200 Subject: Added number of rounds parameter (unused) --- pacman-c++/server.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'pacman-c++/server.cpp') diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 07e4c72..4051807 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp @@ -11,7 +11,7 @@ Server::Server(QWidget *parent) : SceneHolder(parent), m_bindaddress(QHostAddress::Any), - m_port(Constants::Networking::port), m_numbots(0) + m_port(Constants::Networking::port), m_rounds(3), m_numbots(0), m_curRound(0) { /* determine max players by using order array */ for(m_maxplayers = 0; Color::order[m_maxplayers] != Color::none; ++m_maxplayers); @@ -26,6 +26,7 @@ bool Server::run() qDebug() << "[Server] Running server..."; qDebug() << "[Server] Max players:" << m_maxplayers; + qDebug() << "[Server] Number of rounds:" << m_rounds; qDebug() << "[Server] Number of bots:" << m_numbots; if (!waitForClientConnections()) return false; @@ -535,6 +536,10 @@ bool Server::parseCommandline() out << " --nocolorblocks" << endl << " Disable random colorized blocks" << endl << endl; + opt.setOption("rounds", 'r'); + out << " -r, --rounds [1..n]" << endl + << " Number of rounds to play" << endl + << endl; opt.setFlag("nocolorblocks"); out << " -h, --help" << endl << " Prints this help message" << endl; @@ -603,6 +608,18 @@ bool Server::parseCommandline() m_numbots = numbots; } + if (opt.getValue("rounds") != NULL) + { + bool ok; + unsigned int rounds = QString(opt.getValue("rounds")).toUInt(&ok); + if (!ok || rounds == 0) + { + qCritical() << "Invalid number of rounds: " << opt.getValue("rounds") << endl; + return false; + } + m_rounds = rounds; + } + this->setProperty("coloredblocks", !opt.getFlag("nocolorblocks")); return true; -- cgit v1.2.3 From eaf133fd08c9708fe718ef47451bed7ea803a46a Mon Sep 17 00:00:00 2001 From: totycro Date: Tue, 19 Apr 2011 21:56:37 +0200 Subject: Added rounds rounds will end when all points are removed TODO: end round when a pacman gets eaten --- pacman-c++/server.cpp | 115 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 93 insertions(+), 22 deletions(-) (limited to 'pacman-c++/server.cpp') diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 4051807..3cb422b 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp @@ -31,30 +31,20 @@ bool Server::run() if (!waitForClientConnections()) return false; - qDebug() << "[Server] Creating map..."; - Transmission::map_t map = Util::createDemoMap(); - Util::placeActors(map, m_maxplayers, Color::order); - Util::fillPoints(map); + initRoundMap(true); - /* save positions of blocks for later usage */ - for (unsigned int x = 0; x < Constants::map_size.width; ++x) - { - for (unsigned int y = 0; y < Constants::map_size.height; ++y) - { - Transmission::field_t &cur = map[x][y]; - if (cur & Transmission::block) - m_blocks.append(QPoint(x, y)); - } - } + m_tickTimer = new QTimer(this); + connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); + m_tickTimer->start(Constants::tick); - updateMap(map); - sendUpdate(map, true); - Util::deleteMap(map); - map = NULL; + /* finish round every 3 sec + QTimer *timer2 = new QTimer(this); + connect(timer2, SIGNAL(timeout()), this, SLOT(onRoundFinished())); + timer2->start(3000); + / */ + + connect(this, SIGNAL(allPointsRemoved()), SLOT(onRoundFinished())); - QTimer *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(tick())); - timer->start(Constants::tick); return true; } @@ -109,7 +99,6 @@ invalid_direction: // // TODO: support actors eating each other - // TODO: old item - REMOVE THAT? GameEntity *oldItem = visualMap[mapPosition.x()][mapPosition.y()]; /* check if there's an item at new location of actor */ @@ -501,6 +490,88 @@ void Server::keyPressUpdate() } } +void Server::onRoundFinished() +{ + foreach(Actor *actor, m_actors) { + actor->finishRound(); + } + + initRoundMap(); + ++m_curRound; + + if(m_curRound >= m_rounds) { + // end of game + m_tickTimer->stop(); + } +} + +void Server::initRoundMap(bool firstPacket) +{ + qDebug() << endl; + qDebug() << endl; + qDebug() << "[Server] Creating map..."; + qDebug() << endl; + qDebug() << endl; + qDebug() << endl; + + disconnect(this, SIGNAL(allPointsRemoved()), this, SLOT(onRoundFinished())); + if (!firstPacket) { + // clear old map + for (unsigned int i=0; i(e) == NULL) { + removeItem(e); + delete e; + } + } + visualMap[i][j] = 0; + } + } + } + + // create new map + Transmission::map_t map = Util::createDemoMap(); + // add content + Util::placeActors(map, m_maxplayers, Color::order); + /* + if (!firstPacket) { + for (unsigned int i=0; i(map[i][j] & Transmission::color_mask); + Actor *actor = m_actors.value(color, NULL); + qDebug() << "setting actor to " << i << j << mapPositionToCoord(i, j); + actor->setPos(mapPositionToCoord(i, j)); + } + } + } + } + */ + + Util::fillPoints(map); + + /* save positions of blocks for later usage */ + m_blocks.clear(); + for (unsigned int x = 0; x < Constants::map_size.width; ++x) + { + for (unsigned int y = 0; y < Constants::map_size.height; ++y) + { + Transmission::field_t &cur = map[x][y]; + if (cur & Transmission::block) + m_blocks.append(QPoint(x, y)); + } + } + + updateMap(map); + sendUpdate(map, firstPacket); + Util::deleteMap(map); + map = NULL; + + connect(this, SIGNAL(allPointsRemoved()), this, SLOT(onRoundFinished())); +} + bool Server::parseCommandline() { AnyOption opt; -- cgit v1.2.3 From ad0db492c213302a627bb4190458ae66834e82d7 Mon Sep 17 00:00:00 2001 From: totycro Date: Tue, 19 Apr 2011 22:01:41 +0200 Subject: removed some debug output --- pacman-c++/server.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'pacman-c++/server.cpp') diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 3cb422b..cc69f08 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp @@ -507,13 +507,6 @@ void Server::onRoundFinished() void Server::initRoundMap(bool firstPacket) { - qDebug() << endl; - qDebug() << endl; - qDebug() << "[Server] Creating map..."; - qDebug() << endl; - qDebug() << endl; - qDebug() << endl; - disconnect(this, SIGNAL(allPointsRemoved()), this, SLOT(onRoundFinished())); if (!firstPacket) { // clear old map -- cgit v1.2.3 From 7a5e71759c00b2c77f7ee3287c366dd1b48b81ca Mon Sep 17 00:00:00 2001 From: totycro Date: Tue, 19 Apr 2011 22:16:06 +0200 Subject: don't always call setPos --- pacman-c++/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pacman-c++/server.cpp') diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index cc69f08..1c3caf9 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp @@ -41,7 +41,7 @@ bool Server::run() QTimer *timer2 = new QTimer(this); connect(timer2, SIGNAL(timeout()), this, SLOT(onRoundFinished())); timer2->start(3000); - / */ + // */ connect(this, SIGNAL(allPointsRemoved()), SLOT(onRoundFinished())); -- cgit v1.2.3