The problem I have is the following I have a method that should and called 4 times, once every 750 ms. The problem is that the way it is called I can not pass arguments to it, because it is called through pygame.time.set_timer. So I created a global variable (because it would be even worse if I created an attribute called n) to be able to use this method but it does not seem to me the most beautiful way to do it. How could I fit this code?
global n
n = 0
def shuffle(self):
self.card_shuffle.play()
random.shuffle(self.cards)
for n, card in enumerate(self.cards):
card.flip("back")
card.rect.center = [self.screen_rect.centerx - n * 0.5,
self.screen_rect.centery - n * 0.5]
self.human.cards.clear()
self.ia.cards.clear()
pygame.time.set_timer(USEREVENT, 750)
def give_cards(self):
global n
if n < 6:
self.cards[n].flip("front")
self.cards[n].rect.midbottom = [self.screen_rect.centerx + 70 * (
n / 2 - 1), self.screen_rect.bottom]
self.human.cards.append(self.cards[n])
self.cards[n + 1].rect.midtop = [self.screen_rect.centerx + 70 * (
n / 2 - 1), self.screen_rect.top]
self.ia.cards.append(self.cards[n + 1])
n += 2
else:
self.cards[n].rotoflip("front", -90, {
"center": self.cards[n + 1].rect.midright})
self.card_vira = self.cards[n]
pygame.time.set_timer(USEREVENT, 0)
n = 0
def handler_events(self):
for event in pygame.event.get():
if event.type == QUIT:
self.running = False
if event.type == USEREVENT:
self.give_cards()