Trick the random generator...

master
Raphaël Vinot 2014-08-31 11:49:02 +02:00
parent fd2f247d78
commit b1f54e9e7c
1 changed files with 9 additions and 1 deletions

10
game.py
View File

@ -29,6 +29,7 @@ class TheGame:
self.bg = pygame.image.load(os.path.join('img', 'lawyerCrystalBall.png')) self.bg = pygame.image.load(os.path.join('img', 'lawyerCrystalBall.png'))
self.bg.set_colorkey((255,255,255)) self.bg.set_colorkey((255,255,255))
self.bg.set_alpha(75) self.bg.set_alpha(75)
self.last_colors = []
# fonts # fonts
self.bigFont = pygame.font.Font(None, 90) self.bigFont = pygame.font.Font(None, 90)
@ -93,9 +94,16 @@ class TheGame:
def chooseRandomColor(self): def chooseRandomColor(self):
selected = random.randint(0, 3) selected = random.randint(0, 3)
if len(self.last_colors) > 5:
self.last_colors.pop(0)
for i in range(0, 5):
if selected in self.last_colors:
selected = random.randint(0, 3)
else:
break
self.last_colors.append(selected)
return self.colors[selected] return self.colors[selected]
def gameOver(self): def gameOver(self):
screen_width, screen_height = self.screen.get_size() screen_width, screen_height = self.screen.get_size()
gameOverImage = pygame.image.load("img/gameOver.png") gameOverImage = pygame.image.load("img/gameOver.png")