需要帮助分解成模块

时间:2018-03-11 05:25:03

标签: python-3.x

我最近才刚开始上CIS课程,因此至少对python不熟悉。我希望我能对我最近开始的一个项目提出一些建议。我已经写了第五版D& D主动追踪器,我遇到的麻烦就是如何将它从这里分解成模块。我刚刚在python中学习列表(数组),并且在处理列表方面特别缺乏参数和参数。提前谢谢!

要遵循的代码

from random import randint

# Entering player names at the beginning of the session
def main():
    print("Enter PC names, separated by commas (David,Matt,Peter,etc.):")
    pcs = input().split(',')

# Loops every time a new battle has started
    while True:

# Setting up enemies
        num_foes = int(input("How many foes? "))
        foes = []
        foes = ["Enemy " + str(n+1) for n in range(num_foes)]

# Setting up enemy initiative modifiers
        foe_init_mods = []
        for foe in foes:
            foe_init_mods.append(int(input(foe + "'s initiative modifier? ")))

    # Setting up player initiative modifiers
            pcs_init_mods = []
            for pc in pcs:
                pcs_init_mods.append(int(input(pc + "'s initiative modifier? ")))

    # Setting up initiatives
            chars = []
            for i, pc in enumerate(pcs):
                chars.append([randint(1, 20) + pcs_init_mods[i], pc])
            for i, foe in enumerate(foes):
                chars.append([randint(1, 20) + foe_init_mods[i], foe])

    # Ordering characters by initiative
            chars.sort()

    # Displaying characters in order of initiative
            print("\n--- Initiative List ---")
            for i, char in enumerate(chars[::-1]):
                print(str(i+1) + ". " + char[1] + " (" + str(char[0]) + ")")

    # User decides if loop should terminate or not
            break_loop = input("\nAnother battle? (Y/N) ") == "N"
            if break_loop:
                print("Bye!")
                break
            else:
                print("Onwards!")


    main() 

0 个答案:

没有答案