Exemplo n.º 1
0
        public void OnCorrect(Answer answer)
        {
            int indexOfWord = AppState.Translations.FindIndex(f => f.From == answer.Translation);

            if (answer.IsCorrect)
            {
                AppState.UpdateCorrectGuess(indexOfWord);
            }
            else
            {
                AppState.UpdateIncorrectGuesses();
            }

            //Next word has to be not guessed and not on screen
            //var notGuessed = AppState.Words.Where(w => !w.IsGuessed && Data.FindIndex(f => f.Translation == w.Spanish) == -1).ToList();
            var notGuessed  = AppState.Translations.Where(w => !w.IsGuessed).ToList();
            var notOnScreen = notGuessed.Where(w => MultipleChoiceSets.FindIndex(fi => fi.Translation == w.From) == -1).ToList();

            if (notOnScreen.Count == 0 && !answer.IsCorrect)
            {
                notOnScreen.Add(AppState.Translations[indexOfWord]);
            }

            int             nextIndex = random.Next(notOnScreen.Count);
            TranslationItem nextWord  = new TranslationItem();

            if (notOnScreen.Count > 0)
            {
                nextWord = notOnScreen[nextIndex];
                MultipleChoiceSets[answer.ReplacementIndex] = AppState.CreateCardMultipleChoices(nextWord, 2);
            }
            else
            {
                MultipleChoiceSets[answer.ReplacementIndex] = new TranslationMultipleChoices {
                    Answer = "----", Choices = null, Translation = "----"
                };
            }
        }