示例#1
0
def move(player_id, new_node_id):
    player = graph.player(player_id)

    if int(new_node_id) in [rel.end.id for rel in player.location.relationships.outgoing(["Route"])]:
        graph.unlink(player, "Location")
        graph.link(player, graph.node_by_id(new_node_id), "Location")

    return redirect("/player/" + player_id)
示例#2
0
def journey(journey_id):
    journey = graph.journey(journey_id)

    if not journey.current_question:
        attributes = graph.all_linked_nodes(journey, "Attribute")
        return render_template("journey/conclusion.html", journey=journey, attributes=attributes)

    if request.method == "POST":
        answer = request.form["answer"]
        answer_node = first([a for a in journey.current_question.answers if a["id"] == answer])
        reward_nodes = graph.all_linked_nodes(answer_node, "Reward")
        next_question_node = graph.first_linked_node(answer_node, "Next")

        for reward_node in reward_nodes:
            graph.link(journey, reward_node, "Attribute")

        graph.unlink(journey, "Current")

        if next_question_node:
            graph.link(journey, next_question_node, "Current")

        return redirect("/journey/" + journey_id)

    return render_template("journey/question.html", journey=journey)