/*
  * Sets the letters of the player that has lost the round.
  */
 private void setLettersLosingPlayer() {
   if (game.turn() == 1) {
     game.setLettersPlayer1();
     lettersPlayer1.setText(game.getLettersPlayer1());
   } else {
     game.setLettersPlayer2();
     lettersPlayer2.setText(game.getLettersPlayer2());
   }
 }
Esempio n. 2
0
  @TargetApi(Build.VERSION_CODES.KITKAT)
  private void updateView() {
    // Update the current game letters
    TextView textView = (TextView) findViewById(R.id.textview1);
    textView.setText(Html.fromHtml(game.guessedLetters));
    // build up message (if any)
    String messageString = convertMessage();
    TextView message = (TextView) findViewById(R.id.message);
    message.setText(messageString);
    // two textviews indicating player names and score..
    TextView p1tv = (TextView) findViewById(R.id.p1tv);
    TextView p2tv = (TextView) findViewById(R.id.p2tv);
    p1tv.setText(game.p1.getName() + " (" + game.p1.getScore() + ")");
    p1tv.setTextSize(game.turn() ? 30 : 20);
    p2tv.setText(game.p2.getName() + " (" + game.p2.getScore() + ")");
    p2tv.setTextSize(game.turn() ? 20 : 30);
    // text input and submit button
    EditText textInput = (EditText) findViewById(R.id.editText1);
    Button submitButton = (Button) findViewById(R.id.submit);
    // rematch button
    Button rematchButton = (Button) findViewById(R.id.rematch);
    // set the image indicating language
    int uri = dictionaryEnglish ? R.drawable.flag_en : R.drawable.flag_nl;
    if (flagId != uri) { // if not set already..
      flagId = uri;
      Drawable res = ContextCompat.getDrawable(this, uri);
      ImageView imageView = (ImageView) findViewById(R.id.flag);
      imageView.setImageDrawable(res);
    }

    if (game.ended()) { // check if the game has ended and update the display accordingly
      hide_keyboard(this);
      submitButton.setVisibility(View.GONE);
      textInput.setVisibility(View.GONE);
      rematchButton.setVisibility(View.VISIBLE);
    } else { // otherwise the game is running or restarted
      submitButton.setVisibility(View.VISIBLE);
      textInput.setVisibility(View.VISIBLE);
      rematchButton.setVisibility(View.GONE);
      textInput.setText("");
    }
  }
 /*
  * Sets the source of the ImageView that indicates the player turn and makes the name of the
  * player whose turn it is bold (and makes the name of the other player not bold).
  */
 private void setImageTurnAndHighlightPlayer() {
   if (game.turn() == 1) {
     textNamePlayer1.setTypeface(Typeface.DEFAULT_BOLD);
     textNamePlayer2.setTypeface(Typeface.DEFAULT);
     playerTurn.setImageResource(R.drawable.ghost);
   } else {
     textNamePlayer1.setTypeface(Typeface.DEFAULT);
     textNamePlayer2.setTypeface(Typeface.DEFAULT_BOLD);
     playerTurn.setImageResource(R.drawable.ghost2);
   }
 }
 /*
  * Creates a Game instance (see Game.java) and uses the method 'setImageTurnAndHighlightPlayer()'
  * to:
  * 1) Set the source of the ImageView that indicates the player turn, and
  * 2) Make the name of the player whose turn it is bold.
  */
 private void createNewGame(Lexicon lexicon) {
   game = new Game(lexicon);
   setImageTurnAndHighlightPlayer();
   Toast.makeText(
           getApplication(),
           getString(R.string.ghost_game_text_start1)
               + " "
               + game.turn()
               + " "
               + getString(R.string.ghost_game_text_start2),
           Toast.LENGTH_SHORT)
       .show();
 }
 /*
  * Saves all the game data to the shared preferences.
  */
 private void saveGameState() {
   SharedPreferences.Editor editor = prefs.edit();
   editor.putString(namePlayer1Key, namePlayer1);
   editor.putString(namePlayer2Key, namePlayer2);
   editor.putString(lettersPlayer1Key, String.valueOf(lettersPlayer1.getText()));
   editor.putString(lettersPlayer2Key, String.valueOf(lettersPlayer2.getText()));
   editor.putInt(playerTurnKey, game.turn());
   editor.putString(wordFormedKey, String.valueOf(wordFormed.getText()));
   editor.putString(playerInputKey, String.valueOf(playerInput.getText()));
   editor.putBoolean(savedGameKey, true);
   editor.apply();
   Toast.makeText(getApplicationContext(), R.string.ghost_game_text_game_saved, Toast.LENGTH_SHORT)
       .show();
 }
 /*
  * Creates a Game instance (see Game.java) and uses the method 'setImageTurnAndHighlightPlayer()'
  * to:
  * 1) Set the source of the ImageView that indicates the player turn, and
  * 2) Make the name of the player whose turn it is bold.
  */
 private void createSavedGame(
     Lexicon lexicon,
     String lettersPlayer1,
     String lettersPlayer2,
     int playerTurn,
     String wordFormed) {
   game = new Game(lexicon, lettersPlayer1, lettersPlayer2, playerTurn, wordFormed);
   setImageTurnAndHighlightPlayer();
   Toast.makeText(
           getApplication(),
           getString(R.string.ghost_game_text_start1)
               + " "
               + game.turn()
               + " "
               + getString(R.string.ghost_game_text_start2),
           Toast.LENGTH_SHORT)
       .show();
 }