Exemple #1
0
def recipient(request, provided_id):
    if request.method == 'GET':
        return HttpResponse(json.dumps(Recipient.getRecipient(provided_id), default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")
                     
    elif request.method == 'PUT' or request.method == 'POST':
        return HttpResponse(json.dumps(Recipient.updateRecipient(provided_id, json.loads(request.raw_post_data)), default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")
Exemple #2
0
def waiting_room(request, user_id):
    # are we done waiting?
    player = Recipient.getRecipient(user_id)
    return HttpResponse(json.dumps({ "state" : player.game_state(),
                                    "players" : Recipient.active_players,
                                    "donorPool" : int(Mechanics.donor_pool * 100),
                                    "formerPatients" : Recipient.former_patients,
                                    "timeRemaining" : player.remaining_wait_time()
                                    }, 
                                   default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")
Exemple #3
0
def move(request, user_id, move_id):
    player = Recipient.getRecipient(int(user_id))
    print(player)
    mechanic = Mechanics.get_mechanic(int(move_id))
    response = mechanic.execute_move(player)
    # Determine if state should change (all players on same move # or time out or done)
    return HttpResponse(json.dumps({"state" : player.game_state(),
                                    "players" : Recipient.active_players,
                                    "donorPool" : int(Mechanics.donor_pool * 100),
                                    "formerPatients" : Recipient.former_patients,
                                    "result" : response}, default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")