示例#1
0
        /// <summary>
        /// The user selected an answer.
        /// Set the flags, menu entry colors, and start timer.
        /// </summary>
        private void AnswerSelected(bool correctAnswer, FlashCard selectedAnswer)
        {
            QuestionStateMachine.Done();

            if (!AnswerChosen)
            {
                //set flags
                AnswerChosen    = true;
                AnsweredCorrect = correctAnswer;

                //Set all the colors of the answers to let the user know which was the correct answer
                foreach (var entry in Entries)
                {
                    entry.QuestionAnswered = true;
                }

                if (null != QuestionAnswered)
                {
                    QuestionAnswered(this, new QuestionEventArgs(AnsweredCorrect, correctQuestion, selectedAnswer));
                }

                //start the timer to exit this screen
                AutoQuit.Start(1f);

                if (null != OverlayScreen)
                {
                    OverlayScreen.ExitScreen();
                }
            }
        }
示例#2
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            //update the timers
            AutoQuit.Update(gameTime);

            //check if we been here long enough
            if (IsActive)
            {
                QuestionStateMachine.Update(gameTime);

                if (!AutoQuit.Paused && !AutoQuit.HasTimeRemaining)
                {
                    //has the user picked an answer?
                    if (!AnswerChosen)
                    {
                        //the timer ran out but the user hadn't picked an answer.  That counts as "wrong"
                        AnswerSelected(false, correctQuestion);

                        //play the "wrong" sound effect
                        WrongAnswerSound.Play();

                        TimeRanOut = true;
                    }
                    else
                    {
                        //holla at the combat engine
                        ExitScreen();
                    }
                }
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
示例#3
0
 public void PlaySoundEffect(SoundEffect soundEffect, float pause = 0.1f)
 {
     if (null != soundEffect)
     {
         QuestionStateMachine.StartTimer((float)soundEffect.Duration.TotalSeconds + pause);
         soundEffect.Play(SoundVolume, 0f, 0f);
     }
 }
示例#4
0
        public override async Task LoadContent()
        {
            try
            {
                await base.LoadContent();

                if (null == FontSmall)
                {
                    FontSmall = new FontBuddyPlus();
                    FontSmall.LoadContent(Content, StyleSheet.SmallFontResource, StyleSheet.UseFontPlus, StyleSheet.SmallFontSize);
                }

                if (null == FontMedium)
                {
                    FontMedium = new FontBuddyPlus();
                    FontMedium.LoadContent(Content, StyleSheet.MediumFontResource, StyleSheet.UseFontPlus, StyleSheet.MediumFontSize);
                }

                //create the stack layout to hold the question and words
                var questionStack = new StackLayout(StackAlignment.Top)
                {
                    Vertical         = VerticalAlignment.Bottom,
                    Horizontal       = HorizontalAlignment.Center,
                    Highlightable    = false,
                    TransitionObject = new WipeTransitionObject(TransitionWipeType.PopTop),
                };

                //Add the text asking a question
                questionStack.AddItem(new Label($"What is the", FontSmall)
                {
                    Vertical         = VerticalAlignment.Center,
                    Horizontal       = HorizontalAlignment.Center,
                    Highlightable    = false,
                    TransitionObject = new WipeTransitionObject(TransitionWipeType.PopTop),
                });
                questionStack.AddItem(new Shim(0, 8));
                questionStack.AddItem(new Label($"{correctAnswer.Language} for:", FontSmall)
                {
                    Vertical         = VerticalAlignment.Center,
                    Horizontal       = HorizontalAlignment.Center,
                    Highlightable    = false,
                    TransitionObject = new WipeTransitionObject(TransitionWipeType.PopTop),
                });
                questionStack.AddItem(new Shim(0, 8));

                //Add all the translations
                foreach (var translation in correctQuestion.Translations)
                {
                    if (translation.Language != correctAnswer.Language)
                    {
                        CreateTranslationLabel(FontMedium, questionStack, translation);
                    }
                }

                questionStack.Position = new Point(Resolution.ScreenArea.Center.X, (int)((Resolution.TitleSafeArea.Height * 0.2f) - (questionStack.Rect.Height * 0.4f)));
                AddItem(questionStack);

                //create the correct menu entry
                CorrectAnswerEntry          = CreateQuestionMenuEntry(correctAnswer.Word, correctQuestion, true, FontMedium);
                CorrectAnswerEntry.OnClick += CorrectAnswerSelected;
                Entries.Add(CorrectAnswerEntry);

                //Add exactly three wrong answers
                for (int i = 0; i < 3; i++)
                {
                    //get a random wrong answer
                    int index = _rand.Next(wrongAnswers.Count);

                    //create a menu entry for that answer
                    var wrongMenuEntry = CreateQuestionMenuEntry(wrongAnswers[index].Word, wrongQuestions[index], false, FontMedium);
                    wrongMenuEntry.OnClick += WrongAnswerSelected;
                    Entries.Add(wrongMenuEntry);

                    //remove the wrong answer from the list so it wont be added again
                    wrongAnswers.RemoveAt(index);
                    wrongQuestions.RemoveAt(index);
                }

                //shuffle the answers
                Entries.Shuffle(_rand);

                //create the stack layout to hold the possible answers
                var answersStack = new StackLayout(StackAlignment.Top)
                {
                    Name             = "AnswerStack",
                    Vertical         = VerticalAlignment.Center,
                    Horizontal       = HorizontalAlignment.Center,
                    Highlightable    = false,
                    TransitionObject = new WipeTransitionObject(TransitionWipeType.PopBottom),
                    Position         = new Point(Resolution.ScreenArea.Center.X, (int)(Resolution.TitleSafeArea.Height * 0.5f))
                };

                //add all the question entries to the menu
                foreach (var entry in Entries)
                {
                    answersStack.AddItem(entry);
                }
                AddItem(answersStack);

                //load the sound effect to play when time runs out on a question
                WrongAnswerSound = Content.Load <SoundEffect>("WrongAnswer");

                AutoQuit.Stop();
            }
            catch (Exception ex)
            {
                await ScreenManager.ErrorScreen(ex);
            }

            //Try to load the sound effects
            soundContent = new ContentManager(ScreenManager.Game.Services, "Content");
            try
            {
                QuestionSoundEffect = soundContent.Load <SoundEffect>($"TTS/{correctAnswer.Language}Question");
            }
            catch (Exception ex)
            {
                //ignore for now
            }

            //load the correct answer sound effect
            try
            {
                QuestionWordSoundEffect = CorrectQuestion.LoadSoundEffect(correctQuestion.OtherLanguage(correctAnswer.Language), soundContent);
            }
            catch (Exception ex)
            {
                //ignore for now
            }

            //load the sound effect for each question
            for (int i = 0; i < Entries.Count; i++)
            {
                try
                {
                    Entries[i].LoadSoundEffect(correctAnswer.Language, soundContent);
                }
                catch (Exception ex)
                {
                    //ignore for now
                }
            }

            QuestionStateMachine = new QuestionStateMachine();
            QuestionStateMachine.StartTimer(Transition.OnTime + 0.1f);
            QuestionStateMachine.StateChangedEvent += QuestionStateMachine_StateChangedEvent;
        }