public string generateNickname(GenerateData currentData)
        {
            char firstLetter = currentData.FirstLetter;
            int  min         = currentData.MinLength;
            int  max         = currentData.MaxLength;

            // вибор префикса
            string prefix = generatePrefix(firstLetter);
            // выбор суффикса
            string suffix = generateSuffix();

            // недостающие буквы
            if (prefix == null)
            {
                prefix = firstLetter.ToString();
            }
            int size = prefix.Length + suffix.Length;

            if (size > max)
            {
                prefix = firstLetter.ToString();
            }
            size = prefix.Length + suffix.Length;
            int check = min - size;

            if (check < 0)
            {
                min = 0;
            }
            else
            {
                min = check;
            }
            max = max - size;

            string lack = string.Empty;
            int    temp = Rand.Next(min, max + 1);

            for (int i = 0; i < temp; i++)
            {
                if (i % 2 == 0)
                {
                    lack += vowelLetters[Rand.Next(0, vowelLetters.Length)];
                }
                else
                {
                    lack += consonantLetters[Rand.Next(0, consonantLetters.Length)];
                }
                // lack += (char)Rand.Next(0x0061, 0x007B);
            }
            return(prefix + lack + suffix);
        }
예제 #2
0
        public ApplicationViewModel()
        {
            currentData = new GenerateData();

            // Action<object> execute = obj => OutputNickname = new Generator().generateNickname(obj as GenerateData);
            Predicate <object> canExecuted = obj => (obj as GenerateData).IsValid;
            Action <object>    execute     = obj =>
            {
                switch (race)
                {
                case Races.Orc:
                    OutputNickname = new GenaratorOrcNames().generateNickname(currentData as GenerateData);
                    break;

                case Races.Elf:
                    OutputNickname = new GenaratorElfNames().generateNickname(currentData as GenerateData);
                    break;
                }
            };

            generateCommand = new RelayCommand(execute, canExecuted);
        }