From b05d9ebf933665343892fb985ab3466181f92ab3 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Fri, 19 Nov 2010 17:53:23 +0100 Subject: Outline of program flow in Game class. --- server/game.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ server/game.h | 7 +++++++ 2 files changed, 52 insertions(+) (limited to 'server') diff --git a/server/game.cpp b/server/game.cpp index e5a21b6..346251e 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -10,6 +10,10 @@ Game::p Game::create(Player::p player_1, Player::p player_2, Player::p player_3, return p; } +Game::~Game() { + std::cout << "Game destroyed." << std::endl; +} + 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); @@ -18,11 +22,52 @@ Game::Game(Player::p player_1, Player::p player_2, Player::p player_3, Player::p } void Game::handle_ready() { + std::cout << "Still waiting for " << waiting_players << "." << std::endl; + if(--waiting_players) { return; } std::cout << "All ready!" << std::endl; + + round_start(); +} + +void Game::round_start() { + players[0]->round_start(); + players[1]->round_start(); + players[2]->round_start(); + players[3]->round_start(); + + // Sett opp runden + + round_update(); +} + +void Game::round_update() { + // Send RoundState, inkl. liste av mulige actions. + State::p game_state = make_shared(); + + players[0]->round_state(game_state); + players[1]->round_state(game_state); + players[2]->round_state(game_state); + players[3]->round_state(game_state); + + // Kall player->get_action(handle_action) for hver spiller som har actions + players[0]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1)); +} + +void Game::handle_action(Action action) { + // Sjekk action, sjekk om endelig action er avgjort + // Oppdater state + // Evt. round_end() + + round_update(); +} + +void Game::round_end() { + // Flere runder? round_start() + // Ferdig? game_end() } void Game::start() { diff --git a/server/game.h b/server/game.h index 00da0bc..39e02f8 100644 --- a/server/game.h +++ b/server/game.h @@ -7,6 +7,7 @@ #include #include "player.h" +#include "../common/action.h" class Game : public boost::enable_shared_from_this { public: @@ -14,6 +15,8 @@ class Game : public boost::enable_shared_from_this { static p create(Player::p player_1, Player::p player_2, Player::p player_3, Player::p player_4); + ~Game(); + private: std::vector players; @@ -27,6 +30,10 @@ class Game : public boost::enable_shared_from_this { //! Start the game. void start(); + void round_start(); + void round_update(); + void handle_action(Action action); + void round_end(); }; #endif -- cgit v1.2.3