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


Python Map.getLongueur方法代码示例

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


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

示例1: __init__

# 需要导入模块: import Map [as 别名]
# 或者: from Map import getLongueur [as 别名]
class Controleur:

    def __init__(self):
        self.map = Map(31, 23)
        self.nourriture = Nourriture()
        self.serpent = Serpent()
        self.oriente = "Down"
        self.vie = True

    def initialize(self):
        self.serpent.setPosition(5,5, "Left")
        self.gui.ajouterID_corps(3)
        self.nouvellePositionNourriture()
        file = FileMap()
        matrice = file.loadFromFile("map.txt")
        valeur = self.map.loadMatrice(matrice)
        self.gui.ajouterID_obstacles(valeur)

    def getPositionBlock(self):
        return self.block.getPosition()

    def getLongueurMap(self):
        return self.map.getLongueur()

    def getHauteurMap(self):
        return self.map.getHauteur()

    def getPositionSerpent(self):
        return self.serpent.getPosition()

    def getPositionNourriture(self):
        return self.nourriture.getPosition()

    def checkEat(self):
        if self.nourriture.getPosition() == self.serpent.getPosition():
            self.serpent.agrandir(1)
            self.gui.ajouterID_corps()
            self.nouvellePositionNourriture()



    def getRandom(self, start, end):
        return randint(start, end)

    def getRandomFree(self):        #Trop aléatoire, DANGER !
        pos = (self.getRandom(0, self.getLongueurMap()-1), self.getRandom(0, self.getHauteurMap()-1))
        while self.checkCollision(pos[0], pos[1]):
            pos = (self.getRandom(0, self.getLongueurMap()), self.getRandom(0, self.getHauteurMap()))
        return pos

    def serpent_goLeft(self):
        self.serpent.move_left(self.getLongueurMap())

    def serpent_goRight(self):
        self.serpent.move_right(self.getLongueurMap())

    def serpent_goUp(self):
        self.serpent.move_up(self.getHauteurMap())

    def serpent_goDown(self):
        self.serpent.move_down(self.getHauteurMap())

    def nouvellePositionNourriture(self):
        pos = self.getRandomFree()
        self.nourriture.setPosition(pos[0], pos[1])
        self.gui.afficherNourriture()

    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()
#.........这里部分代码省略.........
开发者ID:CyprienProg,项目名称:Snake,代码行数:103,代码来源:Controleur.py

示例2: Serveur

# 需要导入模块: import Map [as 别名]
# 或者: from Map import getLongueur [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.getLongueur方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。