Пример #1
0
        public void TestCircle()
        {
            IFigureFactorory figureFactory = new CircleFactory(1);
            IFigure          figure        = figureFactory.Create();

            Assert.AreEqual(figure.Square, Math.PI);
        }
Пример #2
0
        public static void Demo()
        {
            List <Figure> figures = new List <Figure>();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Console graphical editor.");
                Console.WriteLine("Select option.");
                Console.WriteLine("1. Add Line.");
                Console.WriteLine("2. Add Circle.");
                Console.WriteLine("3. Add Rectangle.");
                Console.WriteLine("4. Add Round.");
                Console.WriteLine("5. Add Ring.");
                Console.WriteLine("6. Add Ring (aggregation).");
                Console.WriteLine("7. Show figures.");
                Console.WriteLine("0. Exit.");

                int select;
                while (!int.TryParse(Console.ReadLine(), out select))
                {
                    Console.WriteLine("Wrong input. Try again.");
                }

                switch (select)
                {
                case 1:
                    figures.Add(LineFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Line added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 2:
                    figures.Add(CircleFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Circle added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 3:
                    figures.Add(RectangleFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Rectangle added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 4:
                    figures.Add(RoundFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Round added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 5:
                    figures.Add(RingFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Ring added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 6:
                    figures.Add(RingAggregationFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Ring (aggregation) added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 7:
                    Console.Clear();
                    foreach (Figure figure in figures)
                    {
                        figure.ShowInfo();
                        Console.WriteLine();
                    }
                    Console.ReadLine();
                    break;

                case 0:
                    Console.WriteLine("Good luck!");
                    Console.ReadLine();
                    return;

                default:
                    Console.WriteLine("Wrong option. Try again.");
                    break;
                }
            }
        }
Пример #3
0
        static void Main()
        {
            Figure         factory = new Figure();
            Random         rand    = new Random();
            List <IFigure> figures = new List <IFigure>();
            bool           finish  = false;

            for (int i = 0; i < 5; i++)
            {
                figures.Add(factory.Create((Dict)rand.Next(0, 3)));
            }
            do
            {
                Console.WriteLine("1. Wyświetl figury.");
                Console.WriteLine("2. Dodaj figurę.");
                Console.WriteLine("K. Wyjdź.");
                string choice;
                choice = Console.ReadLine();
                switch (choice)
                {
                case "1":
                    Console.Clear();
                    do
                    {
                        Console.WriteLine("Aby zwiększyc, zmniejszyć lub usunąć figurę wybierz ją po numerze.");
                        for (int i = 0; i < figures.Count; i++)
                        {
                            Console.WriteLine("{0}. {1}", i + 1, figures[i].ToString());
                        }
                        Console.WriteLine("K. Wróć.");
                        choice = Console.ReadLine();
                        if (choice == "K" || choice == "k")
                        {
                            finish = true;
                            Console.Clear();
                        }
                        else
                        {
                            try
                            {
                                int index = Convert.ToInt32(choice) - 1;
                                Console.Clear();
                                do
                                {
                                    Console.WriteLine(figures[index].ToString());
                                    Console.WriteLine("1. Powiększ.");
                                    Console.WriteLine("2. Zmniejsz.");
                                    Console.WriteLine("3. Usuń.");
                                    Console.WriteLine("K. Wróć.");
                                    choice = Console.ReadLine();
                                    Console.Clear();
                                    switch (choice)
                                    {
                                    case "1":
                                        figures[index].Increase();
                                        break;

                                    case "2":
                                        figures[index].Decrease();
                                        break;

                                    case "3":
                                        figures.RemoveAt(index);
                                        finish = true;
                                        break;

                                    case "k":
                                    case "K":
                                        finish = true;
                                        break;

                                    default:
                                        Console.WriteLine("Zła wartość. Wpisz ponownie.");
                                        break;
                                    }
                                }while (!finish);
                                finish = false;
                            }
                            catch
                            {
                                Console.Clear();
                                Console.WriteLine("Zła wartość. Podaj ponownie.");
                            }
                        }
                    }while (!finish);
                    finish = false;
                    break;

                case "2":
                    do
                    {
                        Console.WriteLine("Wybierz jaką figurę tworzysz:");
                        Console.WriteLine("1. Kwadrat.");
                        Console.WriteLine("2. Prostokąt.");
                        Console.WriteLine("3. Koło.");
                        Console.WriteLine("K. Wróć.");
                        choice = Console.ReadLine();
                        Console.Clear();
                        double a, b;
                        switch (choice)
                        {
                        case "1":
                            SquareFactory squareFactory = new SquareFactory();
                            Console.WriteLine("Podaj długość boku. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            figures.Add(squareFactory.Create(a));
                            break;

                        case "2":
                            RectangleFactory rectangleFactory = new RectangleFactory();
                            Console.WriteLine("Podaj długość pierwszego boku. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            Console.WriteLine("Podaj długość drugiego boku. ");
                            b = Convert.ToDouble(Console.ReadLine());
                            figures.Add(rectangleFactory.Create(a, b));
                            break;

                        case "3":
                            CircleFactory circleFactory = new CircleFactory();
                            Console.WriteLine("Podaj długość promienia. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            figures.Add(circleFactory.Create(a));
                            break;

                        case "k":
                        case "K":
                            finish = true;
                            break;

                        default:
                            Console.Clear();
                            Console.WriteLine("Zły wybór. Wybierz ponownie.");
                            break;
                        }
                    }while (!finish);
                    finish = false;
                    Console.Clear();
                    break;

                case "k":
                case "K":
                    finish = true;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Zły wybór. Wybierz ponownie.");
                    break;
                }
            }while (!finish);
        }