示例#1
0
文件: Form1.cs 项目: blakel95/Hangman
 //when new word is picked
 public void ResetGame()
 {
     TheWordText.Text     = "The Word Being Guessed:";
     PossibleText.Text    = "# of Possible Words Left:";
     LettersLeftText.Text = "Letters Left:";
     BadGuessesText.Text  = "Bad Guesses:";
     GoodGuessesText.Text = "Good Guesses:";
     GuessesLeftText.Text = "Guesses Left:";
     GoodGuessesText.Hide();
     GuessCount           = 9;
     GameStarted          = true;
     GuessCountLabel.Text = GuessCount.ToString();
     GuessCountLabel.Show();
     WinningGif.Hide();
     RightButton.Show();
     WrongButton.Show();
     GuessText.Show();
     GoodGuesses     = "";
     BadGuesses      = "";
     PossibleLetters = "etainoshrdlucmfwygpbvkqjxz"; //most popular letters based on https://en.oxforddictionaries.com/explore/which-letters-are-used-most
     GuessesSoFar    = "";
     label1.Text     = "";
     label2.Text     = "";
     test.Text       = "";
     TheWord         = "";
     Guess           = PossibleLetters[0].ToString();
     label2.Text     = Guess;
     IndexButton.Hide();
     IndexInfo.Hide();
     TipText.Hide();
 }
示例#2
0
文件: Form1.cs 项目: blakel95/Hangman
        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();
            }
        }