Ejemplo n.º 1
0
  public void storeBitmap(Bitmap existingFile) {
    Log.d(LOGGER, "Scaling file ...");

    final int maxSize = game.getWidth() / 3;
    int outWidth;
    int outHeight;
    int inWidth = existingFile.getWidth();
    int inHeight = existingFile.getHeight();
    if (inWidth > inHeight) {
      outWidth = maxSize;
      outHeight = (inHeight * maxSize) / inWidth;
    } else {
      outHeight = maxSize;
      outWidth = (inWidth * maxSize) / inHeight;
    }
    Bitmap scaledFile = Bitmap.createScaledBitmap(existingFile, outWidth, outHeight, false);

    File destination = new File(getFilesDir(), "RandomBotImage.png");
    FileOutputStream fOut;
    try {
      fOut = new FileOutputStream(destination);
      Log.d(LOGGER, "Storing file ...");
      scaledFile.compress(Bitmap.CompressFormat.PNG, 100, fOut);
      fOut.flush();
      fOut.close();
    } catch (Exception e) {
      Log.e(LOGGER, "Exception was thrown:" + e.getMessage());
    }
    Log.d(LOGGER, "RandomBot File ready to use.");

    game.setRandomBotImage(destination.getPath(), scaledFile);
  }
Ejemplo n.º 2
0
  /*
   * This method forces the back button to behave properly.
   * It is needed to prevent a crash if the user opens up the
   * game immediately after hitting back
   */
  @Override
  public void onBackPressed() {

    if (!game.isPaused()) {
      game.pause();
    } else {
      game.resume();
    }
  }
Ejemplo n.º 3
0
  public void showThemeMenu() {
    final ThemeManager themes = game.getThemeManager();
    String[] themeMenuLabels = themes.getAvailableThemeLabels();
    Integer[] themeMenuIcons = themes.getAvailableThemeIconImageIDs();

    ListAdapter adapter =
        new ArrayAdapterWithIcons(
            this, android.R.layout.select_dialog_singlechoice, themeMenuLabels, themeMenuIcons);

    AlertDialog.Builder builder = getDialog(this);
    builder.setTitle("Themes Options");
    builder.setPositiveButton("OK", null);
    builder.setSingleChoiceItems(
        adapter,
        themes.getCurrentThemeID(),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            Log.d(LOGGER, "Theme Selected: " + item);
            if (themes.isAvailable(item)) {
              themes.setTheme(item);
            } else {
              purchaseItem(themes.getSkuForTheme(item));
            }
          }
        });
    builder.show();
  }
Ejemplo n.º 4
0
  public void showGameplayMenu() {
    final GameplayManager modes = game.getGameplayManager();
    String[] gameplayMenuLabels = modes.getLabels();
    Integer[] gameplayMenuIcons = modes.getIconImageIDs();

    ListAdapter adapter =
        new ArrayAdapterWithIcons(
            this,
            android.R.layout.select_dialog_singlechoice,
            gameplayMenuLabels,
            gameplayMenuIcons);

    AlertDialog.Builder builder = getDialog(this);
    builder.setTitle("Gameplay Options");
    builder.setPositiveButton("OK", null);
    builder.setSingleChoiceItems(
        adapter,
        modes.getCurrentID(),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            Log.d(LOGGER, "Gameplay Selected:" + item);
            modes.setGameplayMode(item);
            game.startNewGame(false);
          }
        });
    builder.show();
  }
Ejemplo n.º 5
0
 /*
  * This method handles the final phase of life: destruction
  * This game will "never" come back from this state, so we
  * just need to clear up and head home.
  */
 @Override
 protected void onDestroy() {
   Log.d(LOGGER, "Destroying the activity");
   super.onDestroy();
   game.stop();
   if (billingHelper != null) {
     billingHelper.dispose();
   }
   billingHelper = null;
 }
Ejemplo n.º 6
0
 public void purchaseRandomBot() {
   randomBotPurchased = true;
   getSharedPreferences("BOOT_PREF", MODE_PRIVATE)
       .edit()
       .putBoolean(RANDOM_BOT_KEY, true)
       .commit();
   if (game != null) {
     game.purchaseRandomBot();
   }
 }
Ejemplo n.º 7
0
 @Override
 public void onIabPurchaseFinished(IabResult result, Purchase info) {
   ThemeManager themes = game.getThemeManager();
   if (result.isFailure()) {
     Log.e(LOGGER, "Purchase failed: " + result);
     Toast.makeText(this, "In-App Purchase Failed or was cancelled.", Toast.LENGTH_LONG).show();
   } else if (RANDOM_BOT_SKU.equals(info.getSku())) {
     Log.d(LOGGER, "Purchase of RandomBot succeeded.");
     purchaseRandomBot();
   } else if (themes.purchaseTheme(info.getSku())) {
     Log.d(LOGGER, "Theme Purchased");
   }
 }
Ejemplo n.º 8
0
  public void showHighScoreMenu() {
    String[] scoreLabels = game.getGameplayManager().getHighScores();
    Integer[] gameplayMenuIcons = game.getGameplayManager().getIconImageIDs();

    ListAdapter adapter =
        new ArrayAdapterWithIcons(
            this, android.R.layout.select_dialog_item, scoreLabels, gameplayMenuIcons);

    AlertDialog.Builder builder = getDialog(this);
    builder.setTitle("High Scores");
    builder.setPositiveButton("OK", null);
    builder.setNegativeButton(
        "Clear High Scores",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            Log.d(LOGGER, "High Scores will be cleared");
            game.getGameplayManager().clearAllScores();
          }
        });
    builder.setAdapter(adapter, null);
    builder.show();
  }
