Beispiel #1
0
        /// <summary>
        /// Gives back the type of foods what we add to input.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public override BindableCollection <Food> GetFoodsByType(string t)
        {
            BindableCollection <Food> doughs = new BindableCollection <Food>();
            MySqlCommand command             = new MySqlCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText = "select id,name,description,price from foods where type = @t";

            MySqlParameter typeparameter = new MySqlParameter()
            {
                Value         = t,
                ParameterName = "t",
                MySqlDbType   = MySqlDbType.String
            };

            command.Parameters.Add(typeparameter);

            lock (lockobj) {
                MySqlConnection connection = getConnection();


                try
                {
                    FoodFactory foodFactory = new FoodFactory();
                    command.Connection = connection;
                    OpenConnection(connection);
                    MySqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        int    id          = int.Parse(reader["id"].ToString());
                        string name        = reader["name"].ToString();
                        string description = reader["description"].ToString();
                        double price       = double.Parse(reader["price"].ToString());
                        Food   food        = foodFactory.GetFood(t);
                        food.Id          = id;
                        food.Name        = name;
                        food.Description = description;
                        food.Price       = price;
                        doughs.Add(food);
                    }
                }

                catch (Exception e)
                {
                    var logger = LogHelper.getInstance();
                    logger.Log(Logging.LogType.DbLog, this.GetType().ToString(), "GetFoodsByType", e.Message);
                }
                finally
                {
                    CloseConnection(connection);
                }
            }
            return(doughs);
        }
    public static void Main()
    {
        var player = new Player();

        player.Eat(Console.ReadLine()
                   .Split()
                   .Where(fn => fn != string.Empty)
                   .Select(fn => FoodFactory.GetFood(fn)));

        Console.WriteLine(player);
    }
Beispiel #3
0
    public static void Main()
    {
        var player    = new Player();
        var inputFood = Console.ReadLine()
                        .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                        .Where(pf => pf != string.Empty)
                        .Select(pf => FoodFactory.GetFood(pf));

        player.Eat(inputFood);

        Console.WriteLine(player);
    }
Beispiel #4
0
        static void Main(string[] args)
        {
            var eatenFoods = Console.ReadLine().Split();
            var gandalf    = new Gandalf();

            foreach (var food in eatenFoods)
            {
                gandalf.EatFood(FoodFactory.GetFood(food));
            }

            Console.WriteLine(gandalf);
        }
Beispiel #5
0
    public static void Main(string[] args)
    {
        var collection       = Console.ReadLine().Split();
        var pointsOfHapyness = 0;

        foreach (var item in collection)
        {
            pointsOfHapyness += FoodFactory.GetFood(item.ToLower());
        }

        Console.WriteLine(pointsOfHapyness);
        Console.WriteLine(MoodFactory.GetMode(pointsOfHapyness));
    }
Beispiel #6
0
        public void GetFoodByNull()
        {
            FoodFactory target = new FoodFactory();

            Exception actual = null;

            try
            {
                Food food = target.GetFood(null);
            }
            catch (NullReferenceException e) {
                actual = e;
            }
            Assert.IsNotNull(actual);
        }
Beispiel #7
0
    private static void ReadAndParseInput(List <Animal> animals, List <Food> foods)
    {
        string input = Console.ReadLine();

        while (input != "End")
        {
            string[] animalParts = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string[] foodParts   = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            Animal animal = AnimalFactory.GetAnimal(animalParts);
            Food   food   = FoodFactory.GetFood(foodParts);
            animals.Add(animal);
            foods.Add(food);
            input = Console.ReadLine();
        }
    }
Beispiel #8
0
        public void GetFoodByInvalidLength()
        {
            FoodFactory target = new FoodFactory();

            Exception actual = null;

            try
            {
                Food food = target.GetFood("3214143213123123213133");
            }
            catch (InvalidLegthExceptionForFood e)
            {
                actual = e;
            }
            Assert.IsNotNull(actual);
        }
Beispiel #9
0
    public static void Main()
    {
        List <Food> foods = new List <Food>();

        string[] inputParts = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string foodName in inputParts)
        {
            Food food = FoodFactory.GetFood(foodName);
            foods.Add(food);
        }

        Mood mood = MoodFactory.GetMood(foods);

        Console.WriteLine(foods.Sum(f => f.PointsOfHappiness));
        Console.WriteLine(mood);
    }
