Esempio n. 1
0
        static void Main(string[] args)
        {
            rand = new Random(DateTime.Now.Millisecond);
            Console.CursorVisible = false;

            Mat mat = new Mat();

            try
            {
                mat.Cost = -100;
            }
            catch (Exception ex)
            {
                ex.Message.ToLog();
                ex.ToString().ToLog();
            }
            finally
            {
                Console.Write("\n\tВведите новое значение цены: ");
                var newCost = Convert.ToInt32(Console.ReadLine());
                mat.Cost = Math.Abs(newCost);
            }

            Console.Clear();

            try
            {
                mat.MatType = (Mat.Type)(rand.Next());
            }
            catch (NotAvailableType ex)
            {
                Console.WriteLine($"Expecption {ex} in {ex.Source}");
                Console.WriteLine("Stack trace: " + ex.StackTrace);
                Console.WriteLine("In method:" + ex.TargetSite);
            }
            catch (NullReferenceException)
            {
                "Null!".ToLog();
            }
            finally
            {
                mat.MatType = Mat.Type.TypeB;
            }

            Bar bar;

            try
            {
                mat.Cost = rand.Next() / rand.Next(-1, 2);
                bar      = new Bar(true);
            }
            catch (CannotBeCreated)
            {
                "Cannot be a created".ToLog();
                bar = new Bar();
            }
            catch (DivideByZeroException)
            {
                "Деление на ноль!".ToLog();
                mat.Cost = rand.Next();
            }
            catch (Exception ex)
            {
                ex.ToString().ToLog();
            }

            Bench bench = null;

            Debug.Assert(bench != null, "Got a null");

            Console.ReadKey();
            Console.Clear();

            Equipment[] equipments = new Equipment[4];
            equipments[0] = new Bar();
            equipments[1] = new BasketballBall();
            equipments[2] = new Bench();
            equipments[3] = new Mat();

            Table barTable = new Table(equipments[0]);

            barTable.GetTableDataFrom(equipments[0]);
            barTable.GetTableDataFrom(new Bar());
            barTable.GetTableDataFrom(new Bar());
            Console.WriteLine(barTable);

            Table basketballTable = new Table(equipments[1]);

            basketballTable.GetTableDataFrom(equipments[1]);
            basketballTable.GetTableDataFrom(new BasketballBall());
            basketballTable.GetTableDataFrom(new BasketballBall());
            basketballTable.ToString().WriteFromPosition((Console.WindowWidth / 2, 0));

            Table benchTable = new Table(equipments[2]);

            benchTable.GetTableDataFrom(equipments[2]);
            benchTable.GetTableDataFrom(new Bench());
            benchTable.GetTableDataFrom(new Bench());
            benchTable.ToString().WriteFromPosition((Console.WindowWidth / 2, Console.WindowHeight / 2));

            Table matTable = new Table(equipments[3]);

            matTable.GetTableDataFrom(equipments[3]);
            matTable.GetTableDataFrom(new Mat());
            matTable.GetTableDataFrom(new Mat());
            matTable.ToString().WriteFromPosition((0, Console.WindowHeight / 2));

            equipments[0].DoSomething();
            equipments[1].DoSomething();
            equipments[2].DoSomething();
            equipments[3].DoSomething();
            "Press any button to continue...".ToLog();
            Console.ReadKey();

            IBall ball = equipments[1] as BasketballBall;

            ball.DoKick();

            Printer printer = new Printer();

            foreach (var equipment in equipments)
            {
                printer.IAmPrinting(equipment);
            }

            "Press any button to continue...".ToLog();
            Console.ReadKey();

            (equipments[1] as BasketballBall).DoSomething();
            (equipments[1] as IBall).DoSomething();

            Console.ReadKey();
            Console.Clear();

            Gym gym = new Gym(400);

            while (gym.HasMoney)
            {
                Equipment eq = new BasketballBall();
                gym.AddItem(eq);
            }
            Console.WriteLine(gym.ToString());
            GymController gymc = new GymController(gym);

            gymc.Sort();
            Console.WriteLine(gym.ToString());
            Console.WriteLine("\tEnter cost range:");
            List <Equipment> founded = gymc.Find(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()));

            Console.WriteLine($"\tResult [{founded.Count}]:");
            foreach (var item in founded)
            {
                Console.WriteLine(item.ToString());
            }
            Console.ReadKey();
        }
Esempio n. 2
0
 public GymController(Gym gym)
 {
     this.gym = gym;
 }