implemented won text and set consistent seed

This commit is contained in:
Simon Pirkelmann 2021-09-10 01:22:17 +02:00
parent ca1fe99ff2
commit 885a516fe3

View File

@ -290,7 +290,7 @@ class Game:
# TODO fix number of commands at 5 # TODO fix number of commands at 5
self.cmds = [Command('forward'), Command('left', color=RED), Command('left', color=BLUE), Command('P0'), Command('-')] self.cmds = [Command('forward'), Command('left', color=RED), Command('left', color=BLUE), Command('P0'), Command('-')]
self.state = 'game_over' self.state = 'won'
self.prg = Program(self.robot, self.board, self.cmds) self.prg = Program(self.robot, self.board, self.cmds)
@ -303,7 +303,7 @@ class Game:
int((self.board.tiles.shape[0] + 2) * self.scale_fac * 1.2))) int((self.board.tiles.shape[0] + 2) * self.scale_fac * 1.2)))
self.game_over_text = myfont.render('GAME OVER', False, BLACK) self.game_over_text = myfont.render('GAME OVER', False, BLACK)
self.won_text = myfont.render('YOU WON', False, GREEN) self.won_text = myfont.render('YOU WON', False, BLACK)
self.run_text = myfont.render('RUN', False, tuple(BLACK)) self.run_text = myfont.render('RUN', False, tuple(BLACK))
self.stop_text = myfont_small.render('STOP', False, tuple(BLACK)) self.stop_text = myfont_small.render('STOP', False, tuple(BLACK))
self.step_text = myfont_small.render('STEP', False, tuple(BLACK)) self.step_text = myfont_small.render('STEP', False, tuple(BLACK))
@ -382,7 +382,12 @@ class Game:
pygame.time.wait(1500) pygame.time.wait(1500)
self.state = 'reset' self.state = 'reset'
elif self.state == 'won': elif self.state == 'won':
self.screen.blit(self.won_text, (50, 00)) won_surf = pygame.Surface((self.screen.get_width() // 2, self.screen.get_height() // 2))
won_surf.fill(tuple(GREEN))
won_surf.blit(self.won_text,
((won_surf.get_width() - self.won_text.get_width()) // 2,
(won_surf.get_height() - self.won_text.get_height()) // 2))
self.screen.blit(won_surf, (self.screen.get_width() // 4, self.screen.get_height() // 4))
pygame.display.update() pygame.display.update()
pygame.time.wait(1500) pygame.time.wait(1500)
self.state = 'reset' self.state = 'reset'
@ -483,7 +488,9 @@ class Game:
pygame.time.wait(100) pygame.time.wait(100)
if __name__ == "__main__": if __name__ == "__main__":
random.seed(42) seed = 2
random.seed(seed)
np.random.seed(seed)
game = Game(dimx=7, dimy=4, robotx=3, roboty=1) game = Game(dimx=7, dimy=4, robotx=3, roboty=1)
game.run() game.run()