예제 #1
0
        public void Run()
        {
            var points = 0;
            var input  = Console.ReadLine().Split();

            for (int i = 0; i < input.Length; i++)
            {
                var type = input[i];

                var currentFood = foodFactory.CreateFood(type);
                points += currentFood.Happiness;
            }

            Mood mood;

            if (points < -5)
            {
                mood = moodFactory.CreateMood("angry");
            }
            else if (points >= -5 && points < 0)
            {
                mood = moodFactory.CreateMood("sad");
            }
            else if (points >= 1 && points < 15)
            {
                mood = moodFactory.CreateMood("happy");
            }
            else
            {
                mood = moodFactory.CreateMood("javascript");
            }

            Console.WriteLine(points);
            Console.WriteLine(mood.Name);
        }
예제 #2
0
        public void Run()
        {
            int points = 0;

            string[] input = Console.ReadLine().Split();
            foreach (var type in input)
            {
                Food currentFood = foodFactory.CreateFood(type);
                points += currentFood.Happiness;
            }

            Mood mood;

            if (points < -5)
            {
                mood = moodFactory.CreateMood("angry");
            }
            else if (points <= 0)
            {
                mood = moodFactory.CreateMood("sad");
            }
            else if (points <= 15)
            {
                mood = moodFactory.CreateMood("happy");
            }
            else
            {
                mood = moodFactory.CreateMood("javascript");
            }

            Console.WriteLine(points);
            Console.WriteLine(mood.Type);
        }
예제 #3
0
        static void Main()
        {
            string input = Console.ReadLine();
            AnimalFactory animalFactory=new AnimalFactory();
            FoodFactory foodFactory=new FoodFactory();
            Animal.Animal a;
            Food.Food food;
            while (!input.Equals("End"))
            {
                string[] animalInput = input.Split(' ');
                if (animalInput.Length == 4)
                {
                    a = animalFactory.CreateAnimal(animalInput[0], animalInput[1], double.Parse(animalInput[2]),
                        animalInput[3]);
                }
                else
                {
                    a = animalFactory.CreateAnimal(animalInput[0], animalInput[1], double.Parse(animalInput[2]),
                        animalInput[3],animalInput[4]);
                }

                string[] foodInput = Console.ReadLine().Split(' ');

                food = foodFactory.CreateFood(foodInput[0], int.Parse(foodInput[1]));

                a.MakeNoise();
                a.EatFood(food);
                Console.WriteLine(a);
                input = Console.ReadLine();
            }
        }
