private void handleItem(int option) { try { IPetItem item = player.Take(option); switch (optionSelected) { case PlayerAction.Feed: pet1.Feed(item); break; case PlayerAction.Play: pet1.Play(item); break; case PlayerAction.Medicate: pet1.Medicate(item); break; } } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Invalid Option"); } appState = AppState.Running; }
private void handleShop(int option) { IPetItem item = shop.Take(option); if (item.Price < player.Money) { player.Purchase(item); appState = AppState.Inventory; } else { Console.WriteLine("Not enough money."); } }
public void Medicate(IPetItem medicine) { if (medicine is IMedicine) { var realMedicine = (IMedicine)medicine; health += realMedicine.MedicineValue; if (health > 100) { health = 100; } } else { Console.WriteLine($"{medicine.Name} will not help."); } medicine.Uses--; }
public void Feed(IPetItem food) { if (food is IFood && food.Species == this.species) { var realFood = (IFood)food; hunger -= realFood.FoodValue; if (hunger < 0) { hunger = 0; } } else { Console.WriteLine($"{food.Name} is not edible."); } food.Uses--; }
public void Play(IPetItem toy) { if (toy is IToy) { var realToy = (IToy)toy; mood += realToy.ToyValue; energy -= 10; if (mood > 100) { mood = 100; } } else { Console.WriteLine($"{toy.Name} is not a toy."); } toy.Uses--; }
public void Purchase(IPetItem item) { Money -= item.Price; Items.Add(item.Clone()); }