def send_group_the_phase(game, phase): '''Sends each player in the game the current phase Arguments: game: the game database entry phase: the current game phase ''' game_transmit(Group(game.group_channel), {"game_phase": phase})
def send_players_discard(tt, player, discard): '''Sends a message to each player telling them which cards are theirs''' discard_json = str(discard) game_transmit( Group(tt.game_round.game.group_channel), {"discard": { "player": player.position, "card": discard_json }})
def start(game): '''Starts the game Arguments: game: the game database entry ''' game.active = True game_transmit(Group(game.group_channel), {"enter_room": None}) game.save() add_round(game)
def send_pass_round_started(group_channel, pass_round_id, num_cards_to_pass, phase): now = timezone.now() time_info = game_round.get_time_info(now, PASS_ROUND_TIMEOUT_MS) game_transmit( Group(group_channel), { "pass_round_started": { "id": pass_round_id, "cards_to_pass": num_cards_to_pass, "game_phase": phase, "time_info": time_info } })
def send_turn_notification(tt): player = tt.game_round.game.player_set.get(position=tt.expected_seat) if tt.expected_seat == tt.first_seat: valid_cards = valid_cards_leader(tt, player.hand) else: valid_cards = valid_cards_follower(tt, player.hand) game_transmit(Channel(player.channel), {"your_turn": tt.id}) current_time_ms = ( datetime.datetime.now() - datetime.datetime.utcfromtimestamp(0)).total_seconds() * 1000 time_info = [current_time_ms, 5000, player.bank_ms] game_transmit(Channel(player.channel), {"time_info": time_info}) grrz.send_player_valid_cards(tt.game_round, player, valid_cards) send_delay_message(tt, player, tt.id, valid_cards)
def send_players_score(game): '''Sends a message to each player telling them the scores Note: this is only updated after each hand Arguments: game: the game database entry ''' score_list = [] for player in game.player_set.all(): score_list.append(str(player.game_points)) game_transmit( Group(game.group_channel), {"scores": { "player": player.position, "score_list": score_list }})
def add_player(game, player, group): '''Adds the given player to the given game and group Arguments: game: the game database entry player: the player database entry group: the group channel to add the player to ''' game_transmit(Channel(player.channel), {'id': str(game.id)}) player.enrolled_game = game player.position = len( game.player_set.all()) #no -1 because didn't save yet game_transmit(Channel(player.channel), {"player_pos": player.position}) player.save() Group(group).add(Channel(player.channel)) logging.info('Game %s has %s players', game.id, 'has', game.player_set.all().count(), 'players')
def send_turn_notification(tt): player = tt.game_round.game.player_set.get(position=tt.expected_seat) if tt.expected_seat == tt.first_seat: valid_cards = valid_cards_leader(tt,player.hand) else: valid_cards = valid_cards_follower(tt,player.hand) grrz.send_player_valid_cards(tt.game_round, player, valid_cards) now = timezone.now() time_info = grrz.get_time_info(now, TRICK_BASE_MS, player.bank_ms) game_transmit(Group(tt.game_round.game.group_channel), { 'trick':{ 'id':tt.id, 'player':player.position, 'time_info':time_info, 'game_phase':tt.game_round.phase } }) player.time_turn_started = now player.save() send_delay_message(tt, player, tt.id, valid_cards)
def add_player(game, player, group): '''Adds the given player to the given game and group Arguments: game: the game database entry player: the player database entry group: the group channel to add the player to ''' player.enrolled_game = game player.position = len( game.player_set.all()) #no -1 because didn't save yet player.save() Group(group).add(Channel(player.channel)) game_transmit( Channel(player.channel), { 'enter_room': { 'id': str(game.id), 'player_pos': player.position, 'game_phase': GamePhases.BEFORE_GAME, 'player_id': player.id } }) logging.info('Game %s has %s players', game.id, 'has', game.player_set.all().count(), 'players')
def send_player_valid_cards(gr, player, valid_cards): cards_str = Card.list_to_str(valid_cards) game_transmit(Channel(player.channel), {"valid_cards": cards_str})
def send_players_their_cards(gr): '''Sends a message to each player telling them which cards are theirs''' for player in gr.game.player_set.all(): cards_str = Card.list_to_str(player.hand) game_transmit(Channel(player.channel), {"Cards": cards_str})
def send_turn_notification(pr): game_transmit(Group(pr.game_round.game.group_channel), {"your_turn": pr.id})