Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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.");
            }
        }
Esempio n. 3
0
        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--;
        }
Esempio n. 4
0
        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--;
        }
Esempio n. 5
0
        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());
 }