def __init__(self, width, height, exploration): """ Build the associated room (maze) based on the given parameters, and set up the enemies list """ Maze.__init__(self, width, height, exploration) self.enemies = [] self.rewards = []
def __init__(self, file_path, square_size): Maze.__init__(self, file_path) self.__square_size = square_size self.__game_line = 0 self.__game_column = 0 self.__game_x = 0 self.__game_y = 0 self.__visited_cases = list() self.__width = self.__square_size * Maze.getWidth(self) self.__height = self.__square_size * Maze.getHeight(self) turtle.title('Maze by Pierre') turtle.shape('turtle') turtle.setup(self.__width + 50, self.__height + 50) self.drawMaze()
def __init__(self, x, y): Maze.__init__(self, x, y) self._map = self.m
class Main(): def __init__(self): # Initialize pygame pygame.init() pygame.font.init() # initialize font self.font = pygame.font.SysFont(None, 40) self.smallfont = pygame.font.SysFont(None, 25) # Set the dimension the window self.window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) pygame.display.set_caption("Maze") pygame.display.flip() self.game_over = False self.game_exit = False # Create and generatethe Maze self.maze = Maze() def text_objects(self, text, color, size): if size == "small": textSurface = self.smallfont.render(text, True, color) elif size == "medium": textSurface = self.font.render(text, True, color) return textSurface, textSurface.get_rect() def message_to_screen(self, msg, color, y_displace=0, size = "medium"): textSurf, textRect = self.text_objects(msg, color, size) textRect.center = (WINDOW_WIDTH / 2), (WINDOW_HEIGHT / 2) + y_displace self.window.blit(textSurf, textRect) def show_items_collected(self): show = True nb_items_left = len(self.maze.items) - len(self.maze.mac.backpack) while show: for event in pygame.event.get(): if event.type == QUIT: self.game_over = True elif event.type == KEYDOWN: # Escape to quit if event.key == K_TAB: show = False self.window.fill(WHITE) self.message_to_screen("You picked up:", BLACK) line = 320 position = 240 for char, img in self.maze.items.items(): for item in self.maze.mac.backpack: if item == char: self.window.blit(img, (position, line)) position += SIZE_SPRITE if len(self.maze.mac.backpack) == len(self.maze.items): self.message_to_screen("You can put the guardian to sleep now",GREEN, 80, size = "small") else: self.message_to_screen("You still have {} items to collect".format(nb_items_left), RED, 80, size = "small") pygame.display.flip() def screen_game_over(self): display_screen = True while display_screen: winner = self.maze.winner() mcgyver_win = pygame.image.load(MCGYVER_WIN).convert() murdoc_win = pygame.image.load(MURDOC_WIN).convert() if winner == "McGyver": self.window.blit(mcgyver_win, (0, 0)) self.message_to_screen("You win", WHITE, -75) pygame.display.update() elif winner == "Murdoc": self.window.blit(murdoc_win, (0, 0)) self.message_to_screen("You loose", WHITE, -75) pygame.display.update() self.message_to_screen("Press P to play agin or Q to quit", WHITE) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT: self.game_over = False self.game_exit = True if event.type == pygame.KEYDOWN: if event.key == K_p: self.game_over = False self.game_exit = False # Reset the object self.maze.__init__() self.maze.mac.__init__() display_screen = False elif event.key == K_q: self.game_over = False self.game_exit = True display_screen = False def event_in_pygame(self): move = True while move: for event in pygame.event.get(): # check for closing window if event.type == pygame.QUIT: self.game_exit = True self.game_over = False move = False elif event.type == KEYDOWN: # Escape to quit if event.key == K_ESCAPE: self.game_exit = True self.game_over = False move = False # Arrow keys to move McGyver elif event.key == K_RIGHT: self.maze.mac.move(self.maze, 'right') elif event.key == K_LEFT: self.maze.mac.move(self.maze, 'left') elif event.key == K_UP: self.maze.mac.move(self.maze, 'up') elif event.key == K_DOWN: self.maze.mac.move(self.maze, 'down') # Show the items colectted elif event.key == K_TAB: self.show_items_collected() elif event.key == K_ESCAPE: self.game_over = False self.game_exit = True self.maze.display_maze(self.window) pygame.display.flip() self.game_over = self.maze.game_over() if self.game_over: move = False # Main loop def main_loop(self): pygame.display.flip() while not self.game_exit: # Slow down the loop pygame.time.Clock().tick(30) # Display the maze self.maze.display_maze(self.window) # Refresh the screen pygame.display.flip() # While McGyver have not find the guardian, he can move around the map if not self.game_over: self.event_in_pygame() # Show a screen where you can quit or play again else: self.screen_game_over() self.game_exit = True
def __init__(self): Maze.__init__(self) self.AllStates = [self.START_STATE, self.END_STATE, self.KEY_STATE, self.GOAL_STATE, self.CHOICE_STATE, self.BUFFER_STATE]
class Main(): def __init__(self): # Initialize pygame pygame.init() pygame.font.init() # initialize font self.font = pygame.font.SysFont(None, 40) self.smallfont = pygame.font.SysFont(None, 25) # Set the dimension the window self.window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) pygame.display.set_caption("Maze") pygame.display.flip() self.game_over = False self.game_exit = False # Create and generatethe Maze self.maze = Maze() def text_objects(self, text, color, size): if size == "small": textSurface = self.smallfont.render(text, True, color) elif size == "medium": textSurface = self.font.render(text, True, color) return textSurface, textSurface.get_rect() def message_to_screen(self, msg, color, y_displace=0, size="medium"): textSurf, textRect = self.text_objects(msg, color, size) textRect.center = (WINDOW_WIDTH / 2), (WINDOW_HEIGHT / 2) + y_displace self.window.blit(textSurf, textRect) def show_items_collected(self): show = True nb_items_left = len(self.maze.items) - len(self.maze.mac.backpack) while show: for event in pygame.event.get(): if event.type == QUIT: self.game_over = True elif event.type == KEYDOWN: # Escape to quit if event.key == K_TAB: show = False self.window.fill(WHITE) self.message_to_screen("You picked up:", BLACK) line = 320 position = 240 for char, img in self.maze.items.items(): for item in self.maze.mac.backpack: if item == char: self.window.blit(img, (position, line)) position += SIZE_SPRITE if len(self.maze.mac.backpack) == len(self.maze.items): self.message_to_screen("You can put the guardian to sleep now", GREEN, 80, size="small") else: self.message_to_screen( "You still have {} items to collect".format(nb_items_left), RED, 80, size="small") pygame.display.flip() def screen_game_over(self): display_screen = True while display_screen: winner = self.maze.winner() mcgyver_win = pygame.image.load(MCGYVER_WIN).convert() murdoc_win = pygame.image.load(MURDOC_WIN).convert() if winner == "McGyver": self.window.blit(mcgyver_win, (0, 0)) self.message_to_screen("You win", WHITE, -75) pygame.display.update() elif winner == "Murdoc": self.window.blit(murdoc_win, (0, 0)) self.message_to_screen("You loose", WHITE, -75) pygame.display.update() self.message_to_screen("Press P to play agin or Q to quit", WHITE) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT: self.game_over = False self.game_exit = True if event.type == pygame.KEYDOWN: if event.key == K_p: self.game_over = False self.game_exit = False # Reset the object self.maze.__init__() self.maze.mac.__init__() display_screen = False elif event.key == K_q: self.game_over = False self.game_exit = True display_screen = False def event_in_pygame(self): move = True while move: for event in pygame.event.get(): # check for closing window if event.type == pygame.QUIT: self.game_exit = True self.game_over = False move = False elif event.type == KEYDOWN: # Escape to quit if event.key == K_ESCAPE: self.game_exit = True self.game_over = False move = False # Arrow keys to move McGyver elif event.key == K_RIGHT: self.maze.mac.move(self.maze, 'right') elif event.key == K_LEFT: self.maze.mac.move(self.maze, 'left') elif event.key == K_UP: self.maze.mac.move(self.maze, 'up') elif event.key == K_DOWN: self.maze.mac.move(self.maze, 'down') # Show the items colectted elif event.key == K_TAB: self.show_items_collected() elif event.key == K_ESCAPE: self.game_over = False self.game_exit = True self.maze.display_maze(self.window) pygame.display.flip() self.game_over = self.maze.game_over() if self.game_over: move = False # Main loop def main_loop(self): pygame.display.flip() while not self.game_exit: # Slow down the loop pygame.time.Clock().tick(30) # Display the maze self.maze.display_maze(self.window) # Refresh the screen pygame.display.flip() # While McGyver have not find the guardian, he can move around the map if not self.game_over: self.event_in_pygame() # Show a screen where you can quit or play again else: self.screen_game_over() self.game_exit = True