public RectangleMaze(IMazeBuilder mazeBuilder, IMazeSchema mazeSchema, ILocation startLocation) { StartLocation = startLocation; Walls = new List <IWall>(); Paths = new List <IPath>(); ThreeSixtyView = new Dictionary <ILocation, Dictionary <Direction, IBuildingBlock> >(); string[] schemaLines = mazeSchema.GetSchema().Split(new[] { Environment.NewLine }, StringSplitOptions.None); IBuildingBlockIdentifier wallIdentifier = GetBuildingBlockIdentifier(mazeSchema, BuildingBlockType.Wall); IBuildingBlockIdentifier pathIdentifier = GetBuildingBlockIdentifier(mazeSchema, BuildingBlockType.Path); List <List <IBuildingBlock> > buildingBlocksByRows = CreateBuildingBlocks(mazeBuilder, schemaLines, wallIdentifier, pathIdentifier); PopulateThreeSixtyView(buildingBlocksByRows); foreach (List <IBuildingBlock> buildingBlocks in buildingBlocksByRows) { foreach (IBuildingBlock buildingBlock in buildingBlocks) { switch (buildingBlock.GetBuildingBlockType()) { case BuildingBlockType.Wall: Walls.Add(buildingBlock as IWall); break; case BuildingBlockType.Path: Paths.Add(buildingBlock as IPath); break; default: throw new NotImplementedException(); } } } }
private IBuildingBlockIdentifier GetBuildingBlockIdentifier(IMazeSchema mazeSchema, BuildingBlockType buildingBlockType) { return((from x in mazeSchema.GetBuildingBlockDefinations() where x.GetBuildingBlockType() == buildingBlockType select x).FirstOrDefault()); }