def blackjack(self): player = self.player amount = Decimal('1.5') * self.bet player.credit(amount) player.update_balance(self.round.table_id, str(amount)) self.resolve() data = {'player_id': self.player_id, 'name': player.name } client = Client(data=data, table_id=self.round.table_id, action='blackjack') client.notify()
def deal_dealer_cards(self): """ Hand is over, deal dealer cards, Send the client data for the dealers down card, and call 'flip_down_card()' there """ dealer_hand = self.current_round.dealers_hand data = dealer_hand.get_cards() client = Client(data=data[0], table_id=self.id, action='flip_down_card') client.notify() #only deal if it is if BlackJackHand.objects.filter(round=self.current_round, resolved=False, dealers_hand=False): while (dealer_hand.score < 17) and (not dealer_hand.busted): time.sleep(.7) new_card = self.pull_card() dealer_hand.add_card(new_card) self.game_state = consts.GAME_STATE_BIDDING self.save() self.update_game() self.resolve_bets()
def create(self, request, table_id, response): """ Send a chat message to your table API Handler: POST /table/{id}/chat PARAMS: @message [string] Text of the message you want to send """ player = request.user.get_profile() message = request.POST.get('message') if not message: return response.send(errors="Provide a message to send") try: Seat.objects.get(table__id=table_id, player=player) except Seat.DoesNotExist: return response.send(errors="You aren't sitting at that table", status=500) data = {'message': message, 'from_id': player.id, 'from_name': player.name} client = Client(data=data, table_id=table_id, action='chat') client.notify() return response.send()
def add_card(self, card): cards = self.get_cards() cards.append(card) self.set_cards(cards) if self.can_split: actions = self.get_available_actions() actions.append('split') self.set_available_actions(actions) self.save() #augment the card data for client if self.dealers_hand: card['dealt_to'] = 'dealer' else: if self.split_from.all().count(): card['split_card'] = True player_id = self.player_id card['dealt_to'] = player_id if (self.dealers_hand and self.num_cards == 1): card.update(Card.get_face_down()) client = Client(data=card, table_id=self.round.table_id, action='deal_card') client.notify()
def update_balance(self, table_id, balance_change): data = {'balance': self.pretty_balance, 'balance_change': balance_change} client = Client(data=data, table_id=table_id, player_id=self.id, action='update_balance') client.notify()
def update_game(self): data = self.get_game_data() client = Client(data=data, table_id=self.id, action='update_game') client.notify()