Module bzPicture
[frames] | no frames]

Source Code for Module bzPicture

  1  ##bzPicture.py defines vision of world of a BZoo client. 
  2  ##Copyright (C) 2006  Jean-Baptiste PERIN 
  3  ## 
  4  ##This program is free software; you can redistribute it and/or 
  5  ##modify it under the terms of the GNU General Public License 
  6  ##as published by the Free Software Foundation; either version 2 
  7  ##of the License, or (at your option) any later version. 
  8  ## 
  9  ##This program is distributed in the hope that it will be useful, 
 10  ##but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11  ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 12  ##GNU General Public License for more details. 
 13  ## 
 14  ##You should have received a copy of the GNU General Public License 
 15  ##along with this program; if not, write to the Free Software 
 16  ##Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
 17  """ 
 18   This module give a snapshot of a BZoo World 
 19      
 20  """ 
21 -class bzPicture:
22
23 - def __init__ (self ):
24 """ 25 @return: N/A 26 @rtype: bzClient 27 """ 28 29 ## Indexed by players'Ids 30 self.playerspseudos = [] 31 self.playerspositions = [] 32 self.playersorientations = [] 33 self.playersactions = [] 34 self.playersscenes = [] 35 36 ## Received Messages queue 37 self.playersmessages = []
38 39 40 41
42 - def getNbPlayers (self):
43 """ 44 Gives the number of clients connected to the serveur. 45 @return: The number of people connected to the server 46 @rtype: Integer 47 """ 48 return (len(self.pseudos))
49
50 - def getPlayersPseudo (self):
51 """ 52 Gives the list of currently connected players 53 @return: the list of connected players'pseudos 54 @rtype: list of String 55 """ 56 return (self.playerspseudos)
57
58 - def getPlayerId (self, name):
59 """ 60 Gives the Id of the player which pseudo is name 61 @param name: The pseudo of the player. 62 @type name: String 63 @return: the Id of the player. 64 @rtype: Integer 65 """ 66 return (self.pseudos.index(name))
67
68 - def getPlayerPseudo (self, Id):
69 """ 70 Gives the pseudo of the player which id is Id 71 @param Id: The id of the player. 72 @type Id: Integer 73 @return: the pseudo of the player. 74 @rtype: String 75 """ 76 return (self.pseudos[Id])
77
78 - def getPlayerOrientation (self, Id):
79 """ 80 Gives the rotation matrix of the player which Id is Id 81 @param Id: The id of the player. 82 @type Id: Integer 83 @return: the orientation matrix of the player. 84 @rtype: 3*3 Matrix 85 """ 86 return (self.orientations[Id])
87
88 - def getPlayerPosition(self, Id):
89 """ 90 Gives the position vector of the player which id is Id 91 @param Id: The id of the player. 92 @type Id: Integer 93 @return: the position of the player [PosX, PosY, PosY]. 94 @rtype: 3*1 Vector 95 """ 96 return (self.positions[Id])
97
98 - def getPlayerAction(self, Id):
99 """ 100 Gives the action the player is currently performing 101 @param Id: The id of the player. 102 @type Id: Integer 103 @return: the action played by the player. 104 @rtype: Integer 105 """ 106 return (self.actions[Id])
107
108 - def getPlayerScene(self, Id):
109 """ 110 Gives the scene the player is in. 111 @param Id: The id of the player. 112 @type Id: Integer 113 @return: the scene number the player is in. 114 @rtype: Integer 115 """ 116 return (self.actions[Id])
117
118 - def getPlayersOrientations(self,):
119 """ 120 Gives a list of player's rotation matrix. 121 @return: the list of players rotation matrix. 122 @rtype: list of 3*3 Matrix. 123 """ 124 return (self.playersorientations)
125
126 - def getPlayersPositions(self,):
127 """ 128 Gives a list of player's position vector. 129 @return: the list of players position vector [posX, posY, posY]. 130 @rtype: list of 3*1 Vector. 131 """ 132 return (self.playerpositions)
133
134 - def getPlayersActions(self,):
135 """ 136 Gives a list of player's action. 137 @return: the list of players action. 138 @rtype: list of Integer. 139 """ 140 return (self.playeractions)
141
142 - def getPlayersScenes(self,):
143 """ 144 Gives a list of player's scene. 145 @return: the list of players scene. 146 @rtype: list of Integer. 147 """ 148 return (self.playersscenes)
149 150
151 - def popTextMessage(self,):
152 """ 153 Gives the next received text message and remove it from pending message 154 @return: the next message (sender_pseudo , message). 155 @rtype: tuple {String, String} or None 156 """ 157 return (self.playersmessages.pop(0))
158 159
160 - def updateFromMessageList(self, msgList):
161 """ 162 Updates picture information from a message list. 163 @param msgList: The list of recently received message . 164 @type msgList: dictionnary 165 """ 166 for mess in msg_list.keys(): 167 168 169 #print "receiving data ", msg_list 170 if mess == "1": 171 self.pseudos, self.positions, self.orientations, self.actions = msg_list["1"] 172 self.id = self.pseudos.index(self.pseudo) 173 174 elif mess == "3": 175 ids, messages = msg_list["3"] 176 for idx_client in range (len(ids)): 177 #print self.pseudos[self.ids[idx_client]], self.messages[idx_client] 178 self.display.QueueMessage( messages[idx_client], self.pseudos[ids[idx_client]]) 179 180 elif mess == "0": 181 #msglist[mess][0]?? 182 self.playerspositions[idClient] = msglist[mess][0] 183 self.playersorientations[idClient] = msglist[mess][1] 184 self.playersactions[idClient] = msglist[mess][2] 185 186 elif mess == "2" : 187 #self.playersmessages.append (self.getPlayerPseudo(???),msg_list[mess][0]) 188 pass 189 190 else: 191 print "Unkown message type %s "%mess
192 193 194 195 if __name__ == "__main__": 196 print "bzPicture" 197 198 aPicture = bzPicture() 199 200 #aPicture.updateFromMessageList(msgList) 201 202 del aPicture 203