/** Changes all the textviews so they have the updated text */
  private void setText() {

    guessedView.setText(game.guessedString());
    guessesView.setText(game.guessesString());
    wordView.setText(game.wordString());
    setImage();
  }
 /**
  * Tests if the game has ended. It tests if you have lost or you won and you can continue to the
  * next word. It gives the message to the user with a dialog.
  */
 public void gameEnd() {
   // the player has no guesses left and lost
   if (game.leftGuesses == 0) {
     AlertDialog.Builder end = new AlertDialog.Builder(GameActivity.this);
     end.setTitle(R.string.gameover);
     end.setMessage(getResources().getString(R.string.end) + game.word);
     end.setPositiveButton(
         R.string.end_button,
         new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
             Intent intent = new Intent(GameActivity.this, HighscoreActivity.class);
             intent.putExtra("gamescore", game.score);
             intent.putExtra("wordlength", game.setLength);
             if (evilType) {
               intent.putExtra("gametype", "evil");
             } else {
               intent.putExtra("gametype", "good");
             }
             startActivity(intent);
             finish();
           }
         });
     // he must go to the highscorescreen
     end.setCancelable(false);
     end.create();
     end.show();
     // All the letters of the word have been guessed
   } else if (game.wordString().indexOf("-") < 0) {
     // The player gets a point
     game.addScore(1);
     AlertDialog.Builder end = new AlertDialog.Builder(GameActivity.this);
     end.setTitle(R.string.guessed);
     end.setMessage(getResources().getString(R.string.guess_end) + game.word);
     end.setPositiveButton(
         R.string.next_word,
         new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
             nextWord();
           }
         });
     // The player must go to the next word
     end.setCancelable(false);
     end.create();
     end.show();
   }
 }
  /**
   * Reads in the filled EditText, tests if correct and handles it correctly
   *
   * @param view The button that was pressed
   */
  public void guessLetter(View view) {
    String guess = enterView.getText().toString();
    // It must only be one character
    if (guess.length() != 1) {
      Toast.makeText(getApplicationContext(), "Please enter 1 letter", Toast.LENGTH_SHORT).show();
    } else {
      // All the characters are tested on uppercase
      char letter = guess.toUpperCase().charAt(0);

      // tests if it wasn't guessed before
      if (game.guessed(letter)) {
        Toast.makeText(getApplicationContext(), "Already guessed this letter", Toast.LENGTH_SHORT)
            .show();
      } else {
        game.guess(letter, getApplicationContext());
      }
    }
    setText();
    gameEnd();
  }
 /** Saves the game so that the player can continue at a different time */
 private void saveFile() {
   PrintStream out = null;
   try {
     out = new PrintStream(openFileOutput(SaveFile, MODE_PRIVATE));
     // there is no game to be saved
     if (game.leftGuesses == 0 || (game.score == 0 && game.lettersGuessed[0] == '\0')) {
       out.println("<NO>");
       // there is a gam to be saved
     } else {
       out.println("<YES>");
       if (game.getClass().equals(EvilGameplay.class)) {
         out.println("evil");
         for (String w : EvilGameplay.words) {
           out.println(w);
         }
         out.println("<STOP>");
       } else {
         out.println("good");
         out.println(game.word);
       }
       out.println(game.score);
       out.println(game.leftGuesses);
       out.println(game.setLength);
       out.println(game.setGuesses);
       for (char c : game.wordLetters) {
         out.println(c);
       }
       for (char c : game.lettersGuessed) {
         out.println(c);
       }
     }
     out.close();
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
 }
 /** Prepares the game for the next round. Next word is loaded in and the guesses are reset */
 public void nextWord() {
   game.selectWord();
   game.resetGuesses();
   setText();
 }