예제 #1
0
        public WWWGameResult()
        {
            InitializeComponent();
            index = GameWWW.Instance.CurrentIndex;
            q = GameWWW.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())
            {
                GameWWW.Instance.Score++;
                edtMessage.Text = "Правильно, поздравляем!";
                RightAnswer = true;
            }
            else
            {
                edtMessage.Text = "Увы, вы ошиблись.";
            }

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

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

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

            //            edtAnswer.Text = q.answer;

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += OnTimerTick;
            timer.Start();
        }
예제 #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;

                QuestionWWW q = new QuestionWWW();

                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);
                }

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

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