本文整理汇总了Python中maze.Maze.getPos方法的典型用法代码示例。如果您正苦于以下问题:Python Maze.getPos方法的具体用法?Python Maze.getPos怎么用?Python Maze.getPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maze.Maze
的用法示例。
在下文中一共展示了Maze.getPos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import getPos [as 别名]
class GameSpace:
def __init__(self, mazesize=20):
# game characters
self.p1 = 'H'
self.p2 = 'G'
self.exit = 'E'
# game maze
self.maze = Maze(mazesize)
self.boot = 1
self.size = int()
# game objects
self.player = None
self.clock = None
# game objects
pygame.init()
self.exit_sprite = pygame.image.load("../images/exit.png")
self.exit_rect = self.exit_sprite.get_rect()
self.gameover_sprite = pygame.image.load("../images/gameover.png")
self.gameover_rect = self.gameover_sprite.get_rect()
self.gameover_rect = self.gameover_rect.move(SCREEN_SIZE/4, SCREEN_SIZE/4)
self.gameoverl_sprite = pygame.image.load("../images/gameover_l.png")
self.gameoverl_rect = self.gameoverl_sprite.get_rect()
self.gameoverl_rect = self.gameoverl_rect.move(SCREEN_SIZE/4, SCREEN_SIZE/4)
self.bg = pygame.image.load("../images/background.png")
self.bg_rect = self.bg.get_rect()
self.wait_screen = pygame.image.load("../images/wait_screen.png")
self.wait_rect = self.wait_screen.get_rect()
#self.bg_rect = self.bg_rect.move(SCREEN_SIZE/2, SCREEN_SIZE/2)
self.size = self.width, self.height = SCREEN_SIZE, SCREEN_SIZE
self.green = 0, 255, 0
self.connected = 0
self.opponent = [(MAZE_SIZE/2 - 1) * WALL_SIZE * SCALE, 0, "../images/ghost_down.png"]
self.ghostImage = pygame.image.load(self.opponent[2])
self.ghostRect = self.ghostImage.get_rect()
self.ghostRect.centerx = self.opponent[0]
self.ghostRect.centery = self.opponent[1]
# network
self.ghostProtocol = None
def setup(self):
# generate maze
self.maze.generate()
size = self.maze.getSize()
# send data to ghost
pd = pickle.dumps(self.maze)
self.ghostProtocol.transport.write(pd)
# set character start positions
self.maze.setPos(size-1, size/2-1, self.p1) # human
self.maze.setPos(0, size/2-1, self.p2) # ghost
# set exit (try middle if path, otherwise on edge)
if self.maze.getPos(size/2-1, size/2-1) == self.maze.path:
self.maze.setPos(size/2-1, size/2-1, self.exit)
else:
side = randint(0,1)
i = 0
if side == 0:
# set on left side
while i < size:
if self.maze.getPos(i, 0) == self.maze.path:
self.maze.setPos(i, 0, self.exit)
break
i += 1
else:
# set on right side
while i < self.size:
if self.maze.getPos(i, size-1) == self.maze.path:
self.maze.setPos(i, size-1, self.exit)
break
i += 1
#self.maze.display()
# reset data
self.walls = []
self.game_over = 0
self.lose = 0
self.break_flag = 0
# music
pygame.mixer.music.load("../music/horror.wav")
pygame.mixer.music.play(-1, 0.0)
return
def main(self):
# establish connection with ghost
ghostFactory = GhostFactory(self)
reactor.listenTCP(GHOST_PORT, ghostFactory)
# Initialize screen window
pygame.display.set_caption("PATH")
#.........这里部分代码省略.........