예제 #4
0
        public void Run()
        {
            string        input         = string.Empty;
            List <Animal> listOfAnimals = new List <Animal>();

            while ((input = Console.ReadLine()) != "E")
            {
                string[] animalData = input.Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                      .ToArray();
                string[] foodData = Console.ReadLine()
                                    .Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();

                Animal animal = AnimalFactory.CreateAnimal(animalData);
                listOfAnimals.Add(animal);
                Food food = FoodFactory.CreateFood(foodData);
                Console.WriteLine(animal.ProduceSound());
                try
                {
                    animal.Eat(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
            }
            listOfAnimals.ForEach(Console.WriteLine);
        }
예제 #5
0
파일: Engine.cs 프로젝트: EmORz/OOP-Basic
        public void Run()
        {
            int happinessPoints = 0;

            string[] input = Console.ReadLine().Split();
            for (int i = 0; i < input.Length; i++)
            {
                string type        = input[i];
                Food   currentFood = foodFactory.CreateFood(type);
                happinessPoints += currentFood.Happiness;
            }
            MoodsS moods;

            if (happinessPoints < -5)
            {
                moods = moodFactory.CreateMoods("angry");
            }
            else if (happinessPoints >= -5 && happinessPoints <= 0)
            {
                moods = moodFactory.CreateMoods("sad");
            }
            else if (happinessPoints >= 1 && happinessPoints < 15)
            {
                moods = moodFactory.CreateMoods("happy");
            }
            else
            {
                moods = moodFactory.CreateMoods("javascript");
            }
            Console.WriteLine(happinessPoints);
            Console.WriteLine(moods.Name);
        }
예제 #6
0
        public void Run()
        {
            string[] input = Console.ReadLine()
                             .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < input.Length; i++)
            {
                string type = input[i];
                Food   food = foodFactory.CreateFood(type);
                foods.Add(food);
            }

            int points = foods.Sum(x => x.Happiness);

            Mood mood;

            if (points < -5)
            {
                mood = moodFactory.CreateMood("angry");
            }
            else if (points >= -5 && points < 0)
            {
                mood = moodFactory.CreateMood("sad");
            }
            else if (points > 0 && points < 15)
            {
                mood = moodFactory.CreateMood("happy");
            }
            else
            {
                mood = moodFactory.CreateMood("javascript");
            }
            Console.WriteLine(points);
            Console.WriteLine(mood.GetType().Name);
        }
예제 #7
0
        public void Run()
        {
            string[] eatenFood = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            int      points    = 0;

            foreach (var foodType in eatenFood)
            {
                Food currentFood = FoodFactory.CreateFood(foodType);
                points += currentFood.Happiness;
            }

            string mood = "";

            if (points < -5)
            {
                mood = "Angry";
            }
            else if (points <= 0)
            {
                mood = "Sad";
            }
            else if (points <= 15)
            {
                mood = "Happy";
            }
            else
            {
                mood = "JavaScript";
            }

            Console.WriteLine(points);
            Console.WriteLine(mood);
        }
예제 #8
0
        static void Main()
        {
            List <Animal> animals = new List <Animal>();

            string input;

            while ((input = Console.ReadLine()) != "End")

            {
                Animal animal = AnimalFactory.CreateAnimal(input.Split(' '));
                animals.Add(animal);
                Console.WriteLine(animal.Sound());
                Food food = FoodFactory.CreateFood(Console.ReadLine().Split(" "));

                try
                {
                    animal.EatFood(food);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            animals.ForEach(Console.WriteLine);
        }
예제 #9
0
    /// <summary> Creates a random object of the given type in a random position. </summary>
    /// <param name="objectType"> The type of the object to create. </param>
    /// <returns> The created Game Object. </returns>
    private GameObject CreateRandomObject(ObjectType objectType)
    {
        Vector2 position = GetRandomPosition();

        switch (objectType)
        {
        case ObjectType.StandardApple:
        case ObjectType.GoldenApple:
        case ObjectType.StandardCarrot:
        case ObjectType.GoldenCarrot:
            return(foodFactory.CreateFood(objectType, position));

        case ObjectType.Life:
            return(lifeFactory.CreateLife(position));

        case ObjectType.Cactus:
            return(trapFactory.CreateCactus(position));

        case ObjectType.EnergyCapsule:
            return(energyCapsuleFactory.CrateEnergyCapsule(position));

        case ObjectType.Rock:
            return(rockFactory.CreateRock(position));

        default:
            return(null);
        }
    }
예제 #10
0
    public static void Main()
    {
        string        input         = Console.ReadLine();
        AnimalFactory animalFactory = new AnimalFactory();
        FoodFactory   foodFactory   = new FoodFactory();
        Animal        a;
        Food          food;

        while (!input.Equals("End"))
        {
            string[] animalInput = input.Split(' ');
            if (animalInput.Length == 4)
            {
                a = animalFactory.CreateAnimal(animalInput[0], animalInput[1], double.Parse(animalInput[2]),
                                               animalInput[3]);
            }
            else
            {
                a = animalFactory.CreateAnimal(animalInput[0], animalInput[1], double.Parse(animalInput[2]),
                                               animalInput[3], animalInput[4]);
            }

            string[] foodInput = Console.ReadLine().Split(' ');

            food = foodFactory.CreateFood(foodInput[0], int.Parse(foodInput[1]));

            a.MakeNoise();
            a.EatFood(food);
            Console.WriteLine(a);
            input = Console.ReadLine();
        }
    }
예제 #11
0
 private void foodList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (foodList.Text != "Bread")
     {
         currentFood = FoodFactory.CreateFood(foodList.Text) as Food;
     }
 }
    public static void Main()
    {
        // Split by whitespace
        string[] foodNames = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries);

        List <Food> foods = new List <Food>();

        foreach (string foodName in foodNames)
        {
            char[] currentFoodName = foodName.ToLower().ToCharArray();
            currentFoodName[0] = char.ToUpper(currentFoodName[0]);

            foods.Add(FoodFactory.CreateFood(new string(currentFoodName)));
        }

        int happinessLevel = 0;

        foreach (Food food in foods)
        {
            happinessLevel += food.Happiness;
        }

        Console.WriteLine(happinessLevel);
        Console.WriteLine(MoodFactory.CreateMood(happinessLevel));
    }
예제 #13
0
        public string AddFood(string type, string name, decimal price)
        {
            IBakedFood food = foodFactory.CreateFood(type, name, price);

            bakedFoods.Add(food);
            return($"Added {food.Name} ({food.GetType().Name}) to the menu");
        }
예제 #14
0
    private void CookFood(FoodType type)
    {
        Food food = FoodFactory.CreateFood(type);

        if (food != null)
        {
            food.PrintFoodName();
        }
    }
예제 #15
0
        public void Run()
        {
            //• Felines - "{Type} {Name} {Weight} {LivingRegion} {Breed}";
            //• Birds - "{Type} {Name} {Weight} {WingSize}";
            //• Mice and Dogs - "{Type} {Name} {Weight} {LivingRegion}";

            string input = Console.ReadLine();

            while (input != "End")
            {
                try
                {
                    string[] animalInfo = input.Split();
                    string[] foodInfo   = Console.ReadLine().Split();
                    string   type       = animalInfo[0];
                    string   name       = animalInfo[1];
                    double   weigth     = double.Parse(animalInfo[2]);


                    if (type == "Hen" || type == "Owl")
                    {
                        double wingSize = double.Parse(animalInfo[3]);
                        animal = this.birdFactory.CreateBirds(type, name, weigth, wingSize);
                    }
                    else if (type == "Mouse" || type == "Dog")
                    {
                        string livingRegion = animalInfo[3];
                        animal = this.mammalFactory.CreateMammal(type, name, weigth, livingRegion);
                    }
                    else if (type == "Cat" || type == "Tiger")
                    {
                        string livingRegion = animalInfo[3];
                        string breed        = animalInfo[4];
                        animal = this.felineFactory.CreateFeline(type, name, weigth, livingRegion, breed);
                    }
                    var food = foodFactory.CreateFood(foodInfo[0], int.Parse(foodInfo[1]));

                    animals.Add(animal);
                    animal.AskForFood();
                    animal.Eat(food);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }



                input = Console.ReadLine();
            }


            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
예제 #16
0
        public void Run()
        {
            string input;
            var    countLines = 0;

            while ((input = Console.ReadLine()) != "End")
            {
                try
                {
                    if (countLines % 2 == 0)
                    {
                        try
                        {
                            var animalInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
                            animal = animalFactory.CreateAnimal(animalInfo);
                            countLines++;
                            continue;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            var foodInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
                            food = foodFactory.CreateFood(foodInfo);
                            countLines++;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    try
                    {
                        Console.WriteLine(animal.ProduceSound());
                        animal.Eat(food);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    animals.Add(animal);
                }
                catch (Exception)
                {
                    throw;
                }
            }

            animals.ForEach(a => Console.WriteLine(a));
        }
예제 #17
0
 private void UpdateCurrentFood()
 {
     if (string.IsNullOrEmpty(foodList.Text))
     {
         this.currentFood = FoodFactory.CreateFood("Bread");
     }
     else
     {
         this.currentFood = FoodFactory.CreateFood(foodList.Text) as Food;
     }
 }
예제 #18
0
        public void Run()
        {
            Animal animal = null;
            Food   food   = null;

            int count = 0;


            string input = Console.ReadLine();

            while (input != "End")
            {
                var command = input.Split().ToArray();

                string type = command[0];


                if (count % 2 == 0)
                {
                    string name   = command[1];
                    double weight = double.Parse(command[2]);
                    try
                    {
                        animal = animalFactory.Create(name, type, weight, command);

                        Console.WriteLine(animal.ProduceSound());
                        animals.Add(animal);
                    }
                    catch (InvalidOperationException ioe)
                    {
                        Console.WriteLine(ioe.Message);
                    }
                }
                else
                {
                    int quantity = int.Parse(command[1]);
                    try
                    {
                        food = foodFactory.CreateFood(type, quantity);
                        animal.Feed(food);
                    }
                    catch (InvalidOperationException ioe)
                    {
                        Console.WriteLine(ioe.Message);
                    }
                }

                count++;
                input = Console.ReadLine();
            }

            PrintAnimalsInfo();
        }
예제 #19
0
 public void Test()
 {
     food = FoodFactory.CreateFood(FoodType.Apple);
     if (food != null)
     {
         food.Excute();
     }
     food = FoodFactory.CreateFood(FoodType.StrawberryFood);
     if (food != null)
     {
         food.Excute();
     }
 }
예제 #20
0
    public static void Main()
    {
        var wizard = new Wizard();
        var tokens = Console.ReadLine().Split();

        foreach (var item in tokens)
        {
            Food food = FoodFactory.CreateFood(item);
            wizard.Eat(food);
        }

        Console.WriteLine(wizard);
    }
예제 #21
0
    static void Main(string[] args)
    {
        FoodFactory ff        = new FoodFactory();
        var         foodInput = Console.ReadLine()
                                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                .Select(f => f.ToLower())
                                .ToList();

        List <Food> foods = foodInput.Select(f => ff.CreateFood(f)).ToList();

        GandalfTheGray gray = new GandalfTheGray(foods);

        Console.WriteLine(gray);
    }
        static void Main(string[] args)
        {
            var foodInput   = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var gandalf     = new Gandalf();
            var foodFactory = new FoodFactory();

            foreach (var tyoeOfFood in foodInput)
            {
                var food = foodFactory.CreateFood(tyoeOfFood);
                gandalf.Eat(food);
            }

            Console.WriteLine(gandalf);
        }
예제 #23
0
        public void Run()
        {
            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] animalInfo = input.Split();

                string animalType   = animalInfo[0];
                string animalName   = animalInfo[1];
                double animalWeight = double.Parse(animalInfo[2]);



                if (animalType == "Hen" || animalType == "Owl")
                {
                    double wingSize = double.Parse(animalInfo[3]);

                    animal = birdFactory.CreateBird(animalType, animalName, animalWeight, wingSize);
                }
                else if (animalType == "Dog" || animalType == "Mouse")
                {
                    string livingregion = animalInfo[3];
                    animal = mammalFactory.CreateMammal(animalType, animalName, animalWeight, livingregion);
                }
                else if (animalType == "Cat" || animalType == "Tiger")
                {
                    string livingregion = animalInfo[3];
                    string breed        = animalInfo[4];

                    animal = felineFactory.CreateFeline(animalType, animalName, animalWeight, livingregion, breed);
                }

                string[] foodInfo     = Console.ReadLine().Split();
                string   foodType     = foodInfo[0];
                int      foodQuantity = int.Parse(foodInfo[1]);

                Food food = foodFactory.CreateFood(foodType, foodQuantity);

                animal.ProduceSound();
                animal.Eat(food);
                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
        public void Run()
        {
            string        input            = Console.ReadLine();
            int           inputLineCounter = default;
            List <Animal> animals          = new List <Animal>();
            AnimalFactory animalFactory    = new AnimalFactory();
            FoodFactory   foodFactory      = new FoodFactory();

            while (input != "End")
            {
                if (inputLineCounter % 2 == 0)
                {
                    string[] cmdArgs   = input.Split(' ', '-', StringSplitOptions.RemoveEmptyEntries);
                    Animal   newAnimal = animalFactory.CreateAnimal(cmdArgs);
                    Console.WriteLine(newAnimal.AskForFood());
                    animals.Add(newAnimal);
                }
                else
                {
                    string[] cmdArgs          = input.Split(' ', '-', StringSplitOptions.RemoveEmptyEntries);
                    Food     newFood          = foodFactory.CreateFood(cmdArgs);
                    string   animalType       = animals[animals.Count - 1].GetType().Name;
                    string   foodType         = newFood.GetType().Name;
                    bool     isNewFoodEatable = CheckIfFoodIsEatable(animalType, foodType);

                    if (!isNewFoodEatable)
                    {
                        Console.WriteLine(String.Format(Messages.DOES_NOT_EAT_THIS_TYPE_OF_FOOD,
                                                        animalType, foodType));
                    }
                    else
                    {
                        Animal animal            = animals[animals.Count - 1];
                        double totalWeightGained = animal.WeightGain * newFood.Quantity;
                        animal.Weight    += totalWeightGained;
                        animal.FoodEaten += newFood.Quantity;
                    }
                }

                inputLineCounter++;

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal);
            }
        }
예제 #25
0
파일: Startup.cs 프로젝트: nayots/SoftUni
        private static void Main(string[] args)
        {
            var foodNames = Console.ReadLine().ToLower().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            List <Food> foods = new List <Food>();

            var ff = new FoodFactory();

            foreach (var name in foodNames)
            {
                foods.Add(ff.CreateFood(name));
            }

            Gandalf gandalf = new Gandalf(foods);

            Console.WriteLine(gandalf.ToString());
        }
예제 #26
0
    static void Main(string[] args)
    {
        Gandalf gandalf     = new Gandalf();
        var     foodFactory = new FoodFactory();
        var     input       = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

        foreach (var f in input)
        {
            var food = foodFactory.CreateFood(f);
            gandalf.Eat(food);
        }

        MoodFactory mood = new MoodFactory();

        Console.WriteLine(gandalf.TotalPoints);
        Console.WriteLine(mood.CreateMood(gandalf.TotalPoints).Name);
    }
예제 #27
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (input != "End")
            {
                string[] animalArguments = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   typeAnimal      = animalArguments[0].ToLower();
                string   name            = animalArguments[1];
                double   weight          = double.Parse(animalArguments[2]);

                if (typeAnimal == "hen" || typeAnimal == "owl")
                {
                    double wingSize = double.Parse(animalArguments[3]);
                    animal = birdFactory.CreateBird(typeAnimal, name, weight, wingSize);
                }
                else if (typeAnimal == "mouse" || typeAnimal == "dog")
                {
                    string livingRegion = animalArguments[3];
                    animal = mammalFactory.CreateMammal(typeAnimal, name, weight, livingRegion);
                }
                else if (typeAnimal == "cat" || typeAnimal == "tiger")
                {
                    string livingRegion = animalArguments[3];
                    string breed        = animalArguments[4];
                    animal = felineFactory.CreateFeline(typeAnimal, name, weight, livingRegion, breed);
                }

                animal.ProduceSound();
                string[] foodArguments = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   typeFood      = foodArguments[0];
                int      quantity      = int.Parse(foodArguments[1]);
                var      food          = foodFactory.CreateFood(typeFood, quantity);

                animal.Eat(food);
                this.animals.Add(animal);

                input = Console.ReadLine();
            }

            foreach (var animal in animals)
            {
                Console.WriteLine(animal.ToString());
            }
        }
예제 #28
0
        public void Run()
        {
            foods = new List <Food>();

            string[] data = Console.ReadLine().ToLower().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string name in data)
            {
                Food food = FoodFactory.CreateFood(name);
                foods.Add(food);
            }

            int happiness = CalculateHappiness();

            mood = MoodFactory.CreateMood(happiness);

            Print();
        }
예제 #29
0
    public static void Main()
    {
        string[] foodsNames = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();

        List <Food> foods = new List <Food>();

        for (int i = 0; i < foodsNames.Length; i++)
        {
            Food food = FoodFactory.CreateFood(foodsNames[i].ToLower());
            foods.Add(food);
        }

        Mood mood = MoodFactory.CreateMood(foods);

        Gandalf gandalf = new Gandalf(foods, mood);

        Console.WriteLine(gandalf);
    }
예제 #30
0
        public void Run()
        {
            string[] input = Console.ReadLine().Split();

            for (int i = 0; i < input.Length; i++)
            {
                string type = input[i];

                Food food = foodFactory.CreateFood(type);
                foods.Add(food);
            }

            int  totalHappiness = CalculateHappiness();
            Mood mood           = moodFactory.DetermineMood(totalHappiness);

            Console.WriteLine(totalHappiness);
            Console.WriteLine(mood.Name);
        }
예제 #31
0
    public static void Main()
    {
        var gandalf     = new Gandalf();
        var foodFactory = new FoodFactory();

        Console.ReadLine()
        .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
        .ToList()
        .ForEach(f =>
        {
            var food = foodFactory.CreateFood(f);
            gandalf.Eat(food);
        });

        Console.WriteLine(gandalf.TotalPointsOfHappiness);

        MoodFactory moodFactory = new MoodFactory();

        Console.WriteLine(moodFactory.CreateMood(gandalf.TotalPointsOfHappiness).Name);
    }