Ejemplo n.º 1
0
        private void Letter_Click(object sender, EventArgs e)
        {
            //When a letter button is clicked create a reference to it by casting the sender object to a button, then get the text from the button and disable it.
            Button clickedButton = (Button)sender;
            String Letter        = clickedButton.Text;

            clickedButton.Enabled = false;

            //If letter matches any the the DisplayWord's TextView's text property then remove the password mask and set correctGuess bool to true.
            bool correctGuess = false;

            for (int i = 0; i < DisplayWord.ChildCount; i++)
            {
                TextView myTextView = (TextView)DisplayWord.GetChildAt(i);
                if (myTextView.Text == Letter.ToLower())
                {
                    myTextView.TransformationMethod = null;
                    correctGuess = true;
                }
            }
            //If it was a correct guess then add points and check if the word is complete, if so then the player wins.
            if (correctGuess)
            {
                WordScore += 2;
                if (CheckIfComplete())
                {
                    //WIN CONDITION alert the player, update profile score and call GameFinished method.
                    Toast.MakeText(this, "YOU WIN! +" + WordScore + "points!", ToastLength.Long).Show();
                    Score.Text = "Player Score: " + (Marks + WordScore).ToString();
                    GameFinished();
                }
            }
            else
            //Guess was wrong, decrement points, call the animator to get next image, if animatator is out of images the player loses.
            {
                WordScore -= 1;
                DisplayImg.SetImageResource(MyAnimator.GetNextResource());
                if (MyAnimator.EndOfResources)
                {
                    //LOSE CONDITION alert the player, update profile score and call GameFinished method.
                    Toast.MakeText(this, "YOU LOSE! -" + LossPoints + "points!\nThe word was " + Word, ToastLength.Long).Show();
                    // PlayerProfile.HighScore -= LossPoints;
                    Score.Text = "Player Score: " + (Marks - LossPoints).ToString();
                    GameFinished();
                }
            }
        }