示例#1
0
 /// <summary>
 /// Инициализирует класс <see cref="Survey"/>
 /// </summary>
 /// <param name="Subject">Предмет</param>
 /// <param name="Theme">Тема</param>
 /// <param name="Question">Вопрос</param>
 public Survey(String Name, String Description, String Author, params Question[] Questions)
 {
     this.Name        = Name;
     this.Description = Description;
     this.Author      = Author;
     this.Questions   = Questions.Cast <Question>().ToList();
 }
示例#2
0
        private IList <IAnswer> GenerateAnswers(ICountryQuestion question)
        {
            var country = question.Country;

            var isHard   = Difficulty == Difficulty.Hard;
            var isNormal = Difficulty == Difficulty.Normal;

            var excluded = new HashSet <ICountryInfo>(Questions
                                                      .Cast <ICountryQuestion>()
                                                      .Where(o => o == question || o.State == QuestionState.Correct || (o.State == QuestionState.Incorrect && !isHard))
                                                      .Select(o => o.Country));

            IEnumerable <ICountryInfo> source = Questions
                                                .Cast <ICountryQuestion>()
                                                .Select(o => o.Country)
                                                .Where(c => !excluded.Contains(c))
                                                .Select(c => new { Country = c, Order = _random.Next() })
                                                .OrderBy(i => i.Order)
                                                .Select(i => i.Country)
                                                .Union(_randomizedContryList
                                                       .Where(c => !excluded.Contains(c))
                                                       .Skip(_random.Next() % (_randomizedContryList.Count - excluded.Count - 7)))
                                                .ToList();

            var count = 5;

            if (isNormal || isHard)
            {
                source = country.Borders
                         .Where(b => !b.Excluded && !excluded.Contains(b.Neighbor))
                         .Select(b => b.Neighbor)
                         .Select(c => new { Country = c, Order = _random.Next() })
                         .OrderBy(i => i.Order)
                         .Select(i => i.Country)
                         .Union(source)
                         .ToList();

                count = 7;
            }

            return(source
                   .Distinct()
                   .Take(count)
                   .Union(Enumerable.Repeat(country, 1))
                   .OrderBy(c => c.AdministrativeName)
                   .Select(c => new CountryAnswer(c, !isHard, true) as IAnswer)
                   .ToList());
        }