Ejemplo n.º 1
0
 def test_jokers(self):
     expected = 'a joker'
     for joker in ['joker1', 'joker2']:
         assert card_text_from_id(joker) == expected
Ejemplo n.º 2
0
 def test_ace_of_hearts(self):
     expected = 'the ace of hearts'
     assert card_text_from_id('bd4b01946d') == expected
Ejemplo n.º 3
0
 def test_three_of_spades(self):
     expected = 'the three of spades'
     assert card_text_from_id('04f17d1351') == expected
Ejemplo n.º 4
0
 def test_jack_of_diamonds(self):
     expected = 'the jack of diamonds'
     assert card_text_from_id('1d5eb77128') == expected
Ejemplo n.º 5
0
def peg_round_action(msg):
    """
    Handles the playing of a card as well as passing on playing
    :param message:
    :return:
    """
    if 'card_played' in msg.keys():
        total = bev.get_pegging_total(msg['game'])
        if bev.get_card_value(msg['game'], msg['card_played']) > (31 - total):
            emit('invalid_card', {'card': msg['card_played']})
            return

        if msg['player'] != bev.get_current_turn(msg['game']):
            emit('invalid_card', {'card': msg['card_played']})
            return

        just_won, points_scored, points_source = bev.score_play(
            msg['game'], msg['player'], msg['card_played'])

        new_total = bev.record_play(msg['game'], msg['player'],
                                    msg['card_played'])
        card_text = card_text_from_id(msg['card_played'])
        message = '{} played {}. <b>({})</b>'.format(msg['player'], card_text,
                                                     new_total)

        emit('new_message', {
            'type': 'action',
            'data': message
        },
             room=msg['game'])
        emit('show_card_played', {
            'nickname': msg['player'],
            'card': msg['card_played']
        },
             room=msg['game'])

        if points_scored > 0:
            reason = ', '.join(ps for ps in sorted(points_source))
            award_points(msg['game'], msg['player'], points_scored, reason,
                         just_won)
        if just_won:
            return

    else:
        bev.record_pass(msg['game'], msg['player'])
        emit('new_message', {
            'type': 'action',
            'data': '{} passed.'.format(msg['player'])
        },
             room=msg['game'])

    next_player, go_point_wins = bev.next_player(msg['game'])
    if go_point_wins:
        return
    next_action = bev.get_player_action(msg['game'], next_player)
    if next_action == 'SCORE':
        emit('new_message', {
            'type':
            'chat',
            'data':
            "Time to score everyone's hand! {} goes first.".format(
                next_player),
            'nickname':
            'cribby'
        },
             room=msg['game'])

    emit('send_turn', {
        'player': next_player,
        'action': next_action
    },
         room=msg['game'])