예제 #1
0
        private QuizzAppCheckWordResult CheckWord()
        {
            QuizzAppCheckWordResult returnValue = QuizzAppCheckWordResult.QuizzAppCheckWordNone;

            // check Lenght
            if (this.currentAnswer.Length == this.words[this.currentWordsIndex].Length)
            {
                returnValue = QuizzAppCheckWordResult.QuizzAppCheckWordWrong; // word wrong

                if (this.currentAnswer.Equals(this.words[this.currentWordsIndex]))
                {
                    returnValue          = QuizzAppCheckWordResult.QuizzAppCheckWordFound; // Word found
                    this.nbLettersFound += this.words[this.currentWordsIndex].Length;

                    // Update title view
                    int from = this.CurrentTextInputIndex - this.words[this.currentWordsIndex].Length;
                    for (int i = from; i < from + this.words[this.currentWordsIndex].Length; i++)
                    {
                        this.SetTitleLetterState(this.TitleLetters[i], TitleLetterState.LetterSettedAndValid);
                    }

                    // reset current answer
                    currentAnswer = null;
                    currentWordsIndex++;

                    // Go to next word
                    if (this.currentWordsIndex < this.words.Count)
                    {
                        // Notify good word
                    }
                    else
                    {
                        // Found media response
                        this.IsTitleFound = true;
                    }
                }
                else
                {
                    // Update title view
                    int from = this.CurrentTextInputIndex - this.words[this.currentWordsIndex].Length;
                    for (int i = from; i < from + this.words[this.currentWordsIndex].Length; i++)
                    {
                        this.SetTitleLetterState(this.TitleLetters[i], TitleLetterState.LetterSettedAndInvalid);
                    }
                }
            }

            if (returnValue == QuizzAppCheckWordResult.QuizzAppCheckWordWrong)
            {
                // Notify bad word
                this.NotifyBadWord();
            }

            return(returnValue);
        }
예제 #2
0
        public void DeletePreviousLetter()
        {
            if (this.CanDelete == false)
            {
                return;
            }

            // Update current answer
            this.currentAnswer = this.currentAnswer.Substring(0, this.currentAnswer.Length - 1);


            // We go bak on index until find a character not 'special' on title
            this.CurrentTextInputIndex--;
            while (this.CurrentTextInputIndex > 0 && this.TitleLetters[CurrentTextInputIndex].TitleLetterState == TitleLetterState.StaticLetter)
            {
                this.CurrentTextInputIndex--;
            }

            this.TitleLetters[CurrentTextInputIndex].Letter = ' ';
            int wordIndex = this.TitleLetters[CurrentTextInputIndex].wordIndex;

            // reset to Letter Not setted all letters of corrected word
            foreach (var item in this.TitleLetters)
            {
                if (item.wordIndex == wordIndex)
                {
                    this.SetTitleLetterState(item, TitleLetterState.LetterNotSetted);
                }
            }


            // Going to previous character index on title
            while (this.CurrentTextInputIndex > 0 && this.TitleLetters[CurrentTextInputIndex].TitleLetterState == TitleLetterState.StaticLetter)
            {
                this.CurrentTextInputIndex--;
            }

            // Going to previous character on random letters
            this.currentRandomLettersIndex--;
            var  lastLetterButton  = this.chosenLetterButtonKeys.Last();
            char replacementLetter = this.chosenLetterButtonValues.Last();

            if (lastLetterButton != null)
            {
                lastLetterButton.ReplaceLetter(replacementLetter, true);
                lastLetterButton.IsVisible = true;

                this.chosenLetterButtonKeys.RemoveAt(this.chosenLetterButtonKeys.Count - 1);
                this.chosenLetterButtonValues.RemoveAt(this.chosenLetterButtonValues.Count - 1);
            }

            this.lastCheckWordResult = this.CheckWord();
        }
예제 #3
0
        private void keyLetterClicked(object sender, NotificationEventArgs <char> e)
        {
            KeyboardLetterControlViewModel letterViewModel = sender as KeyboardLetterControlViewModel;

            if (letterViewModel == null)
            {
                return;
            }

            //Anti exception (stats result)
            if (this.TitleLetters == null || this.RandomLetters == null)
            {
                return;
            }

            if (!CanTypeAnswer)
            {
                return;
            }

            //Retrieve button
            char letter = letterViewModel.Letter;

            this.chosenLetterButtonKeys.Add(letterViewModel);
            this.chosenLetterButtonValues.Add(letter);

            if (this.currentAnswer == null)
            {
                this.currentAnswer = letter.ToString();
            }
            else
            {
                this.currentAnswer += letter;
            }

            if (this.CurrentTextInputIndex > (this.TitleLetters.Count - 1))
            {
                return;
            }

            // Update title view
            this.TitleLetters[CurrentTextInputIndex].Letter           = letter;
            this.TitleLetters[CurrentTextInputIndex].TitleLetterState = TitleLetterState.LetterSetted;
            this.CurrentTextInputIndex++;

            // Check word
            this.lastCheckWordResult = this.CheckWord();

            // Going to next character index on title
            while (this.CurrentTextInputIndex < this.TitleLetters.Count - 1 && this.TitleLetters[CurrentTextInputIndex].TitleLetterState == TitleLetterState.StaticLetter)
            {
                this.CurrentTextInputIndex++;
            }

            // Going to next character on random letters
            char newKeyChar = ' ';

            this.currentRandomLettersIndex++;
            if (this.currentRandomLettersIndex < this.RandomLetters.Count)
            {
                newKeyChar = this.RandomLetters[this.currentRandomLettersIndex];
            }
            if (newKeyChar == ' ')
            {
                letterViewModel.IsVisible = false;
            }
            letterViewModel.ReplaceLetter(newKeyChar, true);
        }
