summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorAtle Hellvik Havsø <atle@havso.net>2010-11-20 12:18:25 +0100
committerAtle Hellvik Havsø <atle@havso.net>2010-11-20 12:18:25 +0100
commit6caa3da6a2da23fe8cd8e8fdc8074a1022a00163 (patch)
tree0ad9409451dcd4d0cb7d710b344f5847a0dddf56 /server
parentb3e9ace28566e0572885b04924e2183c587369e7 (diff)
Wait for action from player 0 (East) at the start of a round.
Signed-off-by: Atle Hellvik Havsø <atle@havso.net>
Diffstat (limited to 'server')
-rw-r--r--server/game.cpp37
-rw-r--r--server/game.h7
2 files changed, 40 insertions, 4 deletions
diff --git a/server/game.cpp b/server/game.cpp
index 3f34d07..3c695c4 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -42,6 +42,13 @@ void Game::round_start() {
// Sett opp runden
game_state = make_shared<State>();
+ east_action = false;
+ west_action = false;
+ south_action = false;
+ north_action = false;
+
+ num_player_actions = 0;
+
// Simulates drawing 4, 4 ,4 for each player
for (int player_num = 0; player_num < 4; player_num++) {
for (int i = 0; i < 3; i++) {
@@ -59,7 +66,13 @@ void Game::round_start() {
// Gives an extra tile to the first player (east)
game_state->players[0].hand.push_back(wall.take_one());
-
+ // Set the action that east can do.
+ Action discard;
+ discard.type = Action::Discard;
+ game_state->possible_actions.push_back(discard);
+
+ east_action = true;
+ num_player_actions++;
round_update();
}
@@ -72,16 +85,32 @@ void Game::round_update() {
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));
+ if (east_action) {
+ players[0]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ }
+
+ if (west_action) {
+ players[1]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ }
+
+ if (south_action) {
+ players[2]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ }
+
+ if (north_action) {
+ players[3]->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();
+ if (num_player_actions == 0) {
+ round_update();
+ }
}
void Game::round_end() {
diff --git a/server/game.h b/server/game.h
index dc3a9ff..634ea4d 100644
--- a/server/game.h
+++ b/server/game.h
@@ -31,6 +31,13 @@ class Game : public boost::enable_shared_from_this<Game> {
//! The current state of the game
State::p game_state;
+ int num_player_actions;
+
+ bool east_action;
+ bool west_action;
+ bool south_action;
+ bool north_action;
+
//! Handle Ready message from player.
void handle_ready();