private void InitializeMaze( IList <string> mazeDefinition) { MazeCells = new Dictionary <GridPoint, DonutMazeCell>(); for (int y = 0; y < mazeDefinition.Count; y++) { var rowString = mazeDefinition[y]; for (int x = 0; x < rowString.Length; x++) { var point = new GridPoint(x, y); var cellDefinition = rowString[x].ToString(); if (string.IsNullOrWhiteSpace(cellDefinition)) { continue; } var mazeCellType = DonutMazeCellType.Empty; var portalLetter = string.Empty; if ("#".Equals(cellDefinition)) { mazeCellType = DonutMazeCellType.Wall; } else if (Regex.IsMatch(cellDefinition, @"^[A-Z]$")) { mazeCellType = DonutMazeCellType.Portal; portalLetter = cellDefinition; } var mazeCell = new DonutMazeCell(point, mazeCellType, portalLetter); MazeCells.Add(point, mazeCell); } } CalculateMazeBoundaries(); ConstructPortals(); }
public string GetCellString(GridPoint point) { if (!MazeCells.ContainsKey(point)) { return(" "); } return(DonutMazeCell.GetCellString(MazeCells[point])); }
public static string GetCellString(DonutMazeCell cell) { if (DonutMazeCellType.Empty.Equals(cell.Type)) { return("."); } if (DonutMazeCellType.Wall.Equals(cell.Type)) { return("#"); } if (DonutMazeCellType.Portal.Equals(cell.Type)) { return(cell.PortalLetter); } return(" "); }