예제 #1
0
    private bool HighlightWords(string input)
    {
        List <string>     currentWords   = CurrentWord.GetCurrentWords();
        List <GameObject> currentObjects = CurrentWord.GetCurrentWordObjects();
        bool wordFound = false;

        if (currentWords.Count != currentObjects.Count)
        {
            throw new System.Exception("word and object list does not match wtf");
        }

        for (int i = 0; i < currentObjects.Count; i++)
        {
            if (input.Equals(currentWords[i]))
            {
                wordFound = true;
            }
            else if (input.Length <= currentWords[i].Length)
            {
                string checkmatch = currentWords[i].Substring(0, input.Length);
                if (input.Equals(checkmatch))
                {
                    currentObjects[i].GetComponent <WordMovement>().updateHighlighting(input);
                    wordFound = true;
                }
            }
        }

        return(wordFound);
    }
예제 #2
0
        public void Ask()
        {
            Console.WriteLine("\nGuess a letter:");
            PlayerGuess = Console.ReadLine().ToLower();
            LettersUsed.Add(PlayerGuess);

            while (PlayerGuess.Trim().Length != 1)
            {
                Console.Clear();
                Console.WriteLine("Input 1 letter at a time");
                return;
            }

            char guess = PlayerGuess.Trim().ToCharArray()[0];

            if (CodeWord.Contains(guess))
            {
                Console.WriteLine($"{guess} is in the word!");
                for (int i = 0; i < CodeWord.Length; i++)
                {
                    if (guess == CodeWord[i])
                    {
                        Console.Clear();
                        CurrentWord = CurrentWord.Remove(i, 1).Insert(i, guess.ToString());
                    }
                }
            }
            else
            {
                CurrentNumWrongGuess++;
                ufos.AddPart();
                Console.Clear();
            }
        }
