Exemplo n.º 1
0
        public Animal BuyRandomAnimal(string name, AnimalsStore store)
        {
            if (!this.state.IsStoreAccessible(store))
            {
                throw new Exception("This store is not yet aviable for your level. Middle level store is aviable on level 3, " +
                                    "Premium level store is aviable on level 10");
            }
            ApplicationRepository.GetMoneyFromrUser(user, store.GetAnimalCost());
            NotifyObservers(ActionType.MoneyChanged, user.Money);
            int    randomNumber = new Random().Next(0, 3);
            Animal animal;

            if (randomNumber == 0)
            {
                animal = store.GetBird(name, user);
            }
            else if (randomNumber == 1)
            {
                animal = store.GetMammal(name, user);
            }
            else
            {
                animal = store.GetFish(name, user);
            }
            animals.Add(animal);
            CheckLevel(animals.Count);
            return(animal);
        }