Ejemplo n.º 9
0
  /*
   * Resume the game when it is ready to be visible.
   * This will be called after onCreate or after onPause
   * This message assumes that the Pause Menu was displayed
   * during the onPause process, so the user will use that to
   * resume the game.
   */
  @Override
  protected void onResume() {
    Log.d(LOGGER, "Resuming...");
    super.onResume();

    if (firstRun) {
      Log.d(LOGGER, "This is the first run of the activity");
    } else {
      Log.d(LOGGER, "This activity has run before");
    }

    // Initialize the game as needed, and set it as this activity's content
    if (game == null || game.isStopped()) {
      game = new PopAllTheThingsGame(this, firstRun, randomBotPurchased);
      firstRun = false;
      setContentView(game);
    }
  }
Ejemplo n.º 10
0
  @Override
  public void onQueryInventoryFinished(IabResult result, Inventory inv) {
    if (result.isSuccess()) {
      Log.d(LOGGER, "In app purchases query complete" + result);

      boolean randomBotPurchaseCheck = inv.hasPurchase(RANDOM_BOT_SKU);

      if (randomBotPurchaseCheck && !randomBotPurchased) {
        Log.d(LOGGER, "RandomBot Purchase Imported");
        purchaseRandomBot();
      } else if (!randomBotPurchaseCheck && randomBotPurchased) {
        Log.d(LOGGER, "RandomBot Refund Imported");
        refundRandomBot();
      }

      final ThemeManager themes = game.getThemeManager();
      themes.importPurchases(inv);
    } else {
      Log.e(LOGGER, "In app purchases could not be verified.");
    }
  }
Ejemplo n.º 11
0
  public void showPauseMenu() {

    String[] pausedMenuLabels = new String[7];
    Integer[] pausedMenuIcons = new Integer[7];

    pausedMenuLabels[0] = "GamePlay";
    pausedMenuIcons[0] = game.getGameplayManager().getCurrentIconID();

    pausedMenuLabels[1] = "Themes";
    pausedMenuIcons[1] = game.getThemeManager().getCurrentThemeIconID();

    if (randomBotPurchased) {
      pausedMenuLabels[2] = "Picture For RandomBot";
    } else {
      pausedMenuLabels[2] = "Purchase RandomBot";
    }
    pausedMenuIcons[2] = R.drawable.ic_action_action_android;

    if (game.isMute()) {
      pausedMenuLabels[3] = "Sound: Off";
      pausedMenuIcons[3] = R.drawable.ic_action_av_volume_off;
    } else {
      pausedMenuLabels[3] = "Sound: On";
      pausedMenuIcons[3] = R.drawable.ic_action_av_volume_up;
    }

    if (game.isBlackBackground()) {
      pausedMenuLabels[4] = "Background: Black";
      pausedMenuIcons[4] = R.drawable.ic_action_action_favorite;
    } else {
      pausedMenuLabels[4] = "Background: Clear";
      pausedMenuIcons[4] = R.drawable.ic_action_action_favorite_outline;
    }

    pausedMenuLabels[5] = "High Scores";
    pausedMenuIcons[5] = R.drawable.ic_action_action_grade;

    pausedMenuLabels[6] = "Credits";
    pausedMenuIcons[6] = R.drawable.ic_action_image_palette;

    ListAdapter adapter =
        new ArrayAdapterWithIcons(
            this, android.R.layout.select_dialog_item, pausedMenuLabels, pausedMenuIcons);

    AlertDialog.Builder builder = getDialog(this);
    builder.setTitle("Pause Menu");
    builder.setPositiveButton(
        "Start New Game",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            Log.d(LOGGER, "Restart Button Clicked: Starting a new game");
            game.startNewGame(true);
          }
        });
    builder.setNegativeButton(
        "Continue Game",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            Log.d(LOGGER, "Continue Button Clicked: Continuing with current game");
            game.resume();
          }
        });
    builder.setSingleChoiceItems(
        adapter,
        -1,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
              showGameplayMenu();
            } else if (item == 1) {
              showThemeMenu();
            } else if (item == 2) {
              if (randomBotPurchased) {
                showRandomBotMenu();
              } else {
                showRandomBotPurchaseMenu();
              }
            } else if (item == 3) {
              game.swapMute();
              dialog.dismiss();
              game.resume();
            } else if (item == 4) {
              game.swapBlackBackground();
              dialog.dismiss();
              game.resume();
            } else if (item == 5) {
              showHighScoreMenu();
            } else if (item == 6) {
              showCreditScreen();
              dialog.dismiss();
            }
            Log.d(LOGGER, "MenuClick Detected!, item# " + item);
          }
        });
    builder.setOnCancelListener(
        new DialogInterface.OnCancelListener() {

          @Override
          public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
            game.resume();
          }
        });
    builder.show();
  }
Ejemplo n.º 12
0
 /*
  * There are some cases when our pause/pause-menu can
  * be secretly closed.  This reveals that secret to
  * the game as an "un-pause" or resume event.
  */
 @Override
 public void onOptionsMenuClosed(Menu menu) {
   game.resume();
 }
Ejemplo n.º 13
0
 /*
  * This method handles a user pushing the "menu" button
  * available on older and awesome devices.  This game
  * has a unified pause/pause-menu behavior, so we
  * are going to delegate the work to the game for this.
  */
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   game.pause();
   return true;
 }
Ejemplo n.º 14
0
 /*
  * Pause the game if it is not visible for any reason
  * This is called before onStop, and nothing extra needs done in onStop.
  */
 @Override
 protected void onPause() {
   Log.d(LOGGER, "Pausing Activity");
   game.pause();
   super.onPause();
 }