Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using ArcheEmu.Models;
- using Nancy;
- using Nancy.ModelBinding;
- namespace ArcheEmu
- {
- public class Question
- {
- public string Text { get; set; }
- public List<string> Answers { get; set; }
- public int Answer { get; set; }
- }
- public class User : NancyModule
- {
- public static int QuestionID { get; set; }
- public static List<Question> _Questions { get; set; }
- public static bool first { get; set; }
- public static void Shuffle<T>(IList<T> list)
- {
- Random rng = new Random();
- int n = list.Count;
- while (n > 1)
- {
- n--;
- int k = rng.Next(n + 1);
- T value = list[k];
- list[k] = list[n];
- list[n] = value;
- }
- }
- public void AddQuestions()
- {
- _Questions = new List<Question>
- {
- new Question()
- {
- Text = "Заплелись густые травы,Закудрявились луга,\nДа и сам я весь кудрявый,"
- + "Даже завитком рога.",
- Answers = new List<string>() {"Корова", "Баран", "Овца"},
- Answer = 1
- },
- new Question()
- {
- Text = "Кто такие лангольеры?",
- Answers = new List<string>()
- {
- "Гребцы традиционных венецианских лодок",
- "Хранители вечности. С начала времен они путешествуют вслед за солнцем, пожирая погрузившийся в прошлое мир.",
- "Дикое племя Африки."
- },
- Answer = 1
- },
- new Question() {Text = "2+2/2=?", Answers = new List<string>() {"4", "2", "3"}, Answer = 2},
- new Question()
- {
- Text = "Глупый пингвин робко прячет...",
- Answers = new List<string>()
- {
- "тело жирное в утесах",
- "яйцо меж лап",
- "умный- смело достает"
- },
- Answer = 0
- },
- new Question()
- {
- Text = "Сколько длилась столетняя война?",
- Answers = new List<string>()
- {
- "100",
- "116",
- "150"
- },
- Answer = 1
- },
- new Question()
- {
- Text = "В чем смысл жизни",
- Answers = new List<string>()
- {
- "Не знаю",
- "Смерть",
- "42"
- },
- Answer = 2
- },
- new Question()
- {
- Text = "Или что-то случилось, или ...",
- Answers = new List<string>()
- {
- "одно из двух!",
- "ничего не случилось!",
- "все пропало!"
- },
- Answer = 0
- },
- new Question()
- {
- Text = "— Сверим часы. — На моих ... часов. — Аналогично.",
- Answers = new List<string>()
- {
- "20",
- "42",
- "эндцать",
- "10"
- },
- Answer = 2
- },
- new Question()
- {
- Text = "Разве наши слоны уже ...? — Значит, ...!",
- Answers = new List<string>()
- {
- "живут",
- "умирают",
- "летают"
- }, Answer = 2
- },
- new Question()
- {
- Text = "Я думал, думал и наконец все понял. Это неправильные ...!",
- Answers = new List<string>()
- {
- "вопросы",
- "ответы",
- "пчелы"
- },
- Answer = 2
- }
- };
- }
- public User() : base("/")
- {
- if(_Questions == null)
- AddQuestions();
- Get["/"] = (par) =>
- {
- var v = new MainModel(_Questions[QuestionID], QuestionID,_Questions.Count);
- return View["Index",v];
- };
- Post["/"] = (par) =>
- {
- var qt = _Questions[QuestionID];
- if ((string)Request.Form.browser == qt.Answers[qt.Answer])
- {
- QuestionID++;
- if (QuestionID == _Questions.Count)
- {
- QuestionID = 0;
- return View["Greatings"];
- }
- else
- {
- var v = new MainModel(_Questions[QuestionID], QuestionID, _Questions.Count,
- string.Format("Ваш прошлый ответ {0} - верный",
- Request.Form.browser));
- return View["Index", v];
- }
- }
- Shuffle(_Questions);
- QuestionID = 0;
- var l = new MainModel(_Questions[QuestionID], QuestionID, _Questions.Count, string.Format("Ваш прошлый ответ {0} - не верный",
- Request.Form.browser));
- return View["Index", l];
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement