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


Python Map.getPositionObstacles方法代码示例

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


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

示例1: Jeu

# 需要导入模块: import Map [as 别名]
# 或者: from Map import getPositionObstacles [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 getPositionObstacles [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

示例3: Serveur

# 需要导入模块: import Map [as 别名]
# 或者: from Map import getPositionObstacles [as 别名]
class Serveur(threading.Thread):
    def __init__(self, interface):
        threading.Thread.__init__(self)
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sockets = {}
        self.interface = interface

        self.map = Map(1,1)
        file = FileMap()
        matrice = file.loadFromFile("map.txt")
        valeur = self.map.loadMatrice(matrice)
        self.running = True
        self.updateMovement()           #Faire classe thread

        #valeurs


    def run(self):
        try:
            self.socket.bind(('',33033))
            print("Serveur connecté, attente de player...")
            self.running = True
            while self.running:
                self.socket.listen(3)
                socket, adresse = self.socket.accept()
                print("Player connecté, adresse IP", adresse[0],", port",adresse[1])
                player = Player(socket, self, self.interface)
                pos = self.map.getRandomFree(3)
                player.setPosition(pos[0], pos[1])
                nom = player.getName()
                self.sockets[nom]=player
                player.start()
                self.interface.updatePlayers()                
                                                             
        except:
            print("La liaison du socket a été interrompue.")
            self.running = False
            self.socket.close()
            print ("Unexpected error:", sys.exc_info())

    def updateMovement(self):
        liste_pos = []
        for name in self.sockets:
            player = self.sockets[name]
            player.updateMovement()
            liste_pos.append(player.getPosition())

        self.send("all", "update players", liste_pos)
        if (self.running):
            self.interface.fenetre.after(200, self.updateMovement)
    
    def isrunning(self):
        return self.running

    def getSizeConnected(self):
        return len(self.sockets)

    def stop(self):
        self.running = False
        self.socket.close()

    def analyse(self, name, message):
        message = json.loads(message)
        if message["type"] == "load map":
            obstacles = self.map.getPositionObstacles()
            data = {"width" : self.map.getLongueur(), "height": self.map.getHauteur(), "numbers":len(obstacles), "obstacles":obstacles}
            self.send(name, "load map", data)
        else:
            print("Type inconnu", message["type"], message["data"])

    def send(self, name, types, data = ""):
        message = {}
        message["type"] = types
        message["data"] = data
        message = json.dumps(message)
        if name == "all":
            for name in self.sockets:
                self.sockets[name].socket.send(message.encode("Utf8"))
        else:
            self.sockets[name].socket.send(message.encode("Utf8"))

    def playerDeconnecte(self, name):
        self.sockets.pop(name)
        print ("Player", name,"déconnecté")
        self.interface.updatePlayers()
开发者ID:CyprienProg,项目名称:Snake,代码行数:87,代码来源:Serveur.py


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