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


Python Map类代码示例

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


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

示例1: Jeu

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,代码行数:60,代码来源:Jeu.py

示例2: __init__

	def __init__(self, server, color, levelPreset = "empty"):
		self.server = server

		self.butterflies = []

		self.screen = pygame.display.get_surface()

		self.backgroundImage, self.backgroundRect = loadPNG("background.png")

		self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
		self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)

		self.active = True

		if levelPreset == "empty":
			self.level = Map()
		else:
			self.level = Map(True)

		self.toolbar = GameToolbar()

		self.regis = Rabbit(1, "regis" , color, self.level.objectList, self.level.objectSpritesList)

		self.server.accept()
		self.server.send(b"connexion avec client : OK")
		msg = self.server.recieve()

		mapStr = self.level.getMapStr()

		#MAP STRING SEND
		self.server.send(struct.pack(str(len(mapStr)) + "s", mapStr))

		#SERVER RABBIT COLOR SEND
		self.server.send(struct.pack("iii", self.regis.color[0], self.regis.color[1], self.regis.color[2]))

		#CLIENT RABBIT COLOR RECIEVE
		clientCol = self.server.recieve()
		clientCol = struct.unpack("iii", clientCol)

		#CREATE CLIENT RABBIT
		self.john = Rabbit(2, "john" , clientCol, self.level.objectList, self.level.objectSpritesList, True)

		self.regis.appendRabbit(self.john)
		self.john.appendRabbit(self.regis)

	 	self.pauseMenu = PauseGameMenu()

		self.deltaCarrot = 0
		self.timeCarrot = random.randint(1, 4)

	# 	for l in range(0, 6):
	# 		while True:
	# 			randPos = random.randint(0, 16)
	# 			if not self.level.isInBlock(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26):
	# 				break

	# 		butterfly = Butterfly(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26, (255, 10, 100), self.level.objectList, self.level.objectSpritesList)
	# 		self.butterflies.append(butterfly)

	 	pygame.display.flip()
开发者ID:Barbatos,项目名称:BumpNJump,代码行数:60,代码来源:MultiServerGame.py

示例3: new_game

def new_game():
    global player, inventory, game_msgs, game_state, dungeon_level

    #create object representing the player
    entity_component = Entity(5)
    GameState.player = Object(0, 0, '@', 'player', libtcod.white, blocks=True, entity=entity_component)

    GameState.player.level = 1

    #generate map (at this point it's not drawn to the screen)
    dungeon_level = 1
    Map.make_map()
    initialize_fov()

    game_state = 'playing'
    GameState.inventory = []

    #create the list of game messages and their colors, starts empty
    GameState.game_msgs = []

    #a warm welcoming message!
    GUI.message('Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', libtcod.red)

    #initial equipment: a dagger
    equipment_component = Equipment(slot='right hand', power_bonus=2)
    obj = Object(0, 0, '-', 'dagger', libtcod.sky, equipment=equipment_component)
    GameState.inventory.append(obj)
    equipment_component.equip()
    obj.always_visible = True
开发者ID:edrobot,项目名称:PythonRoguelike_Spring-2014,代码行数:29,代码来源:GameFlow.py

示例4: throwItem

def throwItem(position,index): #Jette un objet
    global throw
    throw = 0
    Map.addItem(position,Player.getItem(index))
    descript = "Vous jetez " + Player.getItemName(index)
    Player.removeItem(index)
    return descript
开发者ID:ValentinPearce,项目名称:The-Shades,代码行数:7,代码来源:OriginalGame.py

示例5: MainWindow

class MainWindow(QMainWindow):
    '''Wrapper class for...well, the game? Maybe this needs to be called the game engine then'''

    def __init__(self):
        '''
        Only initialize critical components(like opengl) here, use start() for anything else
        '''
        QMainWindow.__init__(self)

        Globals.glwidget = GLWidget(self)
        self.setCentralWidget(Globals.glwidget)
        Globals.glwidget.makeCurrent() 
        
        if Globals.musicOn:
            print "Using music"
            Globals.mediaobject = Phonon.MediaObject(self)
            self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
            Phonon.createPath(Globals.mediaobject, self.audioOutput)

        self.map = Map() #map class

        self.drawTimer = QTimer()
        self.drawTimer.timeout.connect(self.drawTimerTimeout)
        self.drawTimer.start(15)
        
    def start(self):
        if Globals.musicOn:
            Globals.muspanel = MusPanel(self)

        #draw map... set view to ground
        Globals.view = self.map.generateMap()

    def drawTimerTimeout(self):
        self.map.update()
        Globals.glwidget.updateGL()
