Ejemplo n.º 1
0
def progress_game(party):
    """Advance the party forward one turn."""

    hot = party.hotseat()
    if hot.pending_protection:
        hot.protected = True
        hot.pending_protection = False

    party.rotate()
    party.turn_number += 1

    if party.turn_number >= party.turns_per_player*len(party.players):
        malt.serve("game over!")

    if party.turn_number in party.alert_turns:
        malt.line("#")
        malt.serve("Alert! Turn {} has been reached.".format(party.turn_number))
        malt.line("#")
        party.alert_turns.remove(party.turn_number)

    if party.to_shuffle:
        random.shuffle(party.players)
        party.to_shuffle = False

#    if party.points_win_condition:
#        if any([p.points >= party.points_win_condition for p in party.players]):
#            print("[ERROR]: the game should end now!")

#    elif party.turns_win_condition:
#        if party.turn_number >= party.turns_win_condition:
#            print("[ERROR]: the game should end now!")

    if party.autosave and party.save_location:
        disk.yaml_dump(party.save_location, party)
Ejemplo n.º 2
0
def main_menu(args):
    """Run the main interactive menu.

    In this menu, party can be added to or removed from the game, and both
    the normal gameplay loop and the special debug loop can be accessed.
    """
    try:
        deck = setup_deck(args)
        party = setup_party(args)
    except SystemExit:
        print("Aborting startup.")
        return

    # Immediately enter debug mode if --debug is given.
    if args.debug:
        malt.serve("entering debug mode...")
        with malt.indent():
            debug.debug_menu(deck, party, args)

    options = [
        'start',
        'mercy',
        'daily',
        'debug',
        'add name',
        'remove name',
        'save game_file',
        'resume game_file',
        'export deck_file',
        'autosave toggle',
    ]
    while True:
        response = malt.fill(options)

        if response == 'start':
            if len(party.players) < 2:
                malt.serve("Please register at least two players to begin the game.")
                continue
            # check if the users want to set a losing punishment
            with malt.indent():
                play.game_menu(deck, party)

        elif response == 'debug':
            malt.serve("Entering debug mode.")
            with malt.indent():
                debug.debug_menu(deck, party, args)

        elif response == 'add':
            name = response.name
            if name in party.names():
                malt.serve("{} is already registered!".format(name))
            else:
                malt.serve("Registering {} as a new player.".format(name))
                party.add(name)

        elif response == 'remove':
            name = response.name
            if name in party.names():
                malt.serve("Removing {} from the game.".format(name))
                party.kick(name)
            else:
                malt.serve("{} is not a registered player!".format(name))

        elif response == 'save':
            path = response.game_file
            disk.yaml_dump(path, party)

        elif response == 'resume':
            path = response.game_file
            new_party = disk.yaml_load(path)
            if new_party is not None:
                party = new_party

        elif response == 'export':
            path = response.deck_file
            disk.yaml_dump(path, deck)

        elif response == 'autosave':
            toggle = response.toggle
            if toggle == 'on':
                filename = malt.freefill("filename: ")
                if disk.yaml_dump(filename, party):
                    party.autosave = True
                    party.save_location = filename
                    malt.serve("Enabled autosave.")
                else:
                    malt.serve("Cancelled autosave.")

            elif toggle == 'off':
                party.autosave = False
                malt.serve("Disabled autosave.")
            elif toggle == 'check':
                malt.serve("Autosave is currently {}.".format(
                    'on' if party.autosave else 'off'))
            else:
                malt.serve("The only options for autosave are on, off, and check.")

        elif response == 'back':
            break