Beispiel #1
0
def create_new_deck(paths):
    if len(paths) < 1:
        raise ValueError("Unable to create deck: no packs given")

    deck = Deck(paths)
    header = None
    category = None
    for path in paths:
        with open(path, 'r') as f:
            for i, line in enumerate(f):
                # Anything after a # is considered a comment and discarded.
                line = line.split('#')[0].strip()
                if not line:
                    continue

                # "[-header-]" is the kind of line we're looking for here.
                if line[0] == '[' and line[-1] == ']':
                    if line[1] == line[-2] == '-':
                        category = 'base'
                    elif line[1] == line[-2] == '^':
                        category = 'subs'
                    else:
                        print("error")
                        return

                    header = line[2:-2]
                    continue

                # Watch out for formatting errors.
                elif category is None or header is None:
                    # Found a card without any headers.
                    print("error")
                    return

                if header not in deck.__dict__[category].keys():
                    deck.__dict__[category][header] = {}

                (text, rating) = line.split(':')
                # TODO: more elegant way of doing this
                rating = rating.strip()
                try:
                    r_value = util.rating_value(rating.strip())
                except ValueError:
                    print("error")
                    return
                else:
                    deck.__dict__[category][header][text.strip()] = r_value

    compile_deck(deck)
    shuffle_deck(deck)
    return deck
Beispiel #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
Beispiel #3
0
def debug_menu(deck, party, args):
    """Offer options for viewing and tweaking internal variables."""

    options = [
        'batch n:int',
        #'level n:int',
        'progress difficulty',
        'np difficulty',
        'dump level',
        'intensity level:int',
        'args',
    ]
    while 1:
        response = malt.fill(options)

        if response == 'batch':
            for i in range(response.n):
                (text, value) = taskgen.random_task(deck)
                print('[{}] '.format(i), end='')
                display((text, value))

        # Print out all tasks at a certain level.
        elif response == 'level':
            level = response.n
            nested = taskgen.all_combinations(deck.base, deck.subs)
            # remove all out-of-level tasks
            nested = [[(t, v) for (t, v) in base if v==level] for base in nested]
            # clean up empty lists
            nested = [base for base in nested if len(base) > 0]
            # sort tasks alphabetically
            nested = sorted(nested, key=lambda x: x[0][0:5])
            for base in nested:
                # sort variations by point value
                base = sorted(base, key=lambda x: x[1])
                print("========================================")
                for variation in base:
                    display(variation)
                print("")

        elif response == 'progress':
            try:
                mod = util.rating_value(response.difficulty)
            except ValueError:
                malt.serve("Invalid difficulty.")
                continue

            points = 0
            turn_num = 0
            while turn_num < 20:
                turn_num += 1
                target = util.target_rating(points, mod)
                (text, rating) = taskgen.random_task(deck, target)
                print("({}) {}".format(rating, text))
                points += util.points_value(mod)

        elif response == 'np':
            # Take arguments.
            try:
                mod = util.rating_value(response.difficulty)
            except ValueError:
                malt.serve("Invalid difficulty.")
                continue
            #end = response.turns

            points = 0
            turn_num = 0
            while turn_num < 20:
                turn_num += 1
                target = util.target_rating(points, mod)
                print("[{}] (Level {})".format(util.format_number(points), target))
                points += util.points_value(mod)

        # Dump every possible complete task.
        elif response == 'dump':
            nested = taskgen.all_combinations(deck.base, deck.subs)
            if response.level == 'all':
                pass
            else:
                try:
                    rating = util.rating_value(response.level)
                    # remove all out-of-level tasks
                    nested = [
                        [(t, v) for (t, v) in base if v==rating] for base in nested]
                    # clean up empty lists
                    nested = [base for base in nested if len(base) > 0]
                except ValueError:
                    malt.serve("Invalid difficulty.")
                    continue
            # sort tasks alphabetically by the first five characters
            nested = sorted(nested, key=lambda x: x[0][0:5])
            for base in nested:
                # sort variations by point value
                base = sorted(base, key=lambda x: x[1])
                print("========================================")
                for variation in base:
                    display(variation)
                #print("")

        # Set the intensity level.
        elif response == 'intensity':
            malt.serve("setting flag -{}".format('x'*response.level))
            party.intensity = response.level

        elif response == 'args':
            malt.serve(args)

        elif response == 'back': break