summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-11-19 17:53:23 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-11-19 17:53:23 +0100
commitb05d9ebf933665343892fb985ab3466181f92ab3 (patch)
tree3b516345b3a227d77efe18603af977769d0565bd
parentcad0ae2d88e74cc48bf62f872128d737013bbac2 (diff)
Outline of program flow in Game class.
-rw-r--r--server/game.cpp45
-rw-r--r--server/game.h7
2 files changed, 52 insertions, 0 deletions
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<State>();
+
+ 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 <vector>
#include "player.h"
+#include "../common/action.h"
class Game : public boost::enable_shared_from_this<Game> {
public:
@@ -14,6 +15,8 @@ class Game : public boost::enable_shared_from_this<Game> {
static p create(Player::p player_1, Player::p player_2, Player::p player_3, Player::p player_4);
+ ~Game();
+
private:
std::vector<Player::p> players;
@@ -27,6 +30,10 @@ class Game : public boost::enable_shared_from_this<Game> {
//! Start the game.
void start();
+ void round_start();
+ void round_update();
+ void handle_action(Action action);
+ void round_end();
};
#endif