예제 #3
0
        ///<summary>
        ///this method capture the user's input letter(it has to be one letter at a time), checks if that letter is indeed anywhere
        ///in the codeword. If yes print those leters at the exact places in the codeword. If the codeword does not contains the user's guess
        ///increase the wrongGuess counter by 1
        /// </summary>

        public void Ask()
        {
            Console.WriteLine("Guess a letter: ");
            string userGuess             = Console.ReadLine();
            string userGuessWithoutSpace = userGuess.Trim();

            while (userGuessWithoutSpace.Length != 1)
            {
                Console.WriteLine("Please enter one letter at a time");
            }
            char guess = userGuessWithoutSpace.ToCharArray()[0];

            if (CodeWord.Contains(guess))
            {
                Console.WriteLine("Here are your guess in the codeWord!");
                for (int i = 0; i < CodeWord.Length; i++)
                {
                    if (guess == CodeWord[i])
                    {
                        CurrentWord = CurrentWord.Remove(i, 1).Insert(i, guess.ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine("Sorry, your guess does not appear in the the codeWord");
                CurrentNumberOfWrongGuess++;
                ufo.AddPart();
            }
        }
예제 #4
0
        /// <summary>
        ///     suggestions for a typical fault of spelling, that
        ///		differs with more, than 1 letter from the right form.
        /// </summary>
        private void ReplaceChars(List <Word> tempSuggestion)
        {
            List <string> replacementChars = Dictionary.ReplaceCharacters;

            for (int i = 0; i < replacementChars.Count; i++)
            {
                int    split       = replacementChars[i].IndexOf(' ');
                string key         = replacementChars[i].Substring(0, split);
                string replacement = replacementChars[i].Substring(split + 1);

                int pos = CurrentWord.IndexOf(key, StringComparison.InvariantCulture);
                while (pos > -1)
                {
                    string tempWord = CurrentWord.Substring(0, pos);
                    tempWord += replacement;
                    tempWord += CurrentWord.Substring(pos + key.Length);

                    if (FindWord(ref tempWord))
                    {
                        SuggestWord(tempWord, tempSuggestion);
                    }

                    pos = CurrentWord.IndexOf(key, pos + 1, StringComparison.InvariantCulture);
                }
            }
        }
예제 #5
0
        public void Ask()
        {
            Console.WriteLine("Hey human! Try to guess a letter or I'll take this other human!");
            string answer = Console.ReadLine();

            Console.WriteLine();
            if (answer.Trim().Length != 1)
            {
                Console.WriteLine("Please, one letter at a time.");
                return;
            }
            char charCode = answer.Trim().ToCharArray()[0];

            if (CodeWord.Contains(charCode))
            {
                Console.WriteLine("You've got it right!");
                for (int i = 0; i < CurrentWord.Length; i++)
                {
                    if (CodeWord[i] == charCode)
                    {
                        CurrentWord = CurrentWord.Remove(i, 1).Insert(i, charCode.ToString());
                    }
                }
            }
            else
            {
                NumGuesses++;
                ufo.AddPart();
            }
        }
예제 #6
0
        public static ArrayList GetWords(string text)
        {
            ArrayList     words       = new ArrayList();
            StringBuilder CurrentWord = new StringBuilder();

            foreach (char c in text.ToCharArray())
            {
                if (c == ' ' || c == '\t')
                {
                    if (CurrentWord.ToString() != "")
                    {
                        words.Add(CurrentWord.ToString());
                        CurrentWord = new StringBuilder();
                    }

                    words.Add(c.ToString
                                  (CultureInfo.InvariantCulture));
                }
                else
                {
                    CurrentWord.Append(c.ToString
                                           (CultureInfo.InvariantCulture)
                                       );
                }
            }
            if (CurrentWord.ToString() != "")
            {
                words.Add(CurrentWord.ToString());
            }
            return(words);
        }
예제 #7
0
        public static ArrayList GetWords(string text)
        {
            ArrayList words = new ArrayList();

            System.Text.StringBuilder CurrentWord = new System.Text.StringBuilder();

            for (int i = 0; i < text.Length; i++)
            {
                char c = text[i];

                if (c == ' ' || c == '\t')
                {
                    if (CurrentWord.ToString() != "")
                    {
                        words.Add(CurrentWord.ToString());
                        CurrentWord = new System.Text.StringBuilder();
                    }

                    words.Add(c.ToString());
                }
                else
                {
                    CurrentWord.Append(c.ToString());
                }
            }
            if (CurrentWord.ToString() != "")
            {
                words.Add(CurrentWord.ToString());
            }
            return(words);
        }
예제 #8
0
        public void Ask()
        {
            Console.Write("Guess a letter: ");
            string stringGuess = Console.ReadLine();

            Console.WriteLine();
            if (stringGuess.Trim().Length != 1)
            {
                Console.WriteLine("One letter at a time!");
                return;
            }
            char guess = stringGuess.Trim().ToCharArray()[0];

            if (CodeWord.Contains(guess))
            {
                Console.WriteLine($"'{guess}' is in the word!");
                for (int i = 0; i < CodeWord.Length; i++)
                {
                    if (guess == CodeWord[i])
                    {
                        CurrentWord = CurrentWord.Remove(i, 1).Insert(i, guess.ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine($"'{guess}' isn't in the word! The tractor beam pulls the person in further...");
                WrongGuesses++;
                spaceship.AddPart();
            }
        }
예제 #9
0
        public static List <string> GetWords(string text)
        {
            var words       = new List <string>();
            var CurrentWord = new StringBuilder();

            foreach (char c in text)
            {
                if (c == ' ' || c == '\t')
                {
                    if (CurrentWord.ToString() != "")
                    {
                        words.Add(CurrentWord.ToString());
                        CurrentWord = new StringBuilder();
                    }

                    words.Add(c.ToString());
                }
                else
                {
                    CurrentWord.Append(c.ToString()
                                       );
                }
            }
            if (CurrentWord.ToString() != "")
            {
                words.Add(CurrentWord.ToString());
            }
            return(words);
        }
 public static void PlayerMistake()
 {
     audio.Play();
     foreach (var ob in CurrentWord.GetCurrentWordObjects())
     {
         ob.GetComponent <WordMovement>().Mistake();
     }
 }
예제 #11
0
        public void Ask()
        {
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("\nPlease type a letter.");
            Console.ResetColor();
            string input = Console.ReadLine();

            // check and tell user to enter ONLY 1 letter
            if (input.Length > 1)
            {
                Console.WriteLine("Please only type ONE letter at a time!\nPress Enter to continue...");
                Console.ReadLine();
                return;
            }

            // check if the input is a letter and prompt the user if not
            if (!char.IsLetter(input[0]))
            {
                Console.WriteLine("Please only enter letters!\nPress Enter to continue...");
                Console.ReadLine();
                return;
            }

            // convert input to lower letter
            string letter = input[0].ToString().ToLower();

            // if the letter has already been inclear
            if (letterList.Contains(letter))
            {
                Console.WriteLine("'{0}' has already been found.\nPlease insert another letter\nPress Enter to continue...", letter);
                Console.ReadLine();
                return;
            }
            letterList.Add(letter);

            // check if the word contains the inserted letter
            if (Codeword.Contains(letter))
            {
                // prompt the user
                Console.WriteLine("Good guess. The codeword contains '{0}'.", letter);
                // loop thru codeword for inserted letter
                // if found replace '_' with letter in current word
                for (int i = 0; i < Codeword.Length; i++)
                {
                    if (Codeword[i].ToString() == letter)
                    {
                        CurrentWord = CurrentWord.Remove(i, 1).Insert(i, letter);
                    }
                }
            }
            // increase the wrong guesses by 1 and Update ufo image
            else
            {
                CurrentNumWrongGuesses += 1;
                ufo.AddPart();
            }
        }
예제 #12
0
        private static void GameInputProcessing()
        {
            while (true)
            {
                DisplayMethod();

                Console.Write("\nEnter guess [# to complete]: ");
                var guess = Console.ReadLine()?.ToLower().Trim();

                while (guess != "#" && !Alphabet.Contains(guess) || GuessProcessing.IsAlreadyGuessed(guess))
                {
                    Console.WriteLine("\nThat ain't a correct guess chief");
                    Console.Write("Enter guess: ");
                    guess = Console.ReadLine()?.ToLower().Trim();
                }

                if (guess == "#")
                {
                    Console.Write("\nEnter guess to complete: ");
                    var completeGuess = Console.ReadLine()?.ToLower().Trim();

                    while (string.IsNullOrWhiteSpace(completeGuess) || completeGuess.ContainsInt())
                    {
                        Console.WriteLine("\nThat ain't a correct guess chief");
                        Console.Write("Enter guess: ");
                        completeGuess = Console.ReadLine()?.ToLower().Trim();
                    }

                    if (completeGuess == CurrentWord)
                    {
                        WinMethod();
                    }

                    IncorrectGuess(completeGuess);
                    continue;
                }

                GuessedCharsPositions.Add(GuessProcessing.UpdateGuessedChars(guess));

                IReadOnlyCollection <int> indexes = CurrentWord.GetAllIndexes(guess).ToList().AsReadOnly();

                if (indexes.Count == 0)
                {
                    IncorrectGuess(guess); continue;
                }

                GuessedWord = GuessProcessing.UpdateGuessedWord(indexes);

                if (GuessProcessing.HasWon())
                {
                    WinMethod();
                }

                Console.Clear();
            }
        }
예제 #13
0
        private void Guess()
        {
            if (!string.IsNullOrWhiteSpace(CurrentWord))
            {
                var candidates = WordPool.Where(word => word.StartsWith(CurrentWord.Trim().ToLower()));

                CanGuess = candidates.Any();

                BestGuess = CanGuess ? candidates.First() : string.Empty;
            }
        }
예제 #14
0
        public void Ask()
        {
            if (_guessedLetters.Count > 0)
            {
                Console.WriteLine($"Already typed letters in thi game session: ");
                _guessedLetters.ForEach(item => Console.Write($" {item} "));
                Console.WriteLine("");
            }

            Console.Write("Enter your guess letter: ");
            var input = Console.ReadLine()?.ToLower();

            if (input == null)
            {
                return;
            }

            if (input.Length > 1)
            {
                Console.WriteLine("Only one letter at a time is valid.");
                return;
            }

            var contains = Codeword.Contains(input);
            var letter   = input.ToCharArray()[0];

            if (_guessedLetters.Contains(letter))
            {
                Console.WriteLine($"You already typed the ({input}) letter, try another one...");
                return;
            }

            if (contains)
            {
                var currentIndex = 0;
                while (true)
                {
                    var index = Codeword.IndexOf(letter, currentIndex);
                    if (index == -1)
                    {
                        break;
                    }
                    currentIndex = index + 1;
                    CurrentWord  = CurrentWord.Remove(index, 1).Insert(index, letter.ToString());
                }
            }
            else
            {
                Ufo.AddPart();
                WrongGuesses++;
            }
            _guessedLetters.Add(letter);
        }
예제 #15
0
 // Update is called once per frame
 void Update()
 {
     if (!CheckOutsideCamera())
     {
         UpdatePosition(Time.deltaTime);
     }
     else
     {
         CurrentWord.DestroyWordByText(_textUnder.text);
         PlayerProgression.PlayerMiss();
     }
 }
예제 #16
0
        private void GetLettersFromWord()
        {
            var charArray = CurrentWord.ToCharArray();
            var position  = 0;

            foreach (var letter in charArray)
            {
                var newLetter = new Letter(letter);
                Letters.SetValue(newLetter, position);
                position++;
            }
        }
예제 #17
0
        public static unsafe void AddString(string Text, Row Row, TextStyle Style,
                                            Segment Segment)
        {
            if (Text == "")
            {
                return;
            }

            StringBuilder CurrentWord = new StringBuilder();

            char[] Buff = Text.ToCharArray();
            fixed(char *c = &Buff[0])
            {
                for (int i = 0; i < Text.Length; i++)
                {
                    if (c[i] == ' ' || c[i] == '\t')
                    {
                        if (CurrentWord.Length != 0)
                        {
                            Word word = Row.Add(CurrentWord.ToString());
                            word.Style   = Style;
                            word.Segment = Segment;
                            CurrentWord  = new StringBuilder();
                        }

                        Word ws = Row.Add(c[i].ToString
                                              (CultureInfo.InvariantCulture));
                        if (c[i] == ' ')
                        {
                            ws.Type = WordType.xtSpace;
                        }
                        else
                        {
                            ws.Type = WordType.xtTab;
                        }
                        ws.Style   = Style;
                        ws.Segment = Segment;
                    }
                    else
                    {
                        CurrentWord.Append(c[i].ToString
                                               (CultureInfo.InvariantCulture));
                    }
                }
                if (CurrentWord.Length != 0)
                {
                    Word word = Row.Add(CurrentWord.ToString());
                    word.Style   = Style;
                    word.Segment = Segment;
                }
            }
        }
예제 #18
0
    private int CheckCurrentWord(string word)
    {
        //Debug.Log(CurrentWord.GetCurrentWords()+":"+word);
        List <string> currentWords = CurrentWord.GetCurrentWords();

        for (int i = 0; i < currentWords.Count; i++)
        {
            if (word == currentWords[i])
            {
                return(i);
            }
        }
        return(-1);
    }
예제 #19
0
        public void  Next(string str_)
        {
            iOffset = iEndOffset = 0;
            CurrentWord.Init();

            //  increment by previous buffer length.
            if (strBuffer != null)
            {
                iShiftOffset += BufferLength;
            }

            strBuffer    = str_;
            BufferLength = strBuffer.Length;
        }
예제 #20
0
        /// <summary>
        ///     split the string into two pieces after every char
        ///		if both pieces are good words make them a suggestion
        /// </summary>
        private void TwoWords(List <Word> tempSuggestion)
        {
            for (int i = 1; i < CurrentWord.Length - 1; i++)
            {
                string firstWord  = CurrentWord.Substring(0, i);
                string secondWord = CurrentWord.Substring(i);

                if (FindWord(ref firstWord) && FindWord(ref secondWord))
                {
                    string tempWord = firstWord + " " + secondWord;
                    SuggestWord(tempWord, tempSuggestion);
                }
            }
        }
 public static void NextLevel()
 {
     currentLevel           += 1;
     currentLevelProgression = 0;
     CurrentWord.ResetWords();
     RecalculateSpeed();
     if (currentLevel % 2 == 1)
     {
         GameObject.Find("MainCamera").GetComponent <CameraTransition>().ChangeToOfficeCamera();
         //1.5f when you are in the office
         CurrentWord.InvokeSpawn(2f);
     }
     else
     {
         //2f when you are at home
         CurrentWord.InvokeSpawn(2.5f);
         GameObject.Find("MainCamera").GetComponent <CameraTransition>().ChangeToHomeCamera();
     }
 }
예제 #22
0
        private static void DisplayMethod()
        {
            var wordLength = CurrentWord.Length - CurrentWord.Count(x => x == ' ');

            Console.WriteLine($"\n{GuessedWord} {wordLength} chars long | {Hangman.Length - Attempts} attempts left\n\n");

            for (var i = 0; i < Alphabet.Length; i++)
            {
                if (GuessedCharsPositions.Contains(i))
                {
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.Write($"{Alphabet[i]}, ");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Console.Write($"{Alphabet[i]}, ");
                }
            }
        }
예제 #23
0
        public void Ask()
        {
            PrintColorMessage(ConsoleColor.Yellow, "Guess a letter: ");
            string stringGuess = Console.ReadLine(); // Get users input

            Console.WriteLine();

            // Check if users input is of length 1  and is a letter
            if (stringGuess.Trim().Length != 1 || int.TryParse(stringGuess.Trim(), out _))
            {
                PrintColorMessage(ConsoleColor.Red, "Only a single letters are accepted!");
                return;
            }

            // Convert user inpur string to char and add to char array
            char guess = stringGuess.Trim().ToCharArray()[0];

            if (CodeWord.Contains(guess))
            {
                // If word contains given letter, find its index ....
                PrintColorMessage(ConsoleColor.Yellow, $"'{guess}' is in the word!");

                for (int i = 0; i < CodeWord.Length; i++)
                {
                    if (guess == CodeWord[i])
                    {
                        //... and replace '_' in a string with a letter
                        CurrentWord = CurrentWord.Remove(i, 1).Insert(i, guess.ToString());
                    }
                }
            }
            else
            {
                // If codeword doesn't contain the letter, increase number of wrong guesses...
                Console.WriteLine();
                PrintColorMessage(ConsoleColor.Yellow, $"'{guess}' isn't in the word! The tractor beam pulls the person in further...");
                WrongGuesses++;
                // Update the string representation of a spaceship according to a current number of wrong guesses
                spaceship.AddPart();
            }
        }
예제 #24
0
        public void Ask()
        {
            Console.WriteLine("Guess a letter:");
            string userGuess = Console.ReadLine();

            if (userGuess.Length != 1)
            {
                Console.WriteLine("One letter at a time!");
                return;
            }

            char guess = userGuess.ToCharArray()[0];

            char[] guessArray = userGuess.ToCharArray();

            if (CodeWord.Contains(guess))
            {
                Console.WriteLine($"{guess} is in the word");
                for (int i = 0; i < CodeWord.Length; i++)
                {
                    if (guess == CodeWord[i])
                    {
                        CurrentWord = CurrentWord.Remove(i, 1).Insert(i, guess.ToString());
                    }
                }
            }

            else
            {
                Console.WriteLine($"{guess} is not in the word. The beam pulls you up further...");
                WrongGuesses++;
                spaceship.AddPart();
            }

            for (int i = 0; i < guessArray.Length; i++)
            {
                Console.WriteLine($"Letters you have guessed so far:{guessArray[i]}");
            }
        }
예제 #25
0
        public bool IsCorrectGuess(char guess)
        {
            var wordChars = CurrentWord.ToCharArray();
            var result    = false;

            for (var i = 0; i < wordChars.Length; i++)
            {
                var wordChar = wordChars[i];
                if (wordChar == guess)
                {
                    _hiddenWord[i] = wordChar;
                    result         = true;
                }
            }

            if (result == false)
            {
                GuessedCharacters.Add(guess);
            }

            return(result);
        }
예제 #26
0
        public List <int> CheckLetter(Char letter, out string message)
        {
            List <int> matchedIndexs = new List <int>();


            foreach (var c in GuessedCharacters)
            {
                if (letter == c)
                {
                    message = "You have already guessed that letter";
                    return(matchedIndexs);
                }
            }


            for (int i = 0; i < CurrentWord.Length; i++)
            {
                if (Char.ToUpper(letter) == CurrentWord.ToUpper()[i])
                {
                    guessed [i] = Char.ToUpper(letter);
                    matchedIndexs.Add(i);
                }
            }

            if (matchedIndexs.Count == 0)
            {
                message = "That letter wasnt in the word";
                Lives--;
            }
            else
            {
                message = "You guessed correctly";
            }


            GuessedCharacters.Add(letter);
            return(matchedIndexs);
        }
예제 #27
0
    private void Update()
    {
        foreach (char c in Input.inputString)
        {
            if (c == '\b') // has backspace/delete been pressed?
            {
                BackSpace();
            }
            else if ((c == '\n') || (c == '\r')) // enter/return
            {
                ClearInputText();
            }
            // TO DO: We can't allow spacebar
            else
            {
                char lowerChar = char.ToLower(c);
                AddInputCharacter(lowerChar);
                int indexCurrentWord = CheckCurrentWord(_text.text);
                if (indexCurrentWord >= 0)
                {
                    ClearInputText();

                    //Destroy Letter
                    CurrentWord.DestroyWord(indexCurrentWord);
                    if (PlayerProgression.RightWord(100))
                    {
                        // The player just got new level
                        audio.PlayOneShot(audioLevelUp);
                    }
                    else
                    {
                        // The player just got the right word
                        audio.PlayOneShot(audioCorrectWord);
                    }
                }
            }
        }
    }
예제 #28
0
        public int[] TakeCharacter(char ch)
        {
            int[] temp = new int[CurrentWord.Length];

            for (int i = 0; i < CurrentWord.Length; i++)
            {
                if (CurrentWord.ToUpper()[i] == ch)
                {
                    temp[i] = 1;
                }
                else
                {
                    temp[i] = 0;
                }
            }

            if (temp.Count(i => i == 1) == 0)
            {
                Stage++;
            }

            return(temp);
        }
예제 #29
0
    private void Awake()
    {
        invokerController = this;
        wordsObject       = new Words();
        //currentWord = "";
        GameObject tempObject    = GameObject.Find("ScreenCanvas");
        GameObject tempCamObject = GameObject.Find("MainCamera");

        if (tempObject != null)
        {
            //If we found the object , get the Canvas component from it.
            canvas = tempObject.GetComponent <Canvas>();
            if (canvas == null)
            {
                Debug.Log("Could not locate Canvas component on " + tempObject.name);
            }
        }

        if (tempCamObject != null)
        {
            cam = tempCamObject.GetComponent <Camera>();
        }
        invokerController.InvokeRepeating("SpawnWord", 0f, _spawnCooldown);
    }
예제 #30
0
        //-------------------------------------------------------------------------
        //  Extract new token from the input stream. Return EndOfStream token again
        //  if this token has already been  reported.
        //-------------------------------------------------------------------------

        public virtual Word    getNextWord()
        {
            int NumberOfSpecials;

            CurrentWord.ClearMarks();

            bool hasUpperCaseChars = false;

            if (CurrentWord.Tag != Word.TokenType.eoEOS)
            {
                SkipWhitespace();
                if (iOffset < BufferLength)
                {
                    iEndOffset = FindRightBorderOfToken(out NumberOfSpecials, out hasUpperCaseChars);
                    CleanToken(ref NumberOfSpecials);

                    string token       = strBuffer.Substring(iOffset, iEndOffset - iOffset + 1);
                    uint   ValidOffset = (uint)(iOffset + iShiftOffset) % MaximalOffset;
                    CurrentWord.Init(token, ValidOffset, iSentenceNumber, iTokenNumber++, Word.TokenType.eoUndef);
                    CurrentWord.SelfIdentifyType(NumberOfSpecials);
                    iOffset     += token.Length;
                    iTokenNumber = (ushort)(iTokenNumber % ushort.MaxValue);
                }
                else
                {
                    CurrentWord.Tag            = Word.TokenType.eoEOS;
                    CurrentWord.SentenceNumber = iSentenceNumber;
                }
            }

            if (hasUpperCaseChars)
            {
                CurrentWord.NormalizeCase();
            }
            return(CurrentWord);
        }