public void TryTransferFoodItemToOtherShop(FoodObject food) { food = new FoodObject(food); if (otherShop.point >= food.getPrice()) { buyButtonText.text = "Buy"; point += food.getPrice(); otherShop.point -= food.getPrice(); AddFoodItem(food, otherShop); RemoveFoodItem(food, this); RefreshDisplay(); otherShop.RefreshDisplay(); } }
public void Setup(FoodObject currentFood, ShopScrollList currentScrollList) { food = currentFood; nameLabel.text = food.getName(); priceLabel.text = food.getPrice().ToString(); iconImage.sprite = Resources.Load <Sprite>(food.getIcon()); scrollList = currentScrollList; if (scrollList.isPlayer) { quantityLabel.text = "x" + food.getQuantity().ToString(); } else { quantityLabel.text = ""; // blank } }
private void AddFoodItem(FoodObject foodToAdd, ShopScrollList shopList) { if (shopList.isPlayer) // if shop that we add to is the player's: { cost += foodToAdd.getPrice(); // find if foodItem exists, then increment quantity for (int i = 0; i < shopList.foodList.Count; ++i) { if (shopList.foodList[i].getName() == foodToAdd.getName()) { shopList.foodList[i].addOneQ(); return; } } // if foodItem not found in list then add it to the list with quantity 1 foodToAdd.setQuantity(1); shopList.foodList.Add(foodToAdd); } }
private void RemoveFoodItem(FoodObject foodToRemove, ShopScrollList shopList) { if (shopList.isPlayer) { cost -= foodToRemove.getPrice(); // find the foodItem in the list for (int i = shopList.foodList.Count - 1; i >= 0; --i) { if (shopList.foodList[i].getName() == foodToRemove.getName()) { // decrease quantity shopList.foodList[i].subOneQ(); if (shopList.foodList[i].getQuantity() <= 0) { // remove if quantity is 0 shopList.foodList.RemoveAt(i); } } } } }