Пример #1
0
        static void Main(string[] args)
        {
            PlayingField playingField = new PlayingField();

            _ = (AuxiliaryShip)playingField.AddShip(playingField.InitNewPoint(), ShipType.auxiliary);
            _ = (MilitaryShip)playingField.AddShip(playingField.InitNewPoint(), ShipType.military);
            MixShip mixShip  = (MixShip)playingField.AddShip(playingField.InitNewPoint(), ShipType.mix);
            MixShip mixShip1 = (MixShip)playingField.AddShip(playingField.InitNewPoint(), ShipType.mix);

            mixShip1.CompareTo(mixShip);
            Console.WriteLine(playingField.GetAllShips());

            //Console.WriteLine("Do you want select ship? Input index:");
            //string index = Console.ReadLine();
            //playingField.SelectShip(index);
        }
Пример #2
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);
        }