def start(player):
    """
    Attempts creating a new game session for the given player.
    """
    if not player:
        return None

    # Initialize all the stacks.
    room_stack = Stack()
    room_stack.save()

    you_stack = Stack()
    you_stack.save()

    equipment_stack = Stack()
    equipment_stack.save()

    forge_stack = Stack()
    forge_stack.save()

    treasure_stack = Stack()
    treasure_stack.save()

    discard_stack = Stack()
    discard_stack.save()

    # Begin a new session.
    session = Session(
        health=HEALTH_CAPACITY,

        # Important to note that a session has to be tied to a player. Same goes for
        # cards and stacks; they must, ultimately, be tied to a session. Otherwise
        # it would be possible to move cards between sessions.
        belongs_to_player=player,

        room_stack=room_stack,
        you_stack=you_stack,
        equipment_stack=equipment_stack,
        forge_stack=forge_stack,
        treasure_stack=treasure_stack,
        discard_stack=discard_stack
    )

    session.save()

    # Draw the first 5 cards.
    initial_room_cards = draw(session, ROOM_CAPACITY)

    # Put the initial cards in place.
    room_stack.push_many(initial_room_cards)

    # If everything went as expected, activate the session by hooking it up to the player.
    player.active_session = session
    player.save()

    return session
Beispiel #2
0
def start(player):
    """
    Attempts creating a new game session for the given player.
    """
    if not player:
        return None

    # Initialize all the stacks.
    room_stack = Stack()
    room_stack.save()

    you_stack = Stack()
    you_stack.save()

    equipment_stack = Stack()
    equipment_stack.save()

    forge_stack = Stack()
    forge_stack.save()

    treasure_stack = Stack()
    treasure_stack.save()

    discard_stack = Stack()
    discard_stack.save()

    # Begin a new session.
    session = Session(
        health=HEALTH_CAPACITY,

        # Important to note that a session has to be tied to a player. Same goes for
        # cards and stacks; they must, ultimately, be tied to a session. Otherwise
        # it would be possible to move cards between sessions.
        belongs_to_player=player,
        room_stack=room_stack,
        you_stack=you_stack,
        equipment_stack=equipment_stack,
        forge_stack=forge_stack,
        treasure_stack=treasure_stack,
        discard_stack=discard_stack)

    session.save()

    # Draw the first 5 cards.
    initial_room_cards = draw(session, ROOM_CAPACITY)

    # Put the initial cards in place.
    room_stack.push_many(initial_room_cards)

    # If everything went as expected, activate the session by hooking it up to the player.
    player.active_session = session
    player.save()

    return session