From b2527a9eaa7082c50ce6230e79df88edbced9abb Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 15 Nov 2010 12:28:19 +0100 Subject: Implement server program flow around GameStart. --- server/game.cpp | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'server/game.cpp') diff --git a/server/game.cpp b/server/game.cpp index 13f2a18..e5a21b6 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -1,16 +1,41 @@ #include "game.h" +#include + #include +Game::p Game::create(Player::p player_1, Player::p player_2, Player::p player_3, Player::p player_4) { + Game::p p(new Game(player_1, player_2, player_3, player_4)); + p->start(); + return p; +} + Game::Game(Player::p player_1, Player::p player_2, Player::p player_3, Player::p player_4) { + players.push_back(player_1); + players.push_back(player_2); + players.push_back(player_3); + players.push_back(player_4); +} + +void Game::handle_ready() { + if(--waiting_players) { + return; + } + + std::cout << "All ready!" << std::endl; +} + +void Game::start() { std::cout << "Started a game with " - << player_1->nick() << ", " - << player_2->nick() << ", " - << player_3->nick() << " and " - << player_4->nick() << "." << std::endl; + << players[0]->nick() << ", " + << players[1]->nick() << ", " + << players[2]->nick() << " and " + << players[3]->nick() << "." << std::endl; + + waiting_players = 4; - player_1->game_start(); - player_2->game_start(); - player_3->game_start(); - player_4->game_start(); + players[0]->game_start(boost::bind(&Game::handle_ready, shared_from_this()), players); + players[1]->game_start(boost::bind(&Game::handle_ready, shared_from_this()), players); + players[2]->game_start(boost::bind(&Game::handle_ready, shared_from_this()), players); + players[3]->game_start(boost::bind(&Game::handle_ready, shared_from_this()), players); } -- cgit v1.2.3