本文整理汇总了Python中maze.Maze.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Maze.__init__方法的具体用法?Python Maze.__init__怎么用?Python Maze.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maze.Maze
的用法示例。
在下文中一共展示了Maze.__init__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Main
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import __init__ [as 别名]
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__()
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import __init__ [as 别名]
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]