예제 #1
0
        static void Main(string[] args)
        {
            using (SQLShipRepository sqlRepository = new SQLShipRepository())
            {
                Ship ship1 = new AuxiliaryShip {
                    Id = 5, Length = 3, Range = 1, Dx = 4, Dy = 4
                };
                Ship ship2 = new MilitaryShip {
                    Id = 2, Length = 1, Range = 2, Dx = 2, Dy = 6
                };
                sqlRepository.Create(ship1);
                sqlRepository.Create(ship2);
                sqlRepository.Save();
                Console.WriteLine("Объекты успешно сохранены");

                var users = sqlRepository.GetEntityList();
                Console.WriteLine("Список объектов:");
                foreach (Ship u in users)
                {
                    Console.WriteLine("Id = {0}; lenght {1} - {2}", u.Id, u.Length, u.Range);
                }
                ship2.Length = 1;
                sqlRepository.Update(ship2);
                sqlRepository.Delete(1);
                sqlRepository.Save();
            }

            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            ShipType military = new ShipType
            {
                Id          = 1,
                Description = "Military"
            };
            ShipType auxiliary = new ShipType
            {
                Id          = 2,
                Description = "Auxiliary"
            };
            ShipType mix = new ShipType
            {
                Id          = 3,
                Description = "Mix"
            };

            Repository <ShipType> shipTypeRepository = new Repository <ShipType>();
            //shipTypeRepository.Insert(military);
            //shipTypeRepository.Insert(auxiliary);
            //shipTypeRepository.Insert(mix);

            AuxiliaryShip auxiliaryShip = new AuxiliaryShip
            {
                Id         = 2,
                Dx         = 1,
                Dy         = 0,
                Range      = 1,
                Length     = 2,
                ShipTypeId = 2
            };
            MilitaryShip militaryShip = new MilitaryShip
            {
                Id         = 1,
                Dx         = 1,
                Dy         = 0,
                Range      = 1,
                Length     = 2,
                ShipTypeId = 1
            };

            Repository <Ship> shipRepository = new Repository <Ship>();
            // shipRepository.Insert(militaryShip);
            //shipRepository.Insert(auxiliaryShip);
            //militaryShip.Length = 3;
            //shipRepository.Update(militaryShip);

            //shipRepository.Delete(auxiliaryShip);
            //Console.WriteLine(shipRepository.GetById(2));
            List <string> res = shipRepository.GetAll();

            Console.ReadKey();
        }
예제 #3
0
        public Ship AddShip(Point startPoint, ShipType type)
        {
            Random random = new Random();
            Ship   ship   = new MixShip
            {
                Range = random.Next(1, 5)
            };

            switch (type)
            {
            case ShipType.auxiliary:
                ship = new AuxiliaryShip
                {
                    Type = ShipType.auxiliary
                };
                AuxiliaryShip aShip = (AuxiliaryShip)ship;
                aShip.Repair();
                break;

            case ShipType.military:
                ship = new MilitaryShip
                {
                    Type = ShipType.military
                };
                MilitaryShip mShip = (MilitaryShip)ship;
                mShip.Shoot();
                break;

            case ShipType.mix:
                ship = new MixShip
                {
                    Type = ShipType.mix
                };
                MixShip mixShip = (MixShip)ship;
                mixShip.Repair();
                mixShip.Shoot();
                break;
            }

            InitializeShip(ref ship, startPoint);
            Ships.Add(startPoint, ship);
            return(ship);
        }