示例#1
0
        // Check for letter in word
        private void CheckWord(string Letter)
        {
            SetPlayers();
            List <int> indexes = new List <int>();

            char[] tempWord = word.ToCharArray();
            char[] label    = wordTxt.Text.ToCharArray();
            char   l        = Char.Parse(Letter);

            if (tempWord.Contains(l))
            {
                // find letter index
                for (int i = 0; i < tempWord.Length; i++)
                {
                    if (l == tempWord[i])
                    {
                        indexes.Add(i);
                    }
                }


                for (int i = 0; i < indexes.Count; i++)
                {
                    // * 2, label is twice the length after formatting
                    label[indexes[i] * 2] = l;

                    // update scoreboard
                    wordInstance.AddPoints(tbName.Text);
                    SetPlayers();
                }
            }
            else
            {
                NumOfGuesses++;
                ChangePicture();

                if (NumOfGuesses == 10)
                {
                    winnerTxt.Visibility = Visibility.Visible;
                    wordInstance.SetWordState(tbName.Text);
                    MessageBox.Show("Word not solved!\nThe word was: " + word);
                    buttonPanel.IsEnabled = false;
                }
            }

            wordTxt.Text = new string(label);
            CheckWin();
        }