public void Update() { foreach (IBuilding building in BuildingList) { Henhouse item = building as Henhouse; item?.Update(); // "?" = check for null } }
public static void UpgradeHenhouseRack <TRackType>(Henhouse henhouse) where TRackType : IRack { IRack upgradedRack = henhouse?.Racks.Find(rack => rack is TRackType) ?? throw new ArgumentNullException("Rack is null", nameof(upgradedRack)); if (CtxFarm.Money >= upgradedRack.UpgrageCost) { CtxFarm.Money -= upgradedRack.UpgrageCost; henhouse.UpgradeRack <TRackType>(); } }
public static void BuyRack <TRackType>(Henhouse henhouse) where TRackType : IRack { if (typeof(VegetableRack).IsAssignableFrom(typeof(TRackType)) && CtxFarm.Money > FarmOptions.DefaultVegetableRackPrice) { henhouse.Racks.Add(new VegetableRack(henhouse)); } else if (typeof(MeatRack).IsAssignableFrom(typeof(TRackType)) && CtxFarm.Money > FarmOptions.DefaultMeatRackPrice) { henhouse.Racks.Add(new MeatRack(henhouse)); } }
internal void Die() { CtxHenhouse = null; }
public Chicken(Henhouse ctxHenhouse, Breed chikenBreed) { CtxHenhouse = ctxHenhouse ?? throw new ArgumentNullException(nameof(ctxHenhouse)); ChikenBreed = chikenBreed; Hunger = 100; }