Example #1
0
def create_new_game():
    if Game.all().filter('title =', request.json['title']).count() == 0:
        name_of_player_to_join = list(set(request.json['players']))  # Makes sure each player is registered only once
        shuffle(name_of_player_to_join)
        players_to_join = [Player.all().filter('username ='******'title'], num_player=len(players_to_join))
        new_game.put()
        for i in range(-1, len(players_to_join)-1):
            killer = players_to_join[i]
            GamePlayer(game=new_game, player=killer).put()
            target = players_to_join[i+1]
            GameHistory(killer=killer, target=target, game=new_game, is_complete=False, confirm_msg=msg_generator()).put()
        return jsonify({"success": True})
    else:
        return jsonify({"success": False})
Example #2
0
def kill():
    try:
        msg = request.json["msg"].upper()
        killer = Player.all().filter('username ='******'game =', game)\
            .filter('killer =', killer)\
            .filter('is_complete =', False).get()
        if msg == old_game_history_success.confirm_msg:
            will_be_last_kill = None
            if GameHistory.all().filter("game =", game).filter("is_complete =", False).count() == 2:
                will_be_last_kill = True
            old_target = old_game_history_success.target
            old_game_history_success.is_complete = True
            old_game_history_success.put()
            old_game_history_failure = GameHistory.all()\
                .filter('game =', game)\
                .filter('killer =', old_target)\
                .filter('is_complete =', False).get()
            old_game_history_failure.is_complete = True
            old_game_history_failure.put()
            if will_be_last_kill:
                game_player = GamePlayer.all().filter('game =', game).filter('player =', killer).get()
                game_player.is_winner = True
                game_player.put()
                return jsonify({"success": True, "info": "Your enemy has been slain! "})
            new_target = old_game_history_failure.target
            GameHistory(killer=killer, target=new_target, game=game, is_complete=False, confirm_msg=msg_generator()).put()
            return jsonify({"success": True, "info": "Your enemy has been slain! "})
        else:
            return jsonify({"success": False, "info": "The message is incorrect. Are you trying to game the system?!"})
    except:  # TODO: please handle exceptions in a more proper way
        return jsonify({"success": False, "info": "Something is fundamentally wrong. ", "Data received by server": str(request.data)})