public void Print(TowerOfHanoiGame game, PrintStyleSettings printStyleSettings) { int horizontalPadding = printStyleSettings.HorizontalPadding; string emptySpace = new string(' ', horizontalPadding); int spacing = game.DiskCount > 0 ? game.DiskCount.ToString().Length : 0; int maxHeight = game.GetMaxHeight(); Console.Write(new string('\n', printStyleSettings.VerticalPadding)); for (int i = maxHeight - 1; i >= 0; i--) { string line = ""; for (int j = 0; j < game.TowerCount; j++) { List <int> tower = game.GetTower(j); int value = 0; if (i < tower.Count) { value = tower[i]; } line += value.ToString().PadLeft(spacing) + emptySpace; } Console.WriteLine(line.Trim()); } Console.Write(new string('\n', printStyleSettings.VerticalPadding)); }
protected void Print(TowerOfHanoiGame game, PrintStyleSettings printStyleSettings, char horizontalLine, char verticalLine, char topLeftCorner, char topRightCorner, char bottomLeftCorner, char bottomRightCorner, char horizontalUpIntersection, char horizontalDownIntersection) { int diskWidth = game.DiskCount > 0 ? game.DiskCount.ToString().Length : 0; int maxHeight = game.DiskCount; int horizontalPadding = printStyleSettings.HorizontalPadding; string emptySpace = new string(' ', horizontalPadding); int verticalPadding = printStyleSettings.VerticalPadding; string verticalPaddingPart = horizontalLine + new string(' ', diskWidth + 2 * horizontalPadding); string verticalPaddingLine = verticalPaddingPart.Repeat(game.TowerCount) + horizontalLine; string topLine = topLeftCorner + (horizontalLine.Repeat(diskWidth + horizontalPadding * 2) + horizontalDownIntersection).Repeat(game.TowerCount - 1) + horizontalLine.Repeat(diskWidth + horizontalPadding * 2) + topRightCorner; Console.WriteLine(topLine); Console.Write((verticalPaddingLine + '\n').Repeat(verticalPadding)); for (int i = maxHeight - 1; i >= 0; i--) { string line = ""; for (int j = 0; j < game.TowerCount; j++) { List <int> tower = game.GetTower(j); string disk = new string(' ', diskWidth); if (i < tower.Count) { disk = tower[i].ToString().PadLeft(diskWidth); } line += verticalLine + emptySpace + disk + emptySpace; } Console.WriteLine(line + verticalLine); } Console.Write((verticalPaddingLine + '\n').Repeat(verticalPadding)); string bottomLine = bottomLeftCorner + (horizontalLine.Repeat(diskWidth + horizontalPadding * 2) + horizontalUpIntersection).Repeat(game.TowerCount - 1) + horizontalLine.Repeat(diskWidth + horizontalPadding * 2) + bottomRightCorner; Console.WriteLine(bottomLine); }
public abstract void Print(TowerOfHanoiGame game, PrintStyleSettings printStyleSettings);