I'm trying to write a random fantasy encounter. Where randomly picking from the main list, will take you to a second list, which will take you to a third list:
- RUINS-> ruins-> manor->hut
or
- RUINS -> ruins-> village-> 4-24 hovels:
broad_categories = ['RUINS', 'RELICS', etc]
ruins = ['manor', 'village', 'city', etc]
manor = ['hut', 'hovel', 'hall', etc]
village = ['2-12 huts', '4-24 hovels', '6-36 cottages', etc]
city = ['7-42 huts and a citadel', '8-48 houses', etc]
so I wrote this:
a = random.randint(0, 1)
b = random.randint(0, 5)
c = random.randint(0, 5)
def place():
if a == 0 and b == 0 and c == 0:
result = 'the ruins of hut'
elif a == 0 and b == 0 and c == 1:
result = 'the ruins of a hovel'
elif a == 0 and b == 0 and c == 2:
result = 'the ruins of a hall'
elif a == 0 and b == 0 and c == 3:
result = 'the ruins of a villa'
elif a == 0 and b == 0 and c == 4:
result = 'the ruins of a cottage'
elif a == 0 and b == 0 and c == 5:
result = 'the ruins of a palace'
etc...
It works, I just have a million elif statements and I'm iterating through every single list by hand. Is there a better way to auto-generate a result? So that when 'RUINS' is randomly picked it then goes to the 'ruins' list and then randomly picks 'manor village or city' and then based on that choice picks from those sub-lists lists?
Aucun commentaire:
Enregistrer un commentaire