private void performMove(Coordinates touchCoordinates) {
   end = !game.move(touchCoordinates);
   GameCanvas.this.invalidate();
   Toast.makeText(
           parent,
           String.format(parent.getString(R.string.game_screen_turn), game.getTurn()),
           Toast.LENGTH_SHORT)
       .show();
 }
  private void checkGameState() {
    if (end) {
      if (musicEnabled) {
        parent.stopService(new Intent(parent, BackgroundMusic.class));
      }

      Leaderboard leaderboard = Leaderboard.load(parent);
      String name = parent.getIntent().getExtras().getString("name");

      switch (difficulty) {
        case EASY:
          leaderboard.addEasyRecord(name, game.getTurn());
          break;

        case NORMAL:
          leaderboard.addNormalRecord(name, game.getTurn());
          break;

        case HARD:
          leaderboard.addHardRecord(name, game.getTurn());
      }

      leaderboard.save(parent);

      new AlertDialog.Builder(parent)
          .setMessage(parent.getString(R.string.game_screen_game_over))
          .setPositiveButton(
              parent.getString(R.string.game_screen_button_return),
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                  SharedPreferences settings =
                      PreferenceManager.getDefaultSharedPreferences(parent);
                  boolean soundEnabled = settings.getBoolean("pref_enable_sound", true);

                  if (soundEnabled) {
                    MediaPlayer player = MediaPlayer.create(parent, R.raw.press);
                    player.setLooping(false);
                    player.start();
                  }

                  parent.finish();
                  parent.overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
                }
              })
          .setNegativeButton(
              parent.getString(R.string.game_screen_button_restart),
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                  SharedPreferences settings =
                      PreferenceManager.getDefaultSharedPreferences(parent);
                  boolean soundEnabled = settings.getBoolean("pref_enable_sound", true);

                  if (soundEnabled) {
                    MediaPlayer player = MediaPlayer.create(parent, R.raw.press);
                    player.setLooping(false);
                    player.start();
                  }

                  game = new Game(difficulty);

                  if (musicEnabled) {
                    parent.startService(new Intent(parent, BackgroundMusic.class));
                  }

                  invalidate();
                }
              })
          .show();
    }
  }