Beispiel #10
0
    public static void Main()
    {
        List <Animal> animals       = new List <Animal>();
        Animal        currentAnimal = null;

        int    lineCount = 0;
        string line      = Console.ReadLine();

        while (line != "End")
        {
            if (lineCount == 0 || lineCount % 2 == 0)
            {
                string[] animalInfo = line.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();

                Animal animal = AnimalFactory.GetAnimal(animalInfo[0], animalInfo.Skip(1).ToArray());
                Console.WriteLine(animal.ProduceSound());

                animals.Add(animal);
                currentAnimal = animal;
            }
            else
            {
                string[] foodInfo = line.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();

                Food food = FoodFactory.GetFood(foodInfo[0], int.Parse(foodInfo[1]));

                try
                {
                    currentAnimal.Eat(food);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            line = Console.ReadLine();
            lineCount++;
        }

        foreach (var animal in animals)
        {
            Console.WriteLine(animal);
        }
    }
Beispiel #11
0
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

        int tottalPointsOfHappiness = 0;

        foreach (var item in input)
        {
            FoodFactory foodFactory = new FoodFactory();
            Food        currentFood = foodFactory.GetFood(item);
            tottalPointsOfHappiness += currentFood.PointsOfHappines;
        }

        MoodFactory moodFactory = new MoodFactory();

        Console.WriteLine(tottalPointsOfHappiness);
        Console.WriteLine(moodFactory.GetMood(tottalPointsOfHappiness));
    }
Beispiel #12
0
    public static void Main()
    {
        List <Food> foodList = new List <Food>();

        string[] line = Console.ReadLine().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
        foreach (var food in line)
        {
            Food currFood = FoodFactory.GetFood(food.ToLower());
            foodList.Add(currFood);
        }

        Mood mood = MoodFactory.GetMood(foodList);

        int allPoints = foodList.Sum(x => x.HappinessPoints);

        Console.WriteLine(allPoints);
        Console.WriteLine(mood);
    }
Beispiel #13
0
        static void Main()
        {
            string input = System.Console.ReadLine();

            string[] args = input.Split();

            int happinesPoints = 0;

            foreach (var item in args)
            {
                var food = FoodFactory.GetFood(item);
                happinesPoints += food.HappinessPoints;
            }

            var mood = MoodFactory.GetMood(happinesPoints);

            System.Console.WriteLine(happinesPoints);
            System.Console.WriteLine(mood.MoodStatus);
        }
Beispiel #14
0
    private static void Main()
    {
        List <string> foodsInput = Console.ReadLine()
                                   .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                   .ToList();
        List <Food> foods = new List <Food>();

        foreach (var food in foodsInput)
        {
            Food current = FoodFactory.GetFood(food);
            foods.Add(current);
        }

        int  gandalfPoints = MoodFactory.Happiness(foods);
        Mood mood          = MoodFactory.GetMood(gandalfPoints);

        Console.WriteLine(gandalfPoints);
        Console.WriteLine(mood);
    }
Beispiel #15
0
        public void Run()
        {
            string input;

            while ((input = reader.ReadLine()) != END_INPUT)
            {
                string[] argsAnimal = input.Split(" ");
                string[] argsFood   = reader.ReadLine().Split(" ");
                Food     food       = foodFactory.GetFood(argsFood);
                Animal   animal     = animalFactory.GetAnimal(argsAnimal);
                writer.WriteLine(animal.ProduceSound());
                animal.Eat(food);
                animals.Add(animal);
            }

            foreach (var animal in animals)
            {
                writer.WriteLine(animal.ToString());
            }
        }
        public static void Main()
        {
            var foodFactory = new FoodFactory();
            var moodFactory = new MoodFactory();

            var inputFood = Console.ReadLine().Split(new[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            var gandalf = new Gandalf();

            foreach (var food in inputFood)
            {
                gandalf.Eat(foodFactory.GetFood(food));
            }

            var hapiness    = gandalf.GetHappinessPoints();
            var currentMood = moodFactory.GetMood(hapiness);

            Console.WriteLine(hapiness);
            Console.WriteLine(currentMood);
        }
Beispiel #17
0
        public static void Main()
        {
            var foodFactory = new FoodFactory();
            var moodFactory = new MoodFactory();

            var inputFoods = Console.ReadLine()
                             .Split(new char[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            var gandi = new Gandalf();

            foreach (var foodstring in inputFoods)
            {
                var food = foodFactory.GetFood(foodstring);
                gandi.Eat(food);
            }
            var totalhappines = gandi.GetHappinessPoints();
            var mood          = moodFactory.GetMood(totalhappines);

            Console.WriteLine(totalhappines);
            Console.WriteLine(mood);
        }
Beispiel #18
0
    public static void Main()
    {
        string[] foodsInput = Console.ReadLine()
                              .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

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

        foreach (string foodInput in foodsInput)
        {
            Food food = FoodFactory.GetFood(foodInput);
            foods.Add(food);
        }

        int happinessValue = foods.Sum(f => f.FoodHappiness);

        Console.WriteLine(happinessValue);

        Mood mood = MoodFactory.GetMood(happinessValue);

        Console.WriteLine(mood.MoodType);
    }
    public static void Main()
    {
        List <Animal> animals = new List <Animal>();

        string input = null;

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

            Animal animal = AnimalFactory.GetAnimal(animalParams);
            Food   food   = FoodFactory.GetFood(foodParams);

            animal.ProduceSound();
            animal.Eat(food);

            animals.Add(animal);
        }

        animals.ForEach(Console.WriteLine);
    }
Beispiel #20
0
    static void Main()
    {
        var foodFactory = new FoodFactory();
        var moodFactory = new MoodFactory();
        var gandalf     = new Gandalf();

        var inputFood = Console.ReadLine()
                        .Split(new[] { '\t', ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);

        foreach (var foodStr in inputFood)
        {
            Food food = foodFactory.GetFood(foodStr);
            gandalf.Eat(food);
        }

        int totalHapinessPoints = gandalf.GetHapinessPoints();

        Mood currentMood = moodFactory.GetMood(totalHapinessPoints);

        Console.WriteLine(totalHapinessPoints);
        Console.WriteLine(currentMood);
    }
Beispiel #21
0
        public static void Main()
        {
            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                var    tokens     = input.Split(new char[] { '\t', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                Animal animal     = AnimalFactory.GetAnimal(tokens);
                var    foodTokens = Console.ReadLine().Split(new char[] { '\t', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                Food   food       = FoodFactory.GetFood(foodTokens);

                Console.WriteLine(animal.MakeSound());
                try
                {
                    animal.Eat(food);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                Console.WriteLine(animal);
            }
        }
Beispiel #22
0
    private static void Main()
    {
        List <Animal> animals = new List <Animal>();

        string input = string.Empty;

        while ((input = Console.ReadLine()) != "End")
        {
            Animal animal = null;
            Food   food   = null;
            try
            {
                animal = AnimalFactory.GetAnimal(input.Split());
                food   = FoodFactory.GetFood(Console.ReadLine().Split());
            }
            catch (ArgumentException)
            {
                continue;
            }

            animal.MakeSound();

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

            animals.Add(animal);
        }

        animals.ForEach(a => Console.WriteLine(a.ToString()));
    }
Beispiel #23
0
    public static void Main()
    {
        List <Animal> animals = new List <Animal>();

        FoodFactory   foodFactory   = new FoodFactory();
        AnimalFactory animalFactory = new AnimalFactory();

        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            string[] animalTokens = input.Split();
            Animal   animal       = animalFactory.GetAnimal(animalTokens[0], animalTokens);

            string[] foodTokens = Console.ReadLine().Split();
            Food     food       = foodFactory.GetFood(foodTokens[0], int.Parse(foodTokens[1]));

            Console.WriteLine(animal.ProduceSound());

            try
            {
                animal.Eat(food);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }

            animals.Add(animal);
        }

        foreach (var animal in animals)
        {
            Console.WriteLine(animal);
        }
    }
        public static void Main()
        {
            var input = "";

            while ((input = Console.ReadLine()) != "End")
            {
                var animalTokens = input.Split(new[] { '\t', ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                var foodTokens   = Console.ReadLine().Split(new[] { '\t', ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                Animal animal = AnimalFactory.GetAnimal(animalTokens);
                Food   food   = FoodFactory.GetFood(foodTokens);

                try
                {
                    Console.WriteLine(animal.MakeSound());
                    animal.Eat(food);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine(animal.ToString());
            }
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            var    animals = new List <Animal>();
            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                var animalsTokens = command.Split();
                var newAnimal     = AnimalFactory.GetAnimal(animalsTokens);
                var foodTokens    = Console.ReadLine().Split();
                var food          = FoodFactory.GetFood(foodTokens);
                Console.WriteLine(newAnimal.ProduceSound());
                animals.Add(newAnimal);
                try
                {
                    newAnimal.TryToEatFood(food);
                }
                catch (ArgumentException err)
                {
                    Console.WriteLine(err.Message);
                }
            }
            PrintAnimals(animals);
        }
    public static void Main()
    {
        var player = new Player();

        player.Eat(Console.ReadLine()
                   .Split()
                   .Where(fn => fn != string.Empty)
                   .Select(fn => FoodFactory.GetFood(fn)));

        Console.WriteLine(player);


        //var currentPoints = new MyFood();
        //var input = Console.ReadLine().ToLower().Trim().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);

        //for (int i = 0; i < input.Length; i++)
        //{
        //    var currentFood = input[i];
        //    currentPoints.AddFoodType(currentFood);
        //}
        //var mood = new MyMood();
        //Console.WriteLine($"{currentPoints.Points}");
        //Console.WriteLine($"{mood.GetMoodFace(currentPoints)}");
    }
Beispiel #27
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     gandalf = new Gandalf();
     gandalf.Eat(str.Split().Where(fn => fn != String.Empty).Select(fn => FoodFactory.GetFood(fn)));
     Mood.Content = gandalf;
 }
Beispiel #28
0
        static void Main(string[] args)
        {
            Gandalf gand = new Gandalf();

            gand.Eat(Console.ReadLine().Split().Where(fn => fn != string.Empty).Select(fn => FoodFactory.GetFood(fn)));
            Console.WriteLine(gand);
        }