private void PurchaseAnimal(PurchaseAnimalOptions animal, int age) { IAnimal newAnimal = CreateAnimal(animal, age); bool purchaseOk = _player.ChangeCash(-newAnimal.PurchaseCost(), true); if (!purchaseOk) { Console.WriteLine("You don't have enough money to purchase this animal"); _zoo.RemoveAtIndex(_zoo.GetCount() - 1); HoldScreen(); } }
private IAnimal CreateAnimal(PurchaseAnimalOptions animal, int age) { //See: https://docs.microsoft.com/en-us/dotnet/api/system.activator?redirectedfrom=MSDN&view=netframework-4.8 string animalString = "ZooTycoon" + "." + animal.ToString(); object[] arguments = new object[2] { age, _baseCost }; System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance("ZooTycoon", animalString, false, 0, null, arguments, null, null); IAnimal newAnimal = (IAnimal)oh.Unwrap(); _zoo.Add(newAnimal); return(newAnimal); }
private bool ChooseAnimal(int age) { PurchaseAnimalOptions selection = (PurchaseAnimalOptions)_purchaseMenu.GetUserSelection(_player) - 1; if (selection == PurchaseAnimalOptions.Return) { return(false); } else { PurchaseAnimal(selection, age); return(true); } }