Example #1
0
        private void MakeGuess(bool correct)
        {
            //if game has started
            if (GameStarted && GuessCount > 0)
            {
                try
                {
                    //letter is a good guess
                    if (correct)
                    {
                        IndexButton.Show();
                        IndexInfo.Show();
                        TipText.Show();
                        WrongButton.Hide();
                        RightButton.Hide();
                    }//letter is a bad guess
                    else
                    {
                        BadGuesses     += Guess;
                        PossibleLetters = PossibleLetters.Replace(Guess, "");
                        Guess           = PossibleLetters[0].ToString();
                        label2.Text     = TheWord;
                        GuessText.Text  = Guess;


                        label1.Text = BadGuesses;
                        GuessCount--;
                        GuessCountLabel.Text = GuessCount.ToString();
                        //remove words from list containing bad guessed letter
                        PossibleWordSet = new SortedSet <string>(from p in PossibleWordSet
                                                                 where !p.Contains(Guess)
                                                                 select p);
                        possible.Text          = PossibleLetters;
                        possiblewordcount.Text = PossibleWordSet.Count.ToString();
                    }



                    if (GuessCount == 0)
                    {
                        WinningGif.Show();
                        RightButton.Hide();
                        WrongButton.Hide();
                        GuessText.Hide();
                    }



                    //if (label2.Text == TheWord)
                    //{
                    //    RightButton.Hide();
                    //    WrongButton.Hide();
                    //}
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }
Example #2
0
        private void GuessButton_Click(object sender, EventArgs e)
        {
            //if game has started
            if (GameStarted && GuessCount > 0)
            {
                try
                {
                    //pick beginning letter based on popularity, words left
                    Random r     = new Random();
                    int    index = 0;
                    string guess = "";

                    //guess first letters of remaining words after first hit
                    if (GoodGuesses.Length == 1)
                    {
                        index = r.Next(0, PossibleWords.Length);
                        guess = PossibleWords[index][PossibleWords[index].Length - 1].ToString();
                    }//if we are one guess away
                    else if (TheWord.Length - GoodGuesses.Length == 1)
                    {
                        index = label2.Text.IndexOf("_");
                        guess = PossibleWords[0][index].ToString();
                    }
                    else
                    {
                        //guess based on letters found in possible words
                        index = label2.Text.IndexOf("_");
                        guess = PossibleWords[r.Next(0, PossibleWords.Length)][index].ToString();

                        //if letter has been guessed - guess based on popular
                        if (GuessesSoFar.Contains(guess))
                        {
                            //just guess on the popular side of random letters
                            {
                                index = r.Next(0, PossibleLetters.Length / 3);
                                guess = PossibleLetters[index].ToString();
                            }
                        }
                    }

                    PossibleLetters = PossibleLetters.Replace(guess, "");

                    //letter is a good guess
                    if (TheWord.Contains(guess))
                    {
                        //change word string
                        string temp = "";
                        int    i    = 0;
                        foreach (char c in TheWord)
                        {
                            string letter = c.ToString();
                            if (letter.Equals(guess)) //add it and sort words based on position of guess
                            {
                                temp         += guess;
                                GoodGuesses  += guess;
                                PossibleWords = (from p in PossibleWords
                                                 where p[i] == TheWord[i]
                                                 select p).ToArray();
                            }
                            else
                            {
                                temp += GuessesSoFar[i];
                            }
                            i++;
                        }
                        label2.Text  = temp;
                        GuessesSoFar = temp;
                    }//letter is a bad guess
                    else
                    {
                        BadGuesses += guess;
                        label1.Text = BadGuesses;
                        GuessCount--;
                        GuessCountLabel.Text = GuessCount.ToString();
                        //remove words from list containing bad guessed letter
                        PossibleWords = (from p in PossibleWords
                                         where !p.Contains(guess)
                                         select p).ToArray();
                    }

                    possible.Text          = PossibleLetters;
                    possiblewordcount.Text = PossibleWords.Length.ToString();

                    if (GuessCount == 0)
                    {
                        WinningGif.Show();
                    }
                    if (label2.Text == TheWord)
                    {
                        GuessButton.Hide();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }
Example #3
0
        private void IndexButton_Click(object sender, EventArgs e)
        {
            //index will be user
            //change word string
            //IndexButton.Hide();
            //IndexInfo.Hide();
            //WrongButton.Show();
            //RightButton.Show();

            GuessText.Text = Guess;
            string temp = IndexInfo.Text;

            IndexInfo.Hide();
            IndexButton.Hide();
            TipText.Hide();
            List <int> indexList = temp.Split(',').Select(int.Parse).ToList();


            foreach (int i in indexList)
            {
                StringBuilder sb = new StringBuilder(TheWord);
                sb[i]   = char.Parse(Guess);
                TheWord = sb.ToString();

                //might need to do a temp set = to possibleWordSet and run the query on that
                PossibleWordSet = new SortedSet <string>(from p in PossibleWordSet
                                                         where p[i] == TheWord[i] //the guess
                                                         select p);
            }
            label2.Text   = TheWord;
            GuessesSoFar += Guess;

            possible.Text          = PossibleLetters;
            possiblewordcount.Text = PossibleWordSet.Count.ToString();



            //new guess
            var count = TheWord.Count(x => x == '_'); //count of _

            if (count == 1)
            {
                PossibleWordSet = new SortedSet <string>(from p in PossibleWordSet
                                                         where PossibleLetters.Contains(p[TheWord.IndexOf('_')]) //the guess
                                                         select p);
            }

            PossibleLetters = PossibleLetters.Replace(Guess, "");

            Guess = PossibleLetters[0].ToString();

            GuessText.Text = Guess;

            WrongButton.Show();
            RightButton.Show();
            IndexInfo.Clear();

            if (!TheWord.Contains("_"))
            {
                guessRightLabel.Text = "We Guessed Right!";
                guessRightLabel.Show();
                RightButton.Hide();
                WrongButton.Hide();
                IndexButton.Hide();
                IndexInfo.Hide();
                GuessText.Hide();
            }
        }