def create_game(request): game_name = request.POST.get('game_name') default_x = request.POST.get('default_x') default_y = request.POST.get('default_y') goal_x = request.POST.get('goal_x') goal_y = request.POST.get('goal_y') if not Game.get_game_by_game_name(game_name): game = Game.create_game(game_name, [], goal_x, goal_y) flag = Flag.create_flag(game_name, default_x, default_y) return HttpResponse(simplejson.dumps({}), mimetype="application/json")
def add_player(request, game_name): game = Game.get_game_by_game_name(game_name) if not game: raise Http404 player_name = request.POST.get('player_name') game.add_player_to_game(player_name) return HttpResponse(simplejson.dumps({}), mimetype="application/json")
def tag_nearest_player(request, player_name): player = Player.get_player_by_player_name(player_name) game_name = request.POST.get('game_name') game = Game.get_game_by_game_name(game_name) closest_player = None nearest = settings.TAG_RANGE for player_to_tag in game.player_list: if player_to_tag != player.player_name: distance = player.distance_to_player(player_to_tag) if distance < nearest: nearest = distance closest_player = player_to_tag if closest_player: player.tag_player(closest_player, game) return HttpResponse(simplejson.dumps({}), mimetype="application/json")
def get_game(request, game_name): game = Game.get_game_by_game_name(game_name) flag = Flag.get_flag_by_game_name(game_name) if not game or not flag: raise Http404 response_data = { 'game_name': game.game_name, 'goal_x': game.goal_x, 'goal_y': game.goal_y, 'is_active': game.is_active, 'players': game.player_list, 'flag_x': flag.location_x, 'flag_y': flag.location_y, 'flag_held_by': flag.held_by } return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")