本文整理汇总了Python中Map.obstacles_contains方法的典型用法代码示例。如果您正苦于以下问题:Python Map.obstacles_contains方法的具体用法?Python Map.obstacles_contains怎么用?Python Map.obstacles_contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.obstacles_contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Map [as 别名]
# 或者: from Map import obstacles_contains [as 别名]
#.........这里部分代码省略.........
def link(self, gui):
self.gui = gui
self.initialize()
def getListeCorpsSerpent(self):
return self.serpent.getListeCorps()
def move (self):
if self.vie:
if self.oriente == "Left":
if self.possible_left():
self.serpent_goLeft()
else:
self.serpentMort()
elif self.oriente == "Right":
if self.possible_right():
self.serpent_goRight()
else :
self.serpentMort()
elif self.oriente == "Up":
if self.possible_up():
self.serpent_goUp()
else :
self.serpentMort()
elif self.oriente == "Down":
if self.possible_down():
self.serpent_goDown()
else :
self.serpentMort()
self.gui.afficherSerpent()
self.gui.afficherNourriture()
else:
print("Mort")
def possible_left(self):
pos = self.serpent.getPosition()
pos = (pos[0]-1, pos[1])
return not self.checkCollision(pos[0], pos[1])
def possible_right(self):
pos = self.serpent.getPosition()
pos = ((pos[0]+1) %self.getLongueurMap(), pos[1])
return not self.checkCollision(pos[0], pos[1])
def possible_up(self):
pos = self.serpent.getPosition()
pos = (pos[0], pos[1]-1 )
return not self.checkCollision(pos[0], pos[1])
def possible_down(self):
pos = self.serpent.getPosition()
pos = (pos[0], (pos[1]+1)%self.getHauteurMap() )
return not self.checkCollision(pos[0], pos[1])
def oriente_serpent_left(self, event):
if self.oriente != "Right":
self.set_var("Left")
def oriente_serpent_right(self, event):
if self.oriente != "Left":
self.set_var("Right")
def oriente_serpent_up(self, event):
if self.oriente != "Down":
self.set_var("Up")
def oriente_serpent_down(self, event):
if self.oriente != "Up":
self.set_var("Down")
def set_var(self, var):
self.oriente = var
def checkCollision_corps(self, pos_x, pos_y):
return self.serpent.contains(pos_x, pos_y)
def switch(self, event):
self.gui.switchToMenu()
def getPositionObstacles(self):
liste_pos = self.map.getPositionObstacles()
return liste_pos
def ajouterObstacles(self, x, y, valeur):
self.map.set_obstacle(x, y, valeur)
self.gui.ajouterID_obstacles()
def checkCollision_obstacles(self, x, y):
return self.map.obstacles_contains(x, y)
def checkCollision(self, x, y):
return self.checkCollision_corps(x, y) or self.checkCollision_obstacles(x, y)
def serpentMort(self):
self.vie = False