def begin_puzzle_game(request): match = Match.objects.get(id=request.session['match']) game = cached.get_game(match.id) if request.user.is_authenticated(): player_name = request.user.username else: player_name = game_master.ANON_PLAYER_NAME hand = game_master.draw_up_to(game, player_name, 5) # init puzzle life game['players'][player_name]['life'] = match.puzzle.player_life # puzzle starting units starting_units = PuzzleStartingUnit.objects.filter(puzzle=match.puzzle) for starting_unit in starting_units: game_master.play(game, 'ai', starting_unit.unit_card.pk, 'ai', starting_unit.location.row, starting_unit.location.x, ignore_hand=True) cached.save(game) censored = game_master.get_censored(game, player_name) return HttpResponse(simplejson.dumps(censored), "application/javascript")
def end_turn(request): # grab game info match_id = request.session['match'] game = cached.get_game(match_id) # get player's actions from requests player_moves = request.POST.get("player_turn").strip().split('\n') if not player_moves: player_moves = ["pass %s" % game['player'], "pass %s" % game['player']] # process the game turn and get data to give back to client hand_and_turn_json = game_master.do_turns(game, player_moves) # did the game end this turn? winner = game_master.is_game_over(game) if winner: match = Match.objects.get(id=match_id) logging.info("))))) trying to set winner: %s for %s" % (winner, match.puzzle)) if match.puzzle: if request.user.is_authenticated(): request.user.get_profile().beaten_puzzle_ids.append(match.puzzle.id) request.user.get_profile().save() match.winner = winner return HttpResponse("game over, winner: %s" % winner) # send appropriate hand & AI info back to client return HttpResponse(hand_and_turn_json, "application/javascript")
def begin_ai_game(request): match = Match.objects.get(id=request.session["match"]) game = cached.get_game(match.id) if request.user.is_authenticated(): player_name = request.user.username else: player_name = game_master.ANON_PLAYER_NAME hand = game_master.draw_up_to(game, player_name, 5) cached.save(game) censored = game_master.get_censored(game, player_name) game = cached.get_game(match.id) return HttpResponse(simplejson.dumps(censored), "application/javascript")