Ejemplo n.º 1
0
 private void SetPrevTransform(IRoundControl question)
 {
     if (question != null)
     {
         (question as Control).RenderTransform = new TranslateTransform(TRANSFORM_DISTANCE * -1, 0);
     }
 }
Ejemplo n.º 2
0
 private void SetActiveTransform(IRoundControl question)
 {
     if (question != null)
     {
         (question as Control).RenderTransform = new TranslateTransform(0, 0);
     }
 }
Ejemplo n.º 3
0
        private void TransformToPreviousQuestion()
        {
            lock (lockObject)
            {
                if (isTransitioning)
                {
                    return;
                }
                isTransitioning = true;
            }
            gParentGrid.Children.Remove(mNextQuestion as Control);
            mNextQuestion = null;

            Duration        duration      = new Duration(new TimeSpan(0, 0, 1));
            DoubleAnimation prevToCurrent = new DoubleAnimation(TRANSFORM_DISTANCE * -1, 0, duration);
            DoubleAnimation currentToNext = new DoubleAnimation(0, TRANSFORM_DISTANCE, duration);

            currentToNext.AccelerationRatio = 0.5;
            prevToCurrent.AccelerationRatio = 0.5;
            currentToNext.DecelerationRatio = 0.5;
            prevToCurrent.DecelerationRatio = 0.5;

            mPreviousQuestion.PreviousEnabled = currentQuestion - 1 > 0;

            prevToCurrent.Completed += (s, e) =>
            {
                mNextQuestion   = mActiveQuestion;
                mActiveQuestion = mPreviousQuestion;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentRound)));
                currentQuestion--;

                AttachNextPrevClickEvents();

                if (currentQuestion > 0)
                {
                    mPreviousQuestion = ExistingQuestions[currentQuestion - 1];
                    SetNextTransform(mPreviousQuestion);
                    gParentGrid.Children.Add(mPreviousQuestion as Control);
                }
                else
                {
                    mPreviousQuestion = null;
                }

                SetActiveTransform(mActiveQuestion);
                SetPrevTransform(mPreviousQuestion);
                SetNextTransform(mNextQuestion);

                AttachQuestionShownEvents();
                (mActiveQuestion as SingleQuestionControl)?.ShowQuestion();
                lock (lockObject)
                {
                    isTransitioning = false;
                }
            };

            (mPreviousQuestion as Control).RenderTransform.BeginAnimation(TranslateTransform.XProperty, prevToCurrent);
            (mActiveQuestion as Control).RenderTransform.BeginAnimation(TranslateTransform.XProperty, currentToNext);
        }
Ejemplo n.º 4
0
        public GameWindow(Game game)
        {
            InitializeComponent();

            if (game == null || game.NumRounds < 2)
            {
                throw new ArgumentException("Game cannot be null and must have at least two rounds");
            }

            mGame = game;

            mSoundPlayerIntro.Load();

            mAttachedKeys = new List <Key>()
            {
                Key.D1, Key.D2, Key.D3, Key.D4, Key.D5, Key.D6, Key.D7, Key.D8, Key.D9, Key.D0
            };

            switch (mGame.BonusRoundLocation)
            {
            case BonusRoundLocation.Middle:
                mBonusRoundIndex  = (int)(game.NumRounds / 2);
                ExistingQuestions = new IRoundControl[mGame.NumRounds + 1];
                break;

            case BonusRoundLocation.End:
                mBonusRoundIndex  = (int)game.NumRounds;
                ExistingQuestions = new IRoundControl[mGame.NumRounds + 1];
                break;

            case BonusRoundLocation.None:
            default:
                mBonusRoundIndex  = int.MaxValue;
                ExistingQuestions = new IRoundControl[mGame.NumRounds];
                break;
            }

            for (int i = 0; i < ExistingQuestions.Length; i++)
            {
                if (i == mBonusRoundIndex)
                {
                    var bonusRound = new BonusRoundControl(game.BonusRound);
                    bonusRound.OnTimerFinished += (sender, args) =>
                    {
                        OnTimerFinished?.Invoke(sender, args);
                    };
                    ExistingQuestions[i] = bonusRound;
                }
                else
                {
                    int normalQuestionIndex = i <= mBonusRoundIndex ? i : i - 1;
                    ExistingQuestions[i] = new SingleQuestionControl(mGame.Rounds.ElementAt(normalQuestionIndex));
                }

                (ExistingQuestions[i] as UIElement).CacheMode = new BitmapCache()
                {
                    EnableClearType = false, RenderAtScale = 1, SnapsToDevicePixels = false
                };
            }

            IntroPlaceholderBorder = new Border()
            {
                Background = new SolidColorBrush(Color.FromRgb(0, 0, 0))
            };

            gParentGrid.Children.Add(IntroPlaceholderBorder);

            mNextQuestion = ExistingQuestions[0];
            SetNextTransform(mNextQuestion);
            gParentGrid.Children.Add(mNextQuestion as Control);

            mMediaPlayerQuestion = new MediaPlayer();

            mMediaPlayerQuestion.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"/Sounds/Next_Question.wav", UriKind.RelativeOrAbsolute));
            mMediaPlayerQuestion.IsMuted = true;

            this.Closed += GameWindow_Closed;
        }
Ejemplo n.º 5
0
        public void BeginQuestions()
        {
            Duration        duration      = new Duration(new TimeSpan(0, 0, 1));
            DoubleAnimation nextToCurrent = new DoubleAnimation(TRANSFORM_DISTANCE, 0, duration);
            DoubleAnimation currentToPrev = new DoubleAnimation(0, TRANSFORM_DISTANCE * -1, duration);

            if (OldStyleCountdown != null)
            {
                OldStyleCountdown.OnCountdownCompleted -= oldStyleCompleted;
                mSoundPlayerIntro.Stop();
            }

            currentToPrev.AccelerationRatio = 0.5;
            nextToCurrent.AccelerationRatio = 0.5;
            currentToPrev.DecelerationRatio = 0.5;
            nextToCurrent.DecelerationRatio = 0.5;

            mNextQuestion.NextEnabled     = ExistingQuestions.Count() > 1;
            mNextQuestion.PreviousEnabled = false;

            nextToCurrent.Completed += (s, e) =>
            {
                mPreviousQuestion = null;
                mActiveQuestion   = mNextQuestion;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentRound)));
                if (gParentGrid.Children.Contains(TitleScreen))
                {
                    gParentGrid.Children.Remove(TitleScreen);
                }
                if (gParentGrid.Children.Contains(OldStyleCountdown))
                {
                    gParentGrid.Children.Remove(OldStyleCountdown);
                }
                if (gParentGrid.Children.Contains(IntroPlaceholderBorder))
                {
                    gParentGrid.Children.Remove(IntroPlaceholderBorder);
                }

                currentQuestion = 0;

                AttachNextPrevClickEvents();

                if (currentQuestion < ExistingQuestions.Length - 1)
                {
                    mNextQuestion = ExistingQuestions[currentQuestion + 1];

                    SetNextTransform(mNextQuestion);
                    gParentGrid.Children.Add(mNextQuestion as Control);
                }
                else
                {
                    mNextQuestion = null;
                }

                SetActiveTransform(mActiveQuestion);
                SetNextTransform(mNextQuestion);

                AttachQuestionShownEvents();
                (mActiveQuestion as SingleQuestionControl)?.ShowQuestion();
            };

            (mNextQuestion as Control).RenderTransform.BeginAnimation(TranslateTransform.XProperty, nextToCurrent);
            //titleScreen.RenderTransform.BeginAnimation(TranslateTransform.XProperty, currentToPrev);

            mMediaPlayerQuestion.Position = new TimeSpan(0, 0, 0);
            mMediaPlayerQuestion.IsMuted  = false;
            mMediaPlayerQuestion.Volume   = 0.75;
            mMediaPlayerQuestion.Play();

            this.KeyUp += KeyPressed;
        }