//This method resets the Animator and then calls it to get the starting image, gets a new word and word score, sets up views for new word and resets the keyboard buttons. private void NewGame() { BtnNewGame.Visibility = ViewStates.Invisible; MyAnimator = new Animator(); DisplayImg.SetImageResource(MyAnimator.GetNextResource()); WordPicker myWordPicker = new WordPicker(WordList); Word = myWordPicker.GetRandomWord(); Score s = new Score(); WordScore = s.GetScore(Word); DisplayWord.RemoveAllViews(); foreach (var letter in Word) { DisplayWord.AddView(new TextView(this) { Text = letter.ToString(), TextSize = 50, TransformationMethod = new PasswordTransformationMethod() }); } foreach (Button key in KeyboardButtons) { key.Visibility = ViewStates.Visible; key.Enabled = true; } }
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(); } } }