def finish(request): def pick_winner(context): if context['player'].hand.value > 21: context['winner'] = "Dealer" elif context['dealer'].hand.value > 21: context['winner'] = context['player'].user.username elif context['player'].hand.value == context['dealer'].hand.value: context['winner'] = "Dealer" elif context['player'].hand.value < context['dealer'].hand.value: context['winner'] = "Dealer" else: context['winner'] = context['player'].user.username return context context = {} if request.POST: return HttpResponseBadRequest("Please do not post") else: context = get_dealer(request, context) while context['dealer'].hand.value < 17: context['dealer'].hand.add_card(C.generate_card()) context['dealer'].hand.save() context['dealer'].save() context = pick_winner(context) if context['winner'] == "Dealer": context['player'].lose() else: context['player'].win() return render("final.html", context, context_instance=RequestContext(request))
def finish(request): def pick_winner(context): if context['player'].hand.value > 21: context['winner'] = "Dealer" elif context['dealer'].hand.value > 21: context['winner'] = context['player'].user.username elif context['player'].hand.value == context['dealer'].hand.value: context['winner'] = "Dealer" elif context['player'].hand.value < context['dealer'].hand.value: context['winner'] = "Dealer" else: context['winner'] = context['player'].user.username return context context = {} if request.POST: return HttpResponseBadRequest("Please do not post") else: context = get_dealer(request, context) while context['dealer'].hand.value < 17: context['dealer'].hand.add_card(C.generate_card()) context['dealer'].hand.save() context['dealer'].save() context = pick_winner(context) if context['winner'] == "Dealer": context['player'].lose() else: context['player'].win() return render("final.html", context, context_instance=RequestContext(request))
def playing(request, template="running_game.html"): context = {} if request.POST: return HttpResponseBadRequest("Please do not post") else: context = get_dealer(request, context) return render(template, context, context_instance=RequestContext(request))
def playing(request, template="running_game.html"): context = {} if request.POST: return HttpResponseBadRequest("Please do not post") else: context = get_dealer(request, context) return render(template, context, context_instance=RequestContext(request))
def start_game(request): context = {} if request.POST: return HttpResponseBadRequest("Please do not post") else: context = get_dealer(request, context) hand = Hand() hand.add_card(C.generate_card()) hand.add_card(C.generate_card()) hand.save() context['player'].hand = hand context['player'].save() dealhand = Hand() dealhand.add_card(C.generate_card()) dealhand.save() context['dealer'].hand = dealhand context['dealer'].save() print context['dealer'].hand return HttpResponseRedirect('/game/playing')
def start_game(request): context = {} if request.POST: return HttpResponseBadRequest("Please do not post") else: context = get_dealer(request, context) hand = Hand() hand.add_card(C.generate_card()) hand.add_card(C.generate_card()) hand.save() context['player'].hand = hand context['player'].save() dealhand = Hand() dealhand.add_card(C.generate_card()) dealhand.save() context['dealer'].hand = dealhand context['dealer'].save() print context['dealer'].hand return HttpResponseRedirect('/game/playing')