Advertisement
Guest User

Untitled

a guest
Apr 6th, 2015
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using ArcheEmu.Models;
  7. using Nancy;
  8. using Nancy.ModelBinding;
  9.  
  10. namespace ArcheEmu
  11. {
  12.     public class Question
  13.     {
  14.         public string Text { get; set; }
  15.         public List<string> Answers { get; set; }
  16.         public int Answer { get; set; }
  17.     }
  18.     public class User : NancyModule
  19.     {
  20.         public static int QuestionID { get; set; }
  21.         public static List<Question> _Questions { get; set; }
  22.         public static bool first { get; set; }
  23.         public static void Shuffle<T>(IList<T> list)
  24.         {
  25.             Random rng = new Random();
  26.             int n = list.Count;
  27.             while (n > 1)
  28.             {
  29.                 n--;
  30.                 int k = rng.Next(n + 1);
  31.                 T value = list[k];
  32.                 list[k] = list[n];
  33.                 list[n] = value;
  34.             }
  35.         }
  36.  
  37.         public void AddQuestions()
  38.         {
  39.             _Questions = new List<Question>
  40.             {
  41.                 new Question()
  42.                 {
  43.                     Text = "Заплелись густые травы,Закудрявились луга,\nДа и сам я весь кудрявый,"
  44.                            + "Даже завитком рога.",
  45.                     Answers = new List<string>() {"Корова", "Баран", "Овца"},
  46.                     Answer = 1
  47.                 },
  48.                 new Question()
  49.                 {
  50.                     Text = "Кто такие лангольеры?",
  51.                     Answers = new List<string>()
  52.                     {
  53.                         "Гребцы традиционных венецианских лодок",
  54.                         "Хранители вечности. С начала времен они путешествуют вслед за солнцем, пожирая погрузившийся в прошлое мир.",
  55.                         "Дикое племя Африки."
  56.                     },
  57.                     Answer = 1
  58.                 },
  59.                 new Question() {Text = "2+2/2=?", Answers = new List<string>() {"4", "2", "3"}, Answer = 2},
  60.                 new Question()
  61.                 {
  62.                     Text = "Глупый пингвин робко прячет...",
  63.                     Answers = new List<string>()
  64.                     {
  65.                         "тело жирное в утесах",
  66.                         "яйцо меж лап",
  67.                         "умный- смело достает"
  68.                     },
  69.                     Answer = 0
  70.                 },
  71.                 new Question()
  72.                 {
  73.                     Text = "Сколько длилась столетняя война?",
  74.                     Answers = new List<string>()
  75.                     {
  76.                         "100",
  77.                         "116",
  78.                         "150"
  79.                     },
  80.                     Answer = 1
  81.                 },
  82.                 new Question()
  83.                 {
  84.                     Text = "В чем смысл жизни",
  85.                     Answers = new List<string>()
  86.                     {
  87.                         "Не знаю",
  88.                         "Смерть",
  89.                         "42"
  90.                     },
  91.                     Answer = 2
  92.                 },
  93.                 new Question()
  94.                 {
  95.                     Text = "Или что-то случилось, или ...",
  96.                     Answers = new List<string>()
  97.                     {
  98.                         "одно из двух!",
  99.                         "ничего не случилось!",
  100.                         "все пропало!"
  101.                     },
  102.                     Answer = 0
  103.                 },
  104.                 new Question()
  105.                 {
  106.                     Text = "— Сверим часы.  — На моих ... часов.  — Аналогично.",
  107.                     Answers = new List<string>()
  108.                     {
  109.                         "20",
  110.                         "42",
  111.                         "эндцать",
  112.                         "10"
  113.                     },
  114.                     Answer = 2
  115.                 },
  116.                 new Question()
  117.                 {
  118.                     Text = "Разве наши слоны уже ...?  — Значит, ...!",
  119.                     Answers = new List<string>()
  120.                     {
  121.                         "живут",
  122.                         "умирают",
  123.                         "летают"
  124.                     }, Answer = 2
  125.                 },
  126.                 new Question()
  127.                 {
  128.                     Text = "Я думал, думал и наконец все понял. Это неправильные ...!",
  129.                     Answers = new List<string>()
  130.                     {
  131.                         "вопросы",
  132.                         "ответы",
  133.                         "пчелы"
  134.                     },
  135.                     Answer = 2
  136.                 }
  137.             };
  138.  
  139.         }
  140.         public User() : base("/")
  141.         {
  142.             if(_Questions == null)
  143.                 AddQuestions();
  144.             Get["/"] = (par) =>
  145.             {          
  146.                 var v = new MainModel(_Questions[QuestionID], QuestionID,_Questions.Count);
  147.                 return View["Index",v];
  148.             };
  149.             Post["/"] = (par) =>
  150.             {
  151.                 var qt = _Questions[QuestionID];
  152.                 if ((string)Request.Form.browser == qt.Answers[qt.Answer])
  153.                 {
  154.                     QuestionID++;
  155.                     if (QuestionID == _Questions.Count)
  156.                     {
  157.                         QuestionID = 0;
  158.                         return View["Greatings"];
  159.                     }
  160.                     else
  161.                     {
  162.                         var v = new MainModel(_Questions[QuestionID], QuestionID, _Questions.Count,
  163.                             string.Format("Ваш прошлый ответ {0} - верный",
  164.                                 Request.Form.browser));
  165.                         return View["Index", v];
  166.                     }
  167.                 }
  168.                 Shuffle(_Questions);
  169.                 QuestionID = 0;
  170.                 var l = new MainModel(_Questions[QuestionID], QuestionID, _Questions.Count, string.Format("Ваш прошлый ответ {0} - не верный",
  171.     Request.Form.browser));
  172.                 return View["Index", l];
  173.             };
  174.         }
  175.     }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement