예제 #1
0
        public static void SetLine(this ITextInterface @this, int lineIndex, string text)
        {
            Guard.AgainstNull(@this, nameof(@this));
            Guard.AgainstNull(text, nameof(text));

            if (text.Length > @this.WindowWidth)
            {
                throw new ArgumentException($"{nameof(text)} must be less than {nameof(ITextInterface)}.{nameof(@this.WindowWidth)}");
            }

            int currentLine   = @this.CursorTop;
            int currentColumn = @this.CursorLeft;

            @this.CursorTop  = lineIndex;
            @this.CursorLeft = 0;

            @this.Write(text);

            if (text.Length < @this.WindowWidth)
            {
                for (int i = text.Length; i < @this.WindowWidth; i++)
                {
                    @this.Write(" ");
                }
            }

            @this.CursorTop  = currentLine;
            @this.CursorLeft = currentColumn;
        }
예제 #2
0
        public static char ReadSingleCharFromList(this ITextInterface @this, params char[] validChars)
        {
            Guard.AgainstNull(@this, nameof(@this));
            Guard.AgainstNullOrEmptyEnumerable(validChars, nameof(validChars));

            var upperValidChars = validChars.Select(chr => Char.IsLower(chr) ? Char.ToUpper(chr) : chr);

            while (true)
            {
                var inputChar = @this.ReadKey();
                if (char.IsLower(inputChar))
                {
                    inputChar = char.ToUpper(inputChar);
                }

                if (upperValidChars.Contains(inputChar))
                {
                    return(inputChar);
                }
                else
                {
                    @this.Backspace();
                }
            }
        }
예제 #3
0
        public static void ClearCurrentLine(this ITextInterface @this)
        {
            Guard.AgainstNull(@this, nameof(@this));

            @this.SetLine(@this.CursorTop, new string(' ', @this.WindowWidth));
            @this.CursorLeft = @this.BufferLeft;
        }
예제 #4
0
        public static bool GetYesOrNoResponse(this ITextInterface @this, string questionText, char yesChar = 'Y', char noChar = 'N')
        {
            Guard.AgainstNull(@this, nameof(@this));
            Guard.AgainstNull(questionText, nameof(questionText));

            @this.Write($"{questionText} ({yesChar}|{noChar}): ");
            return(ReadSingleCharFromList(@this, new char[] { yesChar, noChar }) == yesChar);
        }
예제 #5
0
        public DrawCardsCommandHandler(KeyInputSettings settings, ITextInterface textInterface, ICardCollectionFactory cardCollectionFactory) : base(textInterface)
        {
            Guard.AgainstNullDataContainer(settings, nameof(settings));
            Guard.AgainstNull(textInterface, nameof(textInterface));
            Guard.AgainstNull(cardCollectionFactory, nameof(cardCollectionFactory));

            this.drawCardKey           = settings.DrawCardKey;
            this.cardCollectionFactory = cardCollectionFactory;
        }
예제 #6
0
        public PlayerCollectionFactory(ITextInterface textInterface, IPlayerFactory playerFactory, PlayerSettings playerSettings)
        {
            Guard.AgainstNull(textInterface, nameof(textInterface));
            Guard.AgainstNull(playerFactory, nameof(playerFactory));
            Guard.AgainstNullDataContainer(playerSettings, nameof(playerSettings));

            this.playerFactory  = playerFactory;
            this.textInterface  = textInterface;
            this.playerSettings = playerSettings;
        }
예제 #7
0
        public static int ReadIntegerInRange(this ITextInterface @this, int minimum, int maximum)
        {
            Guard.AgainstNull(@this, nameof(@this));

            if (maximum < minimum)
            {
                throw new ArgumentException($"{nameof(minimum)} must be less than or equal to {nameof(maximum)}.");
            }

            int value      = 0;
            int startIndex = @this.CursorLeft;
            var input      = "";

            while (true)
            {
                var inputChar = @this.ReadKey();
                if (char.IsNumber(inputChar))
                {
                    input += inputChar;
                    var yoyo = (int)inputChar;
                    value = Int32.Parse(input);
                    if (value >= minimum)
                    {
                        if (value <= maximum)
                        {
                            return(value);
                        }
                        else
                        {
                            input = input.Substring(0, input.Length - 1);
                            @this.Backspace();
                        }
                    }
                }
                else if (inputChar == 8)
                {
                    if (@this.CursorLeft == startIndex - 1)
                    {
                        @this.Write(" ");
                    }
                    else
                    {
                        input = (input.Length > 0) ? input.Substring(0, input.Length - 1) : input;
                        @this.Write(" \b");
                    }
                }
                else
                {
                    @this.Backspace();
                }
            }
        }
예제 #8
0
        public CardGameSessionManager(KeyInputSettings settings, ITextInterface textInterface, IPlayerCollectionFactory playerCollectionFactory, ICardGameFactory cardGameFactory)
        {
            Guard.AgainstNullDataContainer(settings, nameof(settings));
            Guard.AgainstNull(textInterface, nameof(textInterface));
            Guard.AgainstNull(playerCollectionFactory, nameof(playerCollectionFactory));
            Guard.AgainstNull(cardGameFactory, nameof(cardGameFactory));

            this.continueRoundKey          = settings.ContinueRoundKey;
            this.exitKey                   = settings.ExitKey;
            this.playerCollectionFactory   = playerCollectionFactory;
            this.cardGameFactory           = cardGameFactory;
            this.textInterface             = textInterface;
            this.textInterface.KeyPressed += TextInterface_KeyPressed;
        }
예제 #9
0
        public static string ReadLine(this ITextInterface @this, int maximumLength, int minimumLength = 0)
        {
            Guard.AgainstNull(@this, nameof(@this));

            var builder = new StringBuilder();

            while (true)
            {
                var inputKey = @this.ReadKey();

                if (inputKey == 13)
                {
                    if (builder.Length >= minimumLength)
                    {
                        break;
                    }
                    else
                    {
                        @this.Backspace();
                    }
                }
                else if (inputKey == 8)
                {
                    if (builder.Length > 0)
                    {
                        builder.Remove(builder.Length - 1, 1);
                    }
                    else
                    {
                        @this.Write(" ");
                    }
                }
                else if (builder.Length < maximumLength)
                {
                    builder.Append(inputKey);
                }
                else
                {
                    @this.Backspace();
                }
            }

            return(builder.ToString());
        }
예제 #10
0
 public UpdateScoresCommandHandler(ITextInterface textInterface) : base(textInterface)
 {
 }
예제 #11
0
        public static void WriteLine(this ITextInterface @this)
        {
            Guard.AgainstNull(@this, nameof(@this));

            @this.WriteLine(String.Empty);
        }
 public CheckForGameEndCommandHandler(ITextInterface textInterface) : base(textInterface)
 {
 }
예제 #13
0
        public TextCardGameCommmandHandler(ITextInterface textInterface)
        {
            Guard.AgainstNull(textInterface, nameof(textInterface));

            this.TextInterface = textInterface;
        }