本文整理汇总了Python中monster.Monster.get_move方法的典型用法代码示例。如果您正苦于以下问题:Python Monster.get_move方法的具体用法?Python Monster.get_move怎么用?Python Monster.get_move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类monster.Monster
的用法示例。
在下文中一共展示了Monster.get_move方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Labyrinth
# 需要导入模块: from monster import Monster [as 别名]
# 或者: from monster.Monster import get_move [as 别名]
#.........这里部分代码省略.........
self.player_location = self.get_random_location()
self.monster_location = self.get_random_location()
self.monster = Monster()
def _remove_random_doors(self):
for x, column in enumerate(self.layout):
for y, room in enumerate(column):
if randint(0,10) < 5:
# Remove a door at random
door = choice(room.doors)
room.doors.remove(door)
change_x, change_y = DIRECTIONS[door]
new_x, new_y = x+change_x, y+change_y
self.layout[new_x][new_y].doors.remove(OPPOSITE_MOVES[door])
def get_random_location(self):
return randint(0, self.width-1), randint(0, self.height-1)
def player_hears(self):
distance = distance(
self.monster_location, self.player_location
)
return distance < SOUND_THRESHOLD
def monster_hears(self):
distance = distance(
self.player_location, self.monster_location
)
return distance < SOUND_THRESHOLD * 1.5
def text_map(self):
"""
Return maze table in ASCII
For debugging purposes
"Borrowed" from http://code.activestate.com/recipes/252127-maze-generator/
"""
result = '.' + self.width*'_.'
result += '\n'
for j in range(self.height-1, -1, -1):
result += '|'
for i in range(self.width):
if SOUTH not in self.layout[i][j].doors:
result += '_'
elif (i,j) == self.player_location:
result += 'p'
elif (i,j) == self.monster_location:
result += 'm'
else:
result += ' '
if EAST not in self.layout[i][j].doors:
result += '|'
else:
result += '.'
result += '\n'
return result
def get_current_player_room(self):
x, y = self.player_location
return self.layout[x][y]
def get_current_monster_room(self):
x, y = self.monster_location
return self.layout[x][y]
def _move_player(self, direction):
current_room = self.get_current_player_room()
print current_room.make_description()
if direction not in current_room.doors:
print "You cannot move in this direction"
else:
current_x, current_y = self.player_location
change_x, change_y = DIRECTIONS[direction]
self.player_location = current_x + change_x, current_y + change_y
print "You moved {}.".format(direction)
def _move_monster(self):
direction = self.monster.get_move()
current_room = self.get_current_monster_room()
if direction in current_room.doors:
current_x, current_y = self.monster_location
change_x, change_y = DIRECTIONS[direction]
self.monster_location = current_x + change_x, current_y + change_y
def _check_condition(self):
if self.player_location == self.monster_location:
print "You have been eaten by a grue."
raise Exception("Grue")
def move_player(self, direction):
self._move_player(direction)
self._move_monster()
self._check_condition()
return self.get_current_player_room()