/* * * * Buying items * * * */ ///<summary>Updates gold amount and relevant item count as appropriate. Also updates expiration date if applicable.</summary> public static bool buyItem(int id) { StoreItem item = STORE_ITEMS[id]; string key = item.getKey(); int numBought = DataAndSettingsManager.getNumBoughtForStoreItem(key); int gold = DataAndSettingsManager.getGoldAmount(); if (gold >= item.getCost() && (id < getNumExpendables() || numBought < 1)) { DataAndSettingsManager.setNumBoughtForStoreItem(key, numBought + 1); DataAndSettingsManager.setGoldAmount(gold -= item.getCost()); if (item.hasLifespan()) { DateTime expiration = DataAndSettingsManager.getExpirationDateForStoreItem(key); DateTime now = DateTime.Now; TimeSpan lifespan = new TimeSpan(item.getLifespanHours(), 0, 0); if (expiration.CompareTo(now) < 0) { // the item has already expired, so set a new expiration date DataAndSettingsManager.setExpirationDateForStoreItem(key, now.Add(lifespan)); } else { // the item hasn't expired yet, so advance the expiration date further DataAndSettingsManager.setExpirationDateForStoreItem(key, expiration.Add(lifespan)); } //Debug.Log("expiration date was " + expiration.ToString()); } return(true); } return(false); }
///<summary>Called when Unity IAP successfully makes a purchase with the appropriate store.</summary> public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) { bool validPurchase = true; string purchasedProductID = args.purchasedProduct.definition.id; #if UNITY_IOS || UNITY_ANDROID validPurchase = validateReceipt(args.purchasedProduct.receipt, purchasedProductID); #endif if (validPurchase) { if (purchasedProductID.Equals(PRODUCT_ID_100_GOLD)) { int gold = DataAndSettingsManager.getGoldAmount(); DataAndSettingsManager.setGoldAmount(gold + 100); storeMenu.updateGoldLabel(); } else { #if UNITY_IOS // update our copy of the unified iOS receipt appReceipt = args.purchasedProduct.receipt; // should already be formatted for Unity #endif } FindObjectOfType <AlertPrompt>().showMessage("Purchase succeeded!"); } else { FindObjectOfType <AlertPrompt>().showMessage("Purchase failed validation."); } return(PurchaseProcessingResult.Complete); }
///<summary>Updates the statistics display.</summary> private void updateStatsMenu() { this.statsGoldLabel.text = "" + DataAndSettingsManager.getGoldAmount(); this.statsHighscoreLabel.text = "Highscore: " + DataAndSettingsManager.getHighscore(); this.statsAverageLabel.text = "Average: " + DataAndSettingsManager.getAverageScore().ToString("F2"); // 2 decimal places this.statsGamesPlayedLabel.text = "Games Played: " + DataAndSettingsManager.getGamesPlayed(); this.showResetAverageButtonIfNecessary(); }
///<summary>Removes gold and bads, updates gold amount, and restarts the game.</summary> public void reviveGame() { //Debug.Log("revive game"); this.removeGold(); foreach (Cube bad in this.bads) { this.removeBad(bad); } this.goldAmount = DataAndSettingsManager.getGoldAmount(); this.updateGoldLabel(); this.isReviving = true; this.actuallyStartGameAction(); this.isReviving = false; }
/* * * * Game pathway steps * * * */ ///<summary>Initializes objects, the game space array, and counters, flags, and labels.</summary> private void setupGame() { //Debug.Log("setup game"); this.destroyObjects(); this.initializeObjects(); this.space = new int[SIZE, SIZE, SIZE]; this.space[2, 2, 2] = SPACE_SNAKE; this.space[3, 2, 2] = SPACE_SNAKE; this.space[4, 2, 2] = SPACE_SNAKE; this.score = 0; this.applesCollected = 0; this.goldAmount = DataAndSettingsManager.getGoldAmount(); this.isHardMode = DataAndSettingsManager.getHardModeState(); this.isPaused = false; this.generateApple(); this.updateScoreLabel(); this.updateGoldLabel(); DataAndSettingsManager.updateColorblindModeListeners(); }
/* * * * Public methods * * * */ public void updateGoldLabel() { this.goldLabel.text = "" + DataAndSettingsManager.getGoldAmount(); }