dimanche 29 octobre 2017

Run a function with a random list element

from roles import Herbalist, Warrior

def makeRolesAct(listOfTheRoles):
    y = 0
    for role in listOfTheRoles:
        print("Role", y, role.describe())
        print(role.act())
        y+=1

def main():
    listOfTheRoles = []
    listOfTheRoles.extend([Warrior('axe', 'dragon'), Herbalist(), Warrior('hammer', 'horse')])

    for x in range(5):
        makeRolesAct(listOfTheRoles)

if __name__ == '__main__':
    main()

describe() describes a role of the current actor. act() makes the actor do his action.

I'd like makeRolesAct() to run with a random listOfTheRoles element. So if I had the function in a loop it would repeat with actions repeating for randomly chosen actors.




Aucun commentaire:

Enregistrer un commentaire