Example #1
0
        public BRGameResult()
        {
            InitializeComponent();
            index = GameBR.Instance.CurrentIndex;
            q = GameBR.Instance.Questions[index];
            edtAnswer.Text = "Ответ: " + q.Answer;
            edtAuthor.Text = "Автор: " + q.author;
            btnScoreMyAnswer.Visibility = System.Windows.Visibility.Visible;
            if (!String.IsNullOrEmpty(q.Comments))
                edtComments.Text = "Комментарий: " + q.Comments;
            if (q.userAnswer.ToUpper() == q.Answer.ToUpper())
            {
                GameBR.Instance.Score++;
                edtMessage.Text = "Правильно, поздравляем!";
                RightAnswer = true;
            }
            else
            {
                edtMessage.Text = "Увы, вы ошиблись.";
            }

            edtScore.Text = GameBR.Instance.Score.ToString() + ":" + (index + 1 - GameBR.Instance.Score).ToString();
            if (index + 1 == GameBR.Instance.Questions.Count)
            {
                btnOk.Content = "Главное меню";
                edtMessage.Text = "Игра закончена, спасибо за игру!";
            }
        }
Example #2
0
        public BRGameQuestion()
        {
            InitializeComponent();
            index = GameBR.Instance.CurrentIndex;
            q = GameBR.Instance.Questions[index];

            timeToRead = q.Question.Length / 20;
            timeToAnswer = q.Answer.Length * 2;

            edtNumber.Text = "Вопрос №" + (index + 1).ToString();
            edtQuestion.Text = q.Question.Replace("\n", " ");

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += OnTimerTick;
            timer.Start();
        }
Example #3
0
        private void QuestionsDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBox.Show("Ошибка подключения к базе вопросов. Проверьте соединение с интернетом.");
                NavigationService.Navigate(new Uri(@"/MainPage.xaml", UriKind.Relative));
                return;
            }

            HtmlNode.ElementsFlags.Remove("option");
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(e.Result);
            HtmlNodeCollection quests = doc.DocumentNode.SelectNodes("//div[@class='random_question']");
            if (quests == null)
            {
                MessageBox.Show("По вашему запросу ничего не найдено! Попробуйте изменить параметры игры.");
                NavigationService.Navigate(new Uri(@"/MainPage.xaml", UriKind.Relative));
                return;
            }
            var foos = from foo in quests select foo;
            foreach (HtmlNode random_question in foos)
            {
                string nodetext = random_question.InnerHtml;

                if (nodetext.Contains("razdatka") || nodetext.Contains("<img"))
                    continue;

                QuestionBR q = new QuestionBR();
                Regex r = new Regex(@"<a.*?>(.*?)</a>.*?");
                string a = r.Match(random_question.InnerHtml).Value;
                string descr = Regex.Match(a, @">(.*?)</").Value.Replace(">", "").Replace(@"</", "");
                int start = a.IndexOf("f=\"") + 3;
                int length = a.IndexOf("\">") - start;
                string url = a.Substring(start, length);
                q.description = descr;
                q.url = url;

                start = nodetext.IndexOf("</strong>") + 9;
                length = nodetext.IndexOf("<div class='collapsible collapsed'>") - start;
                string qw = nodetext.Substring(start, length);
                q.Question = Helpers.HtmlRemoval.StripTagsCharArray(qw);

                start = nodetext.IndexOf("Ответ:</strong>") + 15;
                string tmp1 = nodetext.Substring(start);
                length = tmp1.IndexOf("</p>");
                string qa = tmp1.Substring(0, length);
                q.Answer = Helpers.HtmlRemoval.StripTagsCharArray(qa);

                if (nodetext.Contains("<strong>Комментарий:</strong>"))
                {
                    start = nodetext.IndexOf("Комментарий:</strong>") + 21;
                    string tmp = nodetext.Substring(start);
                    length = tmp.IndexOf("</p>");
                    string txt = tmp.Substring(0, length);
                    q.Comments = Helpers.HtmlRemoval.StripTagsCharArray(txt);
                }
                if (nodetext.Contains("<strong>Источник(и):</strong>"))
                {
                    start = nodetext.IndexOf("<strong>Источник(и):</strong>") + 29;
                    string tmp = nodetext.Substring(start);
                    length = tmp.IndexOf("</p>");
                    string txt = tmp.Substring(0, length);
                    q.source = Helpers.HtmlRemoval.StripTagsCharArray(txt);
                }
                if (nodetext.Contains("<strong>Автор:</strong>"))
                {
                    start = nodetext.IndexOf("<strong>Автор:</strong>") + 24;
                    string tmp = nodetext.Substring(start);
                    length = tmp.IndexOf("</p>");
                    string txt = tmp.Substring(0, length);
                    q.author = Helpers.HtmlRemoval.StripTagsCharArray(txt);
                }

                GameBR.Instance.Questions.Add(q);
            }

            // stop progress bar
            ShowProgress = false;
            ContentPanel.Visibility = System.Windows.Visibility.Visible;
            GameBR.Instance.Score = 0;
            GameBR.Instance.CurrentIndex = 0;
            // redirect to game
            NavigationService.Navigate(new Uri(@"/Games/br/BRGameQuestion.xaml", UriKind.Relative));
        }