Exemple #1
0
        public static void Write(this HanoiComponent component, int discNumber = -1)
        {
            var oldForegroundColor = Console.ForegroundColor;

            Console.ForegroundColor = component.GetColor(discNumber);

            Console.Write(component.GetChar());

            Console.ForegroundColor = oldForegroundColor;
        }
Exemple #2
0
        public static char GetChar(this HanoiComponent component)
        {
            switch (component)
            {
            case HanoiComponent.Base:
                //return '=';
                return('\u25a0');

            case HanoiComponent.Peg:
                //return '|';
                return('\u2588');

            case HanoiComponent.Disc:
                //return '*';
                return('\u2588');

            default:
                throw new Exception(
                          $"Enumeration value {nameof(component)} = {component.ToString()} not handled by programmer.");
            }
        }
Exemple #3
0
        public static ConsoleColor GetColor(this HanoiComponent component, int discNumber = -1)
        {
            switch (component)
            {
            case HanoiComponent.Base:
            case HanoiComponent.Peg:
                return(ConsoleColor.DarkRed);

            case HanoiComponent.Disc:
                // Without the discNumber argument the disc will be
                // colored uniformly with a default color.
                // If the argument is given the disc will be colored
                // according to the number in a repeating color
                // scheme.
                return(discNumber < 1
                            ? ConsoleColor.Yellow
                            : DiscColorWheel().Skip(discNumber - 1).Take(1).Single());

            default:
                throw new Exception(
                          $"Enumeration value {nameof(component)} = {component.ToString()} not handled by programmer.");
            }
        }