public TileLocationCollection GetSourcesFromDestination(TileLocation destination) { var result = new TileLocationCollection(); foreach (var connection in _items) { if (connection.Destination == destination && !result.Contains(connection.Source)) { result.Add(connection.Source); } } return(result); }
public TileLocationCollection GetDestinationsFromSource(TileLocation source) { var result = new TileLocationCollection(); foreach (var connection in _items) { if (connection.Source == source) { result.Add(connection.Destination); } } return(result); }
public void Read(BinaryReader reader) { var offsetToNextLevel = reader.ReadUInt16() + reader.BaseStream.Position; reader.BaseStream.Seek(sizeof(ushort), SeekOrigin.Current); // Level number timeLimit = reader.ReadUInt16(); chipCount = reader.ReadUInt16(); var paramsRead = new bool[7]; while (reader.BaseStream.Position < offsetToNextLevel) { var field = reader.ReadByte(); if (!paramsRead[0] && field == FIELD_MAPDETAIL) { reader.BaseStream.Seek(sizeof(byte), SeekOrigin.Current); // Field is WORD for some reason; skip a byte upperLayer.Read(reader); lowerLayer.Read(reader); reader.BaseStream.Seek(sizeof(ushort), SeekOrigin.Current); // Skip 'bytes to end of level' paramsRead[0] = true; } else if (!paramsRead[1] && field == FIELD_TITLE) { var length = reader.ReadByte(); title = new string(reader.ReadChars(length), 0, length - 1); paramsRead[1] = true; } else if (!paramsRead[2] && field == FIELD_TRAPCONNECTIONS) { var length = reader.ReadByte(); var buffer = reader.ReadBytes(length); trapConnections.Clear(); for (int i = 0; i < length; i += 10) { trapConnections.Add(new TileConnection(BitConverter.ToInt16(buffer, i), BitConverter.ToInt16(buffer, i + 2), BitConverter.ToInt16(buffer, i + 4), BitConverter.ToInt16(buffer, i + 6))); } paramsRead[2] = true; } else if (!paramsRead[3] && field == FIELD_CLONECONNECTIONS) { var length = reader.ReadByte(); var buffer = reader.ReadBytes(length); cloneConnections.Clear(); for (int i = 0; i < length; i += 8) { cloneConnections.Add(new TileConnection(BitConverter.ToInt16(buffer, i), BitConverter.ToInt16(buffer, i + 2), BitConverter.ToInt16(buffer, i + 4), BitConverter.ToInt16(buffer, i + 6))); } paramsRead[3] = true; } else if (!paramsRead[4] && field == FIELD_PASSWORD) { var buffer = reader.ReadBytes(reader.ReadByte()); password = DecodePassword(buffer); paramsRead[4] = true; } else if (!paramsRead[5] && field == FIELD_HINT) { var length = reader.ReadByte(); hint = new string(reader.ReadChars(length), 0, length - 1); paramsRead[5] = true; } else if (!paramsRead[6] && field == FIELD_MONSTERLOCATIONS) { var length = reader.ReadByte(); var buffer = reader.ReadBytes(length); monsterLocations.Clear(); for (int i = 0; i < length; i += 2) { monsterLocations.Add(new TileLocation(buffer[i], buffer[i + 1])); } paramsRead[6] = true; } } }