From 6aff72b7de739af84bcd260e8682e6a394de8daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atle=20Hellvik=20Havs=C3=B8?= Date: Sat, 20 Nov 2010 20:29:53 +0100 Subject: Some changes to game. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Atle Hellvik Havsø --- server/game.cpp | 58 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/server/game.cpp b/server/game.cpp index 1806e25..cdfaf4f 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -60,7 +60,7 @@ void Game::round_start() { game_state.players[player_num].hand.push_back(wall.take_one()); } - current_player = 0; + current_player = 3; num_player_actions = 0; draw_phase = true; @@ -70,7 +70,24 @@ void Game::round_start() { void Game::round_update() { + if ( draw_phase ) { + + + + + if ( current_player == 3) { + current_player = 0; + } else { + current_player++; + } + #ifdef DEBUG + + std::cout << "Next players turn: " << current_player << std::endl; + + #endif + + // Is the wall empty? Then the round is over and we have a draw if (wall.is_done()) { round_end(); @@ -92,37 +109,46 @@ void Game::round_update() { // TODO // Add code for calculation of possible chi, pon, kan and ron. - - // Update who the current player is. - if ( current_player == 3) { - current_player = 0; - } else { - current_player++; - } } // Send RoundState, inkl. liste av mulige actions. - players[0]->round_state(game_state); - players[1]->round_state(game_state); - players[2]->round_state(game_state); - players[3]->round_state(game_state); - + for(int i = 0; i <= 3; i++) { + if ( i != current_player ) { + State send_state = game_state; + + send_state.possible_actions.clear(); + + players[i]->round_state(send_state); + } else { + players[i]->round_state(game_state); + #ifdef DEBUG + std::cout << "Waiting for action from player: " << i << std::endl; + #endif + } + } // Kall player->get_action(handle_action) for hver spiller som har actions, om ingen kan gjøre noe så blir // det neste spiller sin tur. + draw_phase = !draw_phase; if(num_player_actions) { - draw_phase = !draw_phase; players[current_player]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1)); } else { - draw_phase = true; round_update(); } } void Game::handle_action(Action action) { + + #ifdef DEBUG + + std::cout << "Player: " << action.player << " Did action: " << action.type << " On target: " << action.target << std::endl; + + + #endif + switch ( action.type ) { case Action::Pass: { @@ -179,8 +205,6 @@ void Game::handle_action(Action action) { if (num_player_actions == 0) { // TODO // Add code for when someone has done a chi, pon, ron and kan. - - round_update(); } } -- cgit v1.2.3