コード例 #1
0
        private List <List <IBuildingBlock> > CreateBuildingBlocks(IMazeBuilder mazeBuilder, string[] schemaLines, IBuildingBlockIdentifier wallIdentifier, IBuildingBlockIdentifier pathIdentifier)
        {
            List <List <IBuildingBlock> > buildingBlocksByRows = new List <List <IBuildingBlock> >();

            for (int schemaRowIndex = 0; schemaRowIndex <= schemaLines.Length - 1; schemaRowIndex++)
            {
                List <IBuildingBlock> buildingBlocksInRow = new List <IBuildingBlock>();
                buildingBlocksByRows.Add(buildingBlocksInRow);

                string   schemaRow     = schemaLines[schemaRowIndex].Trim();
                string[] schemaColumns = schemaRow.Split();

                int        latiduteIndex = -1; //To Keep track of space which is not BuildingBlock
                ILongitude longitude     = mazeBuilder.CreateLongitude(schemaRowIndex);

                for (int schemaColumnIndex = 0; schemaColumnIndex <= schemaColumns.Length - 1; schemaColumnIndex++)
                {
                    BuildingBlockType?buildingBlockType = null;

                    if (schemaColumns[schemaColumnIndex].ToString() == wallIdentifier.GetIdentifier().ToString())
                    {
                        buildingBlockType = BuildingBlockType.Wall;
                    }
                    else if (schemaColumns[schemaColumnIndex].ToString() == pathIdentifier.GetIdentifier().ToString())
                    {
                        buildingBlockType = BuildingBlockType.Path;
                    }

                    if (buildingBlockType.HasValue)
                    {
                        latiduteIndex++;
                        ILatitude      latitude = mazeBuilder.CreateLatitude(latiduteIndex);
                        ILocation      location = mazeBuilder.CreateLocation(latitude, longitude);
                        IBuildingBlock buildingBlock;
                        switch (buildingBlockType)
                        {
                        case BuildingBlockType.Wall:
                            buildingBlock = mazeBuilder.CreateWall(location);
                            break;

                        case BuildingBlockType.Path:
                            buildingBlock = mazeBuilder.CreatePath(location);
                            break;

                        default:
                            throw new NotImplementedException();
                        }

                        buildingBlocksInRow.Add(buildingBlock);
                    }
                }
            }

            return(buildingBlocksByRows);
        }