def loadMap(self,fileName): self.Map = FileReader.readMap(fileName)
def init(self, pathToBoardFile, configs, pathToPlayerFile = None): """ This function is called to initialize the Board from a board-file or a status-file. If the pathToPlayerFile parameter is given, the first parameter is interpreted as the path to the board-file If the pathToPlayerFile parameter is omitted, the first parameter is interpreted as the path to the status-file :param pathToBoardFile: Path to board-file/status-file :param pathToPlayerFile: Path to the file of players :return: """ if pathToPlayerFile is None: # can be called by player programs, is able to extract the information in the boardCurrent file # now this functions create only the matrix, but player infos and config infos could also be stored, but where( should player objects be created??) d={} key="" with open(os.path.join(pathToOutputDirectory,"boardCurrent.txt")) as f: for line in iter(f): logging.debug( "reading line ",line) if line.startswith("board:"): emptyList = [] key="board" d.update({key:emptyList}) continue if line.startswith("configs:"): emptyList = [] key="configs" d.update({key:emptyList}) continue if line.startswith("board data:"): emptyList = [] key ="board data" d.update({key:emptyList}) continue if line.startswith("player coins:"): emptyList = [] key ="player coins" d.update({key:emptyList}) continue if(key): # key is not empty d[key].append(line) f.close() for line in d["board"]: self.matrix.append(line) else: #config self.configs = configs self.coins = int(configs.numberOfCoins) self.updateTime = float(configs.waitingTime) #store board from Board File to matrix, this file will be read only once self.matrix = FileReader.readMap(pathToBoardFile) #store players from File in list players: list of tuples(character, path to shell script) with open(pathToPlayerFile) as playerFile: for row in playerFile: rowSplits = row.split('\t') self.players.append((rowSplits[0], rowSplits[1].rstrip('\n'))) playerFile.close() #create player info list for i in range(len(self.players)): charPlayer, filePlayer = self.players[i] self.playerInfo[charPlayer] = Player(charPlayer,filePlayer) #add players from Player File at random positions size = len(self.matrix) size2 = len(self.matrix[0]) for p in self.players: index1 = randint(0,size-1) index2 = randint(0,size2-1) while(self.matrix[index1][index2] != ' '): index1 = randint(0,size-1) index2 = randint(0,size2-1) if self.matrix[index1][index2] == ' ': self.matrix[index1][index2] = p[0] self.playerInfo[p[0]].Position = (index1,index2)
IsGridInitialized=False def onGridInitialized(): """ callback function for the GUI thread. It is called after the grid is initialized and before the TK mainloop has been started. (this is before something is visible) """ global IsGridInitialized IsGridInitialized=True if __name__ == '__main__': gui = GUI(onGridInitialized) #gui.loadMap("../boards/testBoard.txt") gui.Map = FileReader.readMap("../boards/testBoard.txt") gui.start() #start separate GUI thread and wait for the grid to be initialized while(not IsGridInitialized): time.sleep(0.1) time.sleep(0.1) gui.addCoinToCell((0,1)) time.sleep(0.1) gui.addCoinToCell((0,2)) time.sleep(0.1) gui.removeItemFromCell((0,1)) numberOfPlayers = gui.getMaxPlayers() playerIndex = 0