问题
I was wondering how to go about picking a random sound and playing it on an event in an OOP way. My original plan was have a list in my resource loader class, and have it iterate through that. My only issue is my code constantly breaks everything when I try to implement this. How would you guys go about this?
回答1:
class SoundManager:
sounds = [] # list of sound objects
@staticmethod
def playRandom():
random.choice(SoundManager.sounds).play()
来源:https://stackoverflow.com/questions/28865782/choosing-a-random-sound-pygame