private void SetupPlayers(PlayerList players, PlayerLocationInfo[] locations) { List <Player> playerList = players.list; foreach (Player player in playerList) { int index = player.GetIndex(); PlayerLocationInfo info = locations[index]; int cx = info.x; int cy = info.y; if (cx == 0 && cy == 0) { AddCell(player); } else { player.SetCell(info.x, info.y); } ClearBrick(cx - 1, cy); ClearBrick(cx, cy - 1); ClearBrick(cx + 1, cy); ClearBrick(cx, cy + 1); } }
protected override Asset Read(BinaryReader reader) { Scheme scheme = new Scheme(); scheme.name = reader.ReadString(); scheme.brickDensity = reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); scheme.fieldData = new FieldData(width, height); FieldBlocks[] blocks = scheme.fieldData.GetDataArray(); for (int i = 0; i < blocks.Length; ++i) { blocks[i] = (FieldBlocks)reader.ReadInt32(); } int playersCount = reader.ReadInt32(); PlayerLocationInfo[] playerLocations = new PlayerLocationInfo[playersCount]; for (int i = 0; i < playerLocations.Length; ++i) { int x = reader.ReadInt32(); int y = reader.ReadInt32(); int team = reader.ReadInt32(); playerLocations[i] = new PlayerLocationInfo(i, x, y, team); } scheme.playerLocations = playerLocations; int powerupsCount = reader.ReadInt32(); PowerupInfo[] powerupInfo = new PowerupInfo[powerupsCount]; for (int i = 0; i < powerupInfo.Length; ++i) { powerupInfo[i].powerupIndex = reader.ReadInt32(); powerupInfo[i].bornWith = reader.ReadBoolean(); powerupInfo[i].hasOverride = reader.ReadBoolean(); powerupInfo[i].overrideValue = reader.ReadInt32(); powerupInfo[i].forbidden = reader.ReadBoolean(); } scheme.powerupInfo = powerupInfo; return(scheme); }
////////////////////////////////////////////////////////////////////////////// #region Server Info internal static ServerInfo ReadServerInfo(NetIncomingMessage message) { // name String name = message.ReadString(); // scheme Scheme scheme = new Scheme(); // scheme: name scheme.name = message.ReadString(); // scheme: field data int fieldWidth = message.ReadInt32(); int fieldHeight = message.ReadInt32(); FieldBlocks[] fieldDataArray = new FieldBlocks[fieldWidth * fieldHeight]; for (int i = 0; i < fieldDataArray.Length; ++i) { fieldDataArray[i] = (FieldBlocks)message.ReadByte(); } scheme.fieldData = new FieldData(fieldWidth, fieldHeight, fieldDataArray); // scheme: player locations int locationsCount = message.ReadByte(); PlayerLocationInfo[] playerLocations = new PlayerLocationInfo[locationsCount]; for (int i = 0; i < locationsCount; ++i) { int x = message.ReadByte(); int y = message.ReadByte(); int team = message.ReadByte(); playerLocations[i] = new PlayerLocationInfo(i, x, y, team); } scheme.playerLocations = playerLocations; ServerInfo info = new ServerInfo(name, message.SenderEndPoint); info.scheme = scheme; return(info); }