Beispiel #1
0
        /// <summary>
        /// Invoke when player's button clicked
        /// </summary>
        /// <param name="buttonIndex">Index of clicked button</param>
        private void QuizManager_OnPlayerButtonClicked(int buttonIndex, double points)
        {
            MediaBlock.Pause();
            isVideoPlay = false;

            Sound.Position = TimeSpan.FromMilliseconds(0);
            Sound.Play();

            if (Players.Where(p => p.ButtonIndex == buttonIndex).ToArray()[0].isAnswered)
            {
                if (Players.Where(p => !p.isAnswered).ToArray().Count() == 0)
                {
                    return;
                }
                else
                {
                    quizManager.WrongPlayer(StartTimer);
                }

                return;
            }

            HideImage();
            _answerSecondsTimer.Change(Timeout.Infinite, 0);
            isTimerStarted    = false;
            isPlayerAnswering = true;

            activePlayerIndex = Players.Where(p => p.ButtonIndex == buttonIndex).ToArray()[0].PlayerIndex;
            Players[activePlayerIndex].ChangeStatus(PlayerStatus.Answering, points, (long)_answersTime.TotalMilliseconds);
            Players[activePlayerIndex].isAnswered = true;
        }
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;
            }
            }
        }