当前位置: 首页>>代码示例>>Python>>正文


Python Map.set_obstacle方法代码示例

本文整理汇总了Python中Map.set_obstacle方法的典型用法代码示例。如果您正苦于以下问题:Python Map.set_obstacle方法的具体用法?Python Map.set_obstacle怎么用?Python Map.set_obstacle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Map的用法示例。


在下文中一共展示了Map.set_obstacle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Jeu

# 需要导入模块: import Map [as 别名]
# 或者: from Map import set_obstacle [as 别名]
class Jeu(Frame):

    def __init__(self, parent, controller):
        Frame.__init__(self, parent)
        self.controller= controller
        self.data = None
        self.map = None
        self.canvas = Canvas(self, bg = 'dark gray', height = 600, width = 800)
        self.canvas.pack(padx = 10, pady = 10)
        self.liste_id_obstacle=[]
        self.taille = 25
        self.color_obstacle = "black"

        
    def initialisation(self):
        self.data = {self.controller.client.name:{"color":"red", "position":[(1,2)]}}
        self.map = Map(10,10)
        self.controller.client.get_map()
        
    def updateAffichage(self):
        self.afficherObstacle()
        '''
        for name in self.data:
            temp = self.data[name]
            pos = temp["position"]
            color = temp["color"]
            for n in pos:
                self.drawCarre(n, color, name)
                '''
    def set_map(self, dico):
        width = dico["width"]
        height = dico["height"]
        numbers = dico["numbers"]
        obstacles = dico["obstacles"]
        self.map = Map(width, height)
        for i in obstacles:
            self.map.set_obstacle(i[0], i[1], True)
        self.ajouterID_obstacles(numbers)

    def moveID(self, pos_x, pos_y, id, taille):
        x0 = pos_x * self.taille + self.taille/2.0 - taille/2.0
        y0 = pos_y * self.taille + self.taille/2.0 - taille/2.0
        x1 = pos_x * self.taille + taille + self.taille/2.0 - taille/2.0
        y1 = pos_y * self.taille + taille + self.taille/2.0 - taille/2.0
        self.canvas.coords(id, x0, y0, x1, y1)    

    def afficherObstacle(self):
        liste_pos = self.map.getPositionObstacles()
        for i in range (len(liste_pos)):
            pos = liste_pos[i]
            self.moveID(pos[0], pos[1], self.liste_id_obstacle[i], self.taille)

    def ajouterID_obstacles(self, nombre =1):
        for i in range (nombre):
            self.liste_id_obstacle.append(self.canvas.create_rectangle(0, 0, self.taille, self.taille, fill = self.color_obstacle))
        self.afficherObstacle()

    def drawCarre(self, n, color, name):
        print (n, color)
        print (name)
开发者ID:CyprienProg,项目名称:Snake,代码行数:62,代码来源:Jeu.py

示例2: __init__

# 需要导入模块: import Map [as 别名]
# 或者: from Map import set_obstacle [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
开发者ID:CyprienProg,项目名称:Snake,代码行数:104,代码来源:Controleur.py


注:本文中的Map.set_obstacle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。