diff options
Diffstat (limited to 'server/game.cpp')
-rw-r--r-- | server/game.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/server/game.cpp b/server/game.cpp index 3548e13..49cfb0b 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -4,6 +4,7 @@ #include <iostream> #include <algorithm> +#include <ctime> bool MyDataSortPredicate(const Tile& d1, const Tile& d2) { @@ -63,6 +64,13 @@ void Game::round_start() { game_state.players[player_num].hand.push_back(wall.take_one()); } + std::sort(game_state.players[0].hand.begin(),game_state.players[0].hand.end(), MyDataSortPredicate); + std::sort(game_state.players[1].hand.begin(),game_state.players[1].hand.end(), MyDataSortPredicate); + std::sort(game_state.players[2].hand.begin(),game_state.players[2].hand.end(), MyDataSortPredicate); + std::sort(game_state.players[3].hand.begin(),game_state.players[3].hand.end(), MyDataSortPredicate); + + + current_player = 3; num_player_actions = 0; draw_phase = true; @@ -74,12 +82,24 @@ void Game::round_update() { // We're in the draw_phase whenever a player draws a tile from the wall if(draw_phase) { + // If the wall is empty (Contains only 14 tiles) when we enter draw phase the round is over. + if(wall.is_done()) { + round_end(); + } + // Since we've entered the draw-phase it's the next players turn if (current_player == 3) { current_player = 0; } else { current_player++; } + + #ifdef DEBUG + + time_t current_time = std::time(0); + std::cout << std::ctime(¤t_time) << " - Waiting for action from player: " << current_player << std::endl; + + #endif // Let's take a tile Tile from_wall = wall.take_one(); @@ -126,9 +146,12 @@ void Game::round_update() { void Game::handle_action(Action action) { + players[action.player]->kill_action(); + #ifdef DEBUG - std::cout << "Player: " << action.player << " Did action: " << action.type << " On target: " << action.target << std::endl; + time_t current_time = std::time(0); + std::cout << std::ctime(¤t_time) << " Player: " << action.player << " Did action: " << action.type << " On target: " << action.target << std::endl; #endif @@ -234,6 +257,17 @@ void Game::handle_action(Action action) { void Game::round_end() { // Flere runder? round_start() // Ferdig? game_end() + players[0]->round_end(); + players[1]->round_end(); + players[2]->round_end(); + players[3]->round_end(); + + #ifdef DEBUG + + time_t current_time = std::time(0); + std::cout << std::ctime(¤t_time) << " Round is over..." << std::endl; + + #endif } void Game::start() { |