开发者ID:tchen,项目名称:OpenAnt,代码行数:35,代码来源:main.py

示例6: main

def main():
    player1 = Player("Player 1")
    player2 = Player("Player 2")
    players = [player1, player2] # TODO: Change when number of players changes
    numOfPlayers = len(players)
    currentPlayer = player1.id

    inf1 = Unit("infantry", 0, 5, "green", 0, 0)
    cav1 = Unit("cavalry", 0, 1, "blue", 1, 1)

    # Test code for Map
    unitsList = []
    terrainList = []
    initialize_map_1(unitsList, terrainList, 15, 8)

    unitsList[inf1.y][inf1.x] = inf1
    unitsList[cav1.y][cav1.x] = cav1

    map = Map(unitsList, terrainList)

    # Main game loop
    choice = " "
    while choice != "exit":
        displayUnits(unitsList)
        map.display()
        menuDisplay(players, currentPlayer)
        choice = input("> ")

        # Make the appropriate action
        takeAction(choice, map, players, currentPlayer)

        # switch to next player's turn
        currentPlayer = nextTurn(currentPlayer, numOfPlayers)
开发者ID:is4ac,项目名称:map-army-game,代码行数:33,代码来源:Main.py

示例7: LoadGame

def LoadGame():
    if not reloadGame:
        loadHolder = maps.load() 
        maps.new_blocks = loadHolder[0]
        player.rect = loadHolder[1]
        objects.all_objects = loadHolder[2]
    else:
        maps.loadMap()
开发者ID:Kanon121,项目名称:TheGame-Multiplayer,代码行数:8,代码来源:Globals.py

示例8: build_constelation

	def build_constelation(self,mol):
		if mol.acteur == None :
			MB.showwarning('Info','Select a molecule in the list')
			return
		if mol.symobs !=None:
			mol.acteur.RemoveObserver(mol.symobs)
		if mol.lsm!=[]:
			for sm in mol.lsm:
				self.gfx.renderer.RemoveActor(sm)
			mol.lsm=[]
		(xmin, xmax, ymin, ymax, zmin, zmax)= self.bounds
		sym=open(self.symlistfile,'r')
		for l in sym:
			ms = l.split()
			nbl = int(ms[6][1:])
			if nbl not in mol.lnbsm:
				continue
			ang = [float(ms[0]),float(ms[1]),float(ms[2])]
			tra = array([float(ms[3]),float(ms[4]),float(ms[5])])
			sm=symmate() #on cree un symmate vide
			sm.SetPosition(mol.acteur.GetPosition()) #on assigne la partie translationelle des pv
			sm.SetOrientation(mol.acteur.GetOrientation()) #on assigne la partie rotationelle des pv
			self.RotaEuler(sm.ut,ang[0],ang[1],ang[2]) #on defini la partie rotationelle de la transformation
			sm.ut.Translate(tra[0],tra[1],tra[2]) #on defini la partie translationelle de la transformation
			sm.SetUserTransform(sm.ut) #on assigne la transformation a notre symmate
			pip = [sm.GetMatrix().GetElement(0,3),sm.GetMatrix().GetElement(1,3),sm.GetMatrix().GetElement(2,3)]#on recupere la partie translationelle de la combinaison de pv et de la transformation (ut)
			if (xmin + self.mdbe < pip[0]) and (pip[0] < xmax - self.mdbe) and (ymin + self.mdbe < pip[1]) and (pip[1] < ymax - self.mdbe) and (zmin + self.mdbe < pip[2]) and (pip[2] < zmax - self.mdbe):# on test si pip est dans la boite
				sm.nbsym=nbl
				if mol.acteur.GetClassName()=='vtkAssembly':# dans le cas ou la molecule independante est un assembly
					for i in range(mol.acteur.GetNumberOfPaths()):
						tmp=vtk.vtkActor()
						tmp.SetMapper(mol.acteur.GetParts().GetItemAsObject(i).GetMapper())
						p=vtk.vtkProperty()
						#p.SetColor(mol.acteur.GetParts().GetItemAsObject(i).GetProperty().GetColor())
						p.SetColor(Map.invcolor(mol.acteur.GetParts().GetItemAsObject(i).GetProperty().GetColor()))
						tmp.SetProperty(p)
						if mol.mod.type=='mol':
							tmp.GetProperty().SetLineWidth(4)
						tmp.DragableOff()
						tmp.PickableOff()
						sm.AddPart(tmp)
				else:#cas simple ou la mol ind est composer d un seul objet
					tmp=vtk.vtkActor()
					tmp.SetMapper(mol.acteur.GetMapper())
					p=vtk.vtkProperty()
					#p.SetColor(mol.acteur.GetParts().GetItemAsObject(i).GetProperty().GetColor())
					p.SetColor(Map.invcolor(mol.acteur.GetProperty().GetColor()))
					tmp.SetProperty(p)
					if mol.mod.type=='mol':
							tmp.GetProperty().SetLineWidth(4)
					tmp.DragableOff()
					tmp.PickableOff()
					sm.AddPart(tmp)
				mol.lsm+=[sm]# on ajoute le symmate a la liste des symmate
		sym.close()
		self.move_sym(mol)
开发者ID:ggoret,项目名称:VEDA,代码行数:56,代码来源:sym.py

示例9: __init__

	def __init__ (self, search_range = 100):
		bjmap = Map()
		filenames = ["bjmap/road"]
		bjmap.load_roads(filenames)
		bjmap.stat_map_info()	

		bjmap.index_roads_on_grid()
		bjmap.gen_road_graph()

		self.traj_map = bjmap
		self.search_range = search_range

		#for constructing a coordinate map in meters
		m_latitude = (self.traj_map.min_latitude + self.traj_map.max_latitude) / 2
		self.WIDTH = map_dist(self.traj_map.min_longitude, m_latitude, self.traj_map.max_longitude, m_latitude)
		m_longitude = (self.traj_map.min_longitude + self.traj_map.max_longitude) / 2
		self.HEIGHT = map_dist(m_longitude, self.traj_map.min_latitude, m_longitude, self.traj_map.max_latitude)

		print "Connecting..Database: shortest_path..."
		self.conn_sp = psycopg2.connect(host='localhost', port='5432', database="mapmatching", user='postgres',password='123456')

		print "Connected!"
		self.cursor_sp = self.conn_sp.cursor()

		self.shortest_path = {}
		self.initialize_sp()

		self.supp = {}
开发者ID:LabNAYO,项目名称:MapMatching-on-JStorm,代码行数:28,代码来源:Matching.py

示例10: pickItem

def pickItem(position,index): #Ramasse un objet
    global pick
    pick = 0
    print "add"
    Player.addItem(Map.getItem(position,index))
    print "describe"
    descript = "Vous ramassez " + Map.getItemName(position,index)
    print "remove"
    Map.removeItem(position,index)
    print "return"
    return descript
开发者ID:ValentinPearce,项目名称:The-Shades,代码行数:11,代码来源:OriginalGame.py

示例11: init

def init(): # Defini les variables de depart
    global descript, myBackground
    myBackground=Background.create("background","victoire","defaite","menu")
    Background.show(myBackground,"menu")
    Player.setName()
    Player.setHealth()
    Player.setPower()
    Map.generate(6)
    descript = descript()
    tty.setcbreak(sys.stdin.fileno())
    return descript
开发者ID:ValentinPearce,项目名称:The-Shades,代码行数:11,代码来源:OriginalGame.py

示例12: getInput

def getInput():
    options = [];
    if Globals.gameState != "Load" and Globals.player.dead():
        Globals.quitGame = True
    else:
        if(Globals.gameState == "Load"):
            options.append(Selection("New Game", ["new", "new game"], "create()"))
            options.append(Selection("Load Game", ["load", "load game"], "load()"))

        if Globals.gameState == "Running":
            options.append(Selection("Fight", ["fight", "fight something"], "testCombat()"))
            options.append(Selection("Display Character",["display","display character"], "print(Globals.player)"))

        if Globals.gameState == "Dungeon":
            options.append(Selection("Move(N,S,E,W)",["n","north","s","south","e","east","w","west"],"Map.mapMain(valInput)"))
            if Map.positionCheck() == [0,4]:
                if Globals.getKey == False:
                    options.append(Selection("Get Key",["get","get key"],"Globals.getKey= True"))
            elif Map.positionCheck() == [4,5]:
                if Globals.doorUnlocked == False:
                    if Globals.getKey:
                        options.append(Selection("Unlock Door",["unlock","unlock door"],"Globals.doorUnlocked = True"))
            if Map.positionCheck() == [2,4]:
                options.append(Selection("Rest",["rest"],"Globals.player.rest()"))
            options.append(Selection("Display Character",["display","display character"], "print(Globals.player)"))
            if Globals.defeatBoss:
                options.append(Selection("New Game +",["new","new game", "new game +"],"newGamePlus()"))
            options.append(Selection("Cheat",["xyzzy"],"Globals.player.AP += 1000"))

        if Globals.gameState == "Combat":
            pass

        if Globals.gameState != "Load" and Globals.gameState != "Combat":
            if Globals.player.AP >= 100:
                options.append(Selection("Level Up", ["level", "level up"], "level()"))
            options.append(Selection("Save Game", ["save", "save game"], "save()"))
        options.append(Selection("Exit Game", ["exit", "exit game"], "quitGame()"))
        stroptions = "("
        for i in range(0, len(options), 1):
            stroptions += str(options[i])
            if i < len(options)-1:
                stroptions += ", "
        stroptions += ")"
        valid = False
        selection = None
        while not valid:
            valInput = input("\nWhat would you like to do? " + str(stroptions) + "\n>").lower()
            for sel in options:
                if sel.validSel(valInput):
                    valid = True
                    selection = sel
                    break
        exec(sel.codeToExecute)
开发者ID:sublethalpanda,项目名称:QSQ,代码行数:53,代码来源:QSO.py

示例13: on_paint

 def on_paint(self,event):
     dc = wx.PaintDC(event.GetEventObject())
     dc.Clear()
     dc.SetPen(wx.Pen("BLACK", 4))
     
     map = Map()
     mapaArray = map.creaPoligono()
     for j in range(0, len(mapaArray)):
         #print mapaArray
         print len(mapaArray[j].polarr)
         for i in range (0,len(mapaArray[j].polarr) - 1):
             dc.DrawLine(int(mapaArray[j].polarr[i].x),int(mapaArray[j].polarr[i].y), int(mapaArray[j].polarr[i + 1].x),int(mapaArray[j].polarr[i + 1].y),)
开发者ID:Eencsio,项目名称:AlgoritmosFinal,代码行数:12,代码来源:Interface.py

示例14: __init__

	def __init__(self, ki=False, level=50):

		# Asking for 'human' I prefer before asking for dump, deadly
		# fast calculating machines...so, I called the member 'human'.
		# I called the "level" now 'ki_level' to make clear it is only
		# valid for computer players, not for human ones.
		self.human		= not ki
		self.ki_level	= level

		# The Player needs some counters for counting his ships
		# 'ship_count' which not sunk so far and a list of ships his foe
		# has already. This is 'foeships'.
		self.ship_count	= 0
		self.foeships	= []

		# Now the maps. Because the handling of maps may be difficult,
		# this is encapsulated in another class called 'Map'. I called
		# them 'ships' for the secret map the Player hold his own ships.
		# And 'hits' which is his open map to track the bombardments.
		self.ships	= Map()
		self.hits	= Map()

		# The player (especially the KI) needs to remember the last
		# turn's result. So here we hold space to save is...
		self.last_result = None
开发者ID:OBdA,项目名称:battleships,代码行数:25,代码来源:battleships.py

示例15: Game

class Game(object):

    Ranked, Unranked = range(2)
    Blind, Draft, Random = range(3)

    phases = 3

    def __init__(self, sid, stype = Unranked, smode = Draft, spublic = False, mapsettings = (4, 4, 3) ):
        self.id = sid
        self.type = stype #ranked?
        self.mode = smode #draft?
        self.public = spublic

        self.players = []

        # Pending meta requests (rewind, draw, etc)
        self.requests = [];
        
        self.rosters = {}
        if self.mode == self.Draft:
            self.bans = {}
        
        self.map = Map(mapsettings)
        self.states = {}
        self.states[(0,0)] = self.map.getState((0,0))
开发者ID:jseakle,项目名称:lol,代码行数:25,代码来源:Game.py


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