Example #1
0
def game_tools_menu(party):
    """Run the interface for non-essential gameplay tools."""
    options = [
        'timer seconds:str',
        'countdown turns:int',
        'flip',
        'modify name amount:int',
        'reject name',
        'show name',
        'intensity x:int',
    ]

    while True:
        response = malt.fill(options)
        if response == 'timer':
            with malt.indent():
                timer(response.seconds)

        elif response == 'countdown':
            with malt.indent():
                if response.turns < 1:
                    malt.serve("Can only countdown one or more turns in advance.")
                    continue
                malt.serve("Scheduling an alert in {} turns.".format(response.turns))
            party.alert_turns.append(party.turn_number + response.turns)
                

        elif response == 'flip':
            with malt.indent():
                flip_coin()

        elif response == 'back':
            break

        elif response == 'modify':
            name = response.name
            points = response.amount
            if party.score(name, points):
                malt.serve("Adding {} to {}'s score.".format(points, name))
            del name

        elif response == 'reject':
            name = response.name
            player = party.lookup(name)
            if player:
                player.reject()
                malt.serve("Rejected {}'s last attempt.".format(name))
                points = player.points
                malt.serve("{} has been reverted to {} points.".format(name, points))
            else:
                malt.serve("{} is not a registered player.".format(name))
            del name, player

        elif response == "show":
            name = response.name
            p = party.lookup(name)
            if p:
                malt.serve("{}: {} Points".format(p.name, p.points))
            else:
                malt.serve("{} is not a registered player.".format(name))
            del name, p

        elif response == "intensity":
            x = response.x
            malt.serve("Setting intensity level to [{}].".format('X'*x))
            party.intensity = x
            del x

        elif response == 'back':
            break
Example #2
0
def game_menu(deck, party):
    options = [
        "task",
        "set difficulty",
        #"manual",
        "perks",
        "scores",
        "tools",
        #"tip name amount:int",
        "challenge name",
    ]
    while True:
        hotseat = party.hotseat()
        if hotseat.protected:
            hotseat.protected = False
            malt.serve("{} skips their turn.".format(hotseat))
            progress_game(party)
            continue

        malt.serve()
        update_string = "It is {}'s turn.".format(hotseat)
        malt.serve(update_string)
        malt.serve("="*len(update_string))
        response = malt.fill(options)

        if response == "task":
            if hotseat.stored_task:
                (task, points) = hotseat.stored_task
                hotseat.stored_task = None
            else:
                (task, points) = new_task(hotseat, deck, party)

            with malt.indent():
                task_menu(party, hotseat, (task, points))

        elif response == "set":
            try:
                hotseat.mod = util.rating_value(response.difficulty)
            except ValueError:
                malt.serve("Task difficulty must be easy, normal, hard, or brutal.")
            else:
                malt.serve("Set difficulty to {}.".format(response.difficulty))
            continue

        elif response == "manual":
            malt.serve("Manually creating new task.")
            with malt.indent():
                manual_task_creation_menu(deck)

        elif response == "perks":
            malt.serve("Entering perk shop.")
            with malt.indent():
                shop.perk_menu(party)

        elif response == "scores":
            for p in party.players:
                malt.serve("{}: {} Points".format(p.name, p.points))

        elif response == 'tools':
            malt.serve("Entering gameplay utilities.")
            with malt.indent():
                sugar.game_tools_menu(party)

        elif response == 'until':
            n = response.winning_points
            if n < 0:
                party.points_win_condition = 0
                malt.serve("Disabled win condition.")
            else:
                party.points_win_condition = n
                malt.serve("First person to {} points wins.".format(n))

        elif response == 'back':
            break
Example #3
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