private async Task GetNewQuestion()
        {
            QuestionDTO question = await GameManager.GetNewQuestion();

            CurrentWord = question.CurrentWord;
            Word1       = question.Word1;
            Word2       = question.Word2;
            Word3       = question.Word3;
            rightAnswer = question.RightAnswer;

            IsLoading = false;
        }
Ejemplo n.º 2
0
        public static async Task <QuestionDTO> GetNewQuestion()
        {
            Random rand        = new Random();
            int    rightAnswer = rand.Next(1, 4);
            int    currentWord = rand.Next(0, words.Count);
            int    option1     = rand.Next(0, words.Count);

            while (option1 == currentWord)
            {
                option1 = rand.Next(0, words.Count);
            }

            int option2 = rand.Next(0, words.Count);

            while (option2 == currentWord || option2 == option1)
            {
                option2 = rand.Next(0, words.Count);
            }

            QuestionDTO question = new QuestionDTO();

            question.CurrentWord = words[currentWord].Text;
            question.RightAnswer = rightAnswer;

            await SetTranslatedText(words[option1]);
            await SetTranslatedText(words[option2]);
            await SetTranslatedText(words[currentWord]);

            var localCache = ((App)Xamarin.Forms.Application.Current).LocalCache;

            localCache.InsertObject(String.Format(WORDS_KEY, Language), words).Wait();

            question.Word1 = rightAnswer == 1 ?
                             words[currentWord].GetTranslatedText() : words[option1].GetTranslatedText();

            question.Word2 = rightAnswer == 2 ?
                             words[currentWord].GetTranslatedText() :
                             rightAnswer < 2 ? words[option1].GetTranslatedText() : words[option2].GetTranslatedText();

            question.Word3 = rightAnswer == 3 ?
                             words[currentWord].GetTranslatedText() : words[option2].GetTranslatedText();

            return(question);
        }