我希望随机时间通过红色和绿色随机改变更改以更简单的方式不涉及.wait函数,(现在是几秒钟和几秒)我有
self.time = random.randint(1,3)
self.bgcolor = random.randint(1,2)
if self.time == 1:
self.x = 30
self.wait = 1
if self.time == 2:
self.x = 30
self.wait = 2
if self.time == 3:
self.x = 30
self.wait = 3
if self.bgcolor == 1:
self.screen.fill(self.red)
time.sleep(self.time)
pygame.display.flip()
if self.bgcolor == 2:
self.screen.fill(self.green)
time.sleep(self.time)
pygame.display.flip()
答案 0 :(得分:0)
你可以这样做:
from random import choice, randint
self.screen.fill(choice([self.red, self.green]))
self.wait = self.time = randint(1, 3)
time.sleep(self.wait)