예제 #4
0
        public void InitializeTitle(string title, bool isAlreadyFound, int nbSecondsForHelp)
        {
            this.isOnInitialization = true;
            this.Title            = title;
            this.nbSecondsForHelp = nbSecondsForHelp;

            if (string.IsNullOrEmpty(title))
            {
                return;
            }

            // Normalized the title
            // We remove accents
            // We upper case
            this.normalizedAnswer = StringTools.RemoveAccents(title).ToUpper();
            Debug.WriteLine("title with no accents : " + this.normalizedAnswer);

            // We split on all characters that are not 'abcdedfghi'
            // Split on all non-word characters.
            this.words = this.SplitIntoWords(this.normalizedAnswer);
            foreach (var item in words)
            {
                Debug.WriteLine("words : " + item);
            }

            // Create real Letters char list
            List <char> realLetters = new List <char>();

            words.ForEach(f => realLetters.AddRange(f.ToCharArray()));


            // Case title already found
            if (isAlreadyFound)
            {
                this.PrepareTitleLetters();

                foreach (var item in this.normalizedAnswer)
                {
                    // Update title view
                    this.TitleLetters[CurrentTextInputIndex].Letter = item;
                    if (!StringTools.IsOnQuizzAppAlphabet(item))
                    {
                        this.SetTitleLetterState(this.TitleLetters[CurrentTextInputIndex], TitleLetterState.StaticLetter);
                    }
                    else
                    {
                        this.SetTitleLetterState(this.TitleLetters[CurrentTextInputIndex], TitleLetterState.LetterSettedAndValid);
                    }
                    this.CurrentTextInputIndex++;
                }
                this.IsTitleFound = true;
            }
            else
            {
                // Create fake letters char list
                int nbRandomLetters = (int)Math.Floor((float)(realLetters.Count / 4));
                int nbChosenLetters = (realLetters.Count + nbRandomLetters);
                if (nbChosenLetters < this.nbTotalLetters)
                {
                    nbRandomLetters += (nbTotalLetters - nbChosenLetters);
                }

                List <char> fakeLetters = new List <char>(nbRandomLetters);
                for (int i = 0; i < nbRandomLetters; i++)
                {
                    fakeLetters.Add(StringTools.GetRandomLetterUpperCase());
                }

                // Create randoms letters tab
                List <char> allLetters = new List <char>(realLetters.Count + fakeLetters.Count);
                allLetters.AddRange(realLetters);

                // Insert randomly fake letters
                Random randomer = new Random();
                for (int i = 0; i < fakeLetters.Count; i++)
                {
                    int insertIndex = randomer.Next(0, allLetters.Count - 1);
                    allLetters.Insert(insertIndex, fakeLetters[i]);
                }

                // randomize first Nbitems
                var shuffledLetters = allLetters.Take(this.NbTotalLetters).OrderBy(a => randomer.NextDouble()).ToList();


                // Create random final tab
                List <char> randomizedLetters = new List <char>(allLetters.Count);
                for (int i = 0; i < allLetters.Count; i++)
                {
                    if (i < shuffledLetters.Count)
                    {
                        randomizedLetters.Insert(i, shuffledLetters[i]);
                    }
                    else
                    {
                        randomizedLetters.Insert(i, allLetters[i]);
                    }
                }


                this.RandomLetters             = randomizedLetters;
                this.currentRandomLettersIndex = this.NbTotalLetters - 1;

                // Prepare keyboard letters with random letters
                for (int i = 0; i < this.KeysViewModels.Count; i++)
                {
                    if (i < this.RandomLetters.Count)
                    {
                        char aChar = this.RandomLetters[i];
                        this.KeysViewModels[i].ReplaceLetter(aChar, false);
                        this.KeysViewModels[i].IsVisible = true;
                    }
                }


                // Reinit variables
                this.chosenLetterButtonKeys   = new List <KeyboardLetterControlViewModel>(this.RandomLetters.Count);
                this.chosenLetterButtonValues = new List <char>(this.RandomLetters.Count);
                this.currentWordsIndex        = 0;
                this.nbLettersFound           = 0;
                this.currentAnswer            = null;
                this.lastCheckWordResult      = QuizzAppCheckWordResult.QuizzAppCheckWordNone;

                this.PrepareTitleLetters();
            }
            this.isOnInitialization = false;
        }