Beispiel #1
0
        /// <summary>
        /// Invoke when manager starts new question
        /// </summary>
        /// <param name="id">Number of question</param>
        /// <param name="text">Text of question</param>
        /// <param name="secondsToAnswer">Time in seconds to answer</param>
        /// <param name="kind">Type of question</param>
        /// <param name="answers">List of answers</param>
        /// <param name="mediaPath">Path to video or picture for question</param>
        private void QuizManager_OnNewQuestion(int id, string text, string rightAnswer, int secondsToAnswer, QuestionKind kind, List <Answer> answers, Uri mediaPath, MediaAnswer mediaAnswer)
        {
            switch (kind)
            {
            case QuestionKind.WithVideo:
            {
                ShowBlacker();
                ImageAndVideoGrid.Children[0].Visibility = Visibility.Collapsed;
                MediaGrid.Visibility  = Visibility.Visible;
                MediaBorder.Padding   = new Thickness(200, 30, 200, 0);
                MediaBlock.Source     = mediaPath;
                MediaBlock.Visibility = Visibility.Visible;
                MediaBlock.Play();
                isVideoQuestion = true;
                isVideoPlay     = true;
                break;
            }

            case QuestionKind.WithImage:
            {
                ShowBlacker();
                MediaBlock.Stop();

                ImageAndVideoGrid.Children.RemoveAt(0);

                Image       image = new Image();
                BitmapImage src   = new BitmapImage();
                src.BeginInit();
                src.UriSource = mediaPath;
                src.EndInit();
                image.Source  = src;
                image.Stretch = Stretch.Uniform;

                ImageAndVideoGrid.Children.Insert(0, image);


                MediaGrid.Visibility  = Visibility.Visible;
                MediaBlock.Visibility = Visibility.Collapsed;
                isVideoQuestion       = false;


                break;
            }

            case QuestionKind.Simple:
            {
                HideBlacker();
                MediaBlock.Stop();
                MediaDockPanel.Visibility = Visibility.Collapsed;
                MediaBlock.Visibility     = Visibility.Collapsed;
                isVideoQuestion           = false;
                break;
            }
            }

            switch (mediaAnswer.Kind)
            {
            case AnswerKind.WithImage:
            {
                RightAnswerMediaGrid.Visibility = Visibility.Visible;
                RightAnswerMediaBlock.Stop();
                RightAnswerMediaBlock.Visibility = Visibility.Collapsed;

                RightMediaInnerGrid.Children.RemoveAt(0);

                Image       image = new Image();
                BitmapImage src   = new BitmapImage();
                src.BeginInit();
                src.UriSource = mediaAnswer.AnswerImagePath;
                src.EndInit();
                image.Source  = src;
                image.Stretch = Stretch.Uniform;

                RightMediaInnerGrid.Children.Insert(0, image);

                if (src.Height > SystemParameters.PrimaryScreenHeight / 2.4)
                {
                    (RightMediaInnerGrid.Children[0] as Image).Height = SystemParameters.PrimaryScreenHeight / 2.4;
                }


                RightAnswerDockPanel.Margin = new Thickness(0, 20, 0, 0);

                break;
            }

            case AnswerKind.WithVideo:
            {
                RightAnswerMediaGrid.Visibility            = Visibility.Visible;
                RightAnswerMediaBlock.Visibility           = Visibility.Visible;
                RightMediaInnerGrid.Children[0].Visibility = Visibility.Collapsed;
                RightAnswerMediaBlock.Source = mediaAnswer.AnswerVideoPath;
                RightAnswerMediaBlock.Play();

                RightAnswerDockPanel.Margin = new Thickness(0, 20, 0, 0);

                break;
            }

            case AnswerKind.Simple:
            {
                RightAnswerMediaGrid.Visibility = Visibility.Collapsed;
                RightAnswerDockPanel.Margin     = new Thickness(0, 100, 0, 0);
                break;
            }
            }

            QuestionNumberFontSize = 33 - ((int)Math.Log10(QuestionNumber) + 1) * 2;
            if (text.Count() < 93)
            {
                QuestionTextBlock.VerticalAlignment = VerticalAlignment.Center;
            }
            else if (text.Count() < 185)
            {
                QuestionTextBlock.VerticalAlignment = VerticalAlignment.Top;
            }
            else
            {
                QuestionTextBlock.VerticalAlignment = VerticalAlignment.Top;
                text = text.Substring(0, 182) + "...";
            }

            QuestionText = text;

            Regex reg = new Regex(@"\s{2,}");

            text = reg.Replace(text, " ");

            MainWindowQuestion = text;
            AnswerTimerText    = secondsToAnswer.ToString();
            _answersTime       = TimeSpan.FromSeconds(secondsToAnswer);

            QuestionNumber = id;

            RightAnswer = rightAnswer;
            RightAnswerGrid.Visibility = Visibility.Hidden;
            RightAnswerMediaBlock.Stop();

            MediaGrid.Visibility      = Visibility.Visible;
            MediaDockPanel.Visibility = Visibility.Visible;
            ShowImage();
        }
Beispiel #2
0
        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.P:
            {
                if (isVideoQuestion)
                {
                    if (isVideoPlay)
                    {
                        MediaBlock.Pause();
                    }
                    else
                    {
                        MediaBlock.Play();
                    }

                    isVideoPlay = !isVideoPlay;
                }

                if (isVideoRightAnswer)
                {
                    if (isRightAnswerVideoPlay)
                    {
                        RightAnswerMediaBlock.Pause();
                    }
                    else
                    {
                        RightAnswerMediaBlock.Play();
                    }

                    isRightAnswerVideoPlay = !isRightAnswerVideoPlay;
                }
                break;
            }

            case Key.R:
            {
                if (isVideoQuestion)
                {
                    MediaBlock.Stop();
                    MediaBlock.Play();
                    isVideoPlay = true;
                }

                if (isVideoRightAnswer)
                {
                    MediaBlock.Stop();
                    MediaBlock.Play();
                    isRightAnswerVideoPlay = true;
                }
                break;
            }
            }

            if (!isQuizStarted)
            {
                return;
            }

            if (e.Key == Key.Enter)
            {
                if (isAddPointsWindowOpened)
                {
                    if (ActivePlayer != null && ActivePlayer.PlayerIndex >= 0)
                    {
                        if (quizManager.AddedPoints())
                        {
                            HideBlacker();
                        }
                        else
                        {
                            ShowBlacker();
                        }


                        isAddPointsWindowOpened = false;

                        AddPointsMenu.Visibility = Visibility.Collapsed;

                        if (isAddingPointNecessary)
                        {
                            AddPoints(ActivePlayer.PlayerIndex, Convert.ToDouble(AddingPointsTextBlock.Text));
                            QuizManager_OnRightAnswer(0, true);
                            MediaGrid.Visibility       = Visibility.Hidden;
                            RightAnswerGrid.Visibility = Visibility.Visible;
                            isAddingPointNecessary     = false;
                            return;
                        }

                        HideBlacker();
                        AddPoints(ActivePlayer.PlayerIndex, Convert.ToDouble(AddingPointsTextBlock.Text));

                        isAddingPointNecessary   = false;
                        closedElement.Visibility = Visibility.Visible;
                    }
                }
            }

            if (e.Key == Key.Escape)
            {
                if (isAddPointsWindowOpened)
                {
                    if (!isAddingPointNecessary)
                    {
                        AddPointsMenu.Visibility = Visibility.Hidden;
                        closedElement.Visibility = Visibility.Visible;
                        HideBlacker();
                    }
                }
            }

            if (isAddPointsWindowOpened)
            {
                if (Char.IsDigit((char)KeyInterop.VirtualKeyFromKey(e.Key)) && e.Key != Key.Back || e.Key == Key.Space)
                {
                    if ((int)(((char)KeyInterop.VirtualKeyFromKey(e.Key)) - '0') > Players.Count || (int)(((char)KeyInterop.VirtualKeyFromKey(e.Key)) - '0') == 0)
                    {
                        return;
                    }

                    ActivePlayer = Players[(int)(((char)KeyInterop.VirtualKeyFromKey(e.Key)) - '0') - 1];
                }
                else
                {
                    return;
                }
            }

            switch (e.Key)
            {
            case Key.Y:
            {
                quizManager.RightAnswerClick();
                break;
            }

            case Key.N:
            {
                quizManager.WrongAnswerClick();
                break;
            }

            case Key.S:
            {
                quizManager.StartButtonListener(StartTimer);
                break;
            }

            case Key.C:
            {
                quizManager.Next();
                break;
            }

            case Key.Q:
            {
                ShowBlacker();
                isAddingPointNecessary   = false;
                AddPointsMenu.Visibility = Visibility.Visible;
                ActivePlayer             = null;

                if (RightAnswerGrid.Visibility == Visibility.Visible)
                {
                    closedElement = RightAnswerGrid;
                    RightAnswerGrid.Visibility = Visibility.Hidden;
                }
                else if (MediaGrid.Visibility == Visibility.Visible)
                {
                    closedElement        = MediaGrid;
                    MediaGrid.Visibility = Visibility.Hidden;
                }
                else if (MainSettingsGrid.Visibility == Visibility.Visible)
                {
                    closedElement = MainSettingsGrid;
                    MainSettingsGrid.Visibility = Visibility.Hidden;
                }

                isAddPointsWindowOpened = true;

                quizManager.StopQuiz();

                break;
            }
            }
        }