예제 #1
0
        public void InitializeTheFleet()
        {
            List <Coordinate> carrierCoordinates = new List <Coordinate>(5);

            carrierCoordinates.Add(new Coordinate(1, 1));
            carrierCoordinates.Add(new Coordinate(1, 2));
            carrierCoordinates.Add(new Coordinate(1, 3));
            carrierCoordinates.Add(new Coordinate(1, 4));
            carrierCoordinates.Add(new Coordinate(1, 5));

            List <Coordinate> battleshipCoordinates = new List <Coordinate>(4);

            battleshipCoordinates.Add(new Coordinate(1, 7));
            battleshipCoordinates.Add(new Coordinate(2, 7));
            battleshipCoordinates.Add(new Coordinate(3, 7));
            battleshipCoordinates.Add(new Coordinate(4, 7));

            List <Coordinate> destroyerCoordinates = new List <Coordinate>(3);

            destroyerCoordinates.Add(new Coordinate(5, 2));
            destroyerCoordinates.Add(new Coordinate(5, 3));
            destroyerCoordinates.Add(new Coordinate(5, 4));

            List <Coordinate> submarineCoordinates = new List <Coordinate>(3);

            submarineCoordinates.Add(new Coordinate(7, 5));
            submarineCoordinates.Add(new Coordinate(8, 5));
            submarineCoordinates.Add(new Coordinate(9, 5));

            List <Coordinate> smallAssaultShipCoordinates = new List <Coordinate>(1);

            smallAssaultShipCoordinates.Add(new Coordinate(8, 9));

            Carrier          carrier;
            Battleship       battleship;
            Destroyer        destroyer;
            Submarine        submarine;
            SmallAssaultShip assaultShip;

            ShipFactoryCreator factory = new ShipFactoryCreator();

            carrier = (Carrier)factory.CreateShip(ShipType.Carrier, carrierCoordinates);
            Console.WriteLine("Created {0}", carrier.GetType().Name);
            battleship = (Battleship)factory.CreateShip(ShipType.Battleship, battleshipCoordinates);
            Console.WriteLine("Created {0}", battleship.GetType().Name);
            destroyer = (Destroyer)factory.CreateShip(ShipType.Destroyer, destroyerCoordinates);
            Console.WriteLine("Created {0}", destroyer.GetType().Name);
            submarine = (Submarine)factory.CreateShip(ShipType.Submarine, submarineCoordinates);
            Console.WriteLine("Created {0}", submarine.GetType().Name);
            assaultShip = (SmallAssaultShip)factory.CreateShip(ShipType.SmallAssaultShip, smallAssaultShipCoordinates);
            Console.WriteLine("Created {0}", assaultShip.GetType().Name);

            _fleet = new Fleet(carrier, battleship, destroyer, submarine, assaultShip);
        }
예제 #2
0
        private void InitializeTheBattleshipGrid()
        {
            Ship[] ships = new Ship[5];

            List <Coordinate> carrierCoordinates = new List <Coordinate>(5);

            carrierCoordinates.Add(new Coordinate(1, 1));
            carrierCoordinates.Add(new Coordinate(1, 2));
            carrierCoordinates.Add(new Coordinate(1, 3));
            carrierCoordinates.Add(new Coordinate(1, 4));
            carrierCoordinates.Add(new Coordinate(1, 5));

            List <Coordinate> battleshipCoordinates = new List <Coordinate>(4);

            battleshipCoordinates.Add(new Coordinate(1, 7));
            battleshipCoordinates.Add(new Coordinate(2, 7));
            battleshipCoordinates.Add(new Coordinate(3, 7));
            battleshipCoordinates.Add(new Coordinate(4, 7));

            List <Coordinate> destroyerCoordinates = new List <Coordinate>(3);

            destroyerCoordinates.Add(new Coordinate(5, 2));
            destroyerCoordinates.Add(new Coordinate(5, 3));
            destroyerCoordinates.Add(new Coordinate(5, 4));

            List <Coordinate> submarineCoordinates = new List <Coordinate>(3);

            submarineCoordinates.Add(new Coordinate(7, 5));
            submarineCoordinates.Add(new Coordinate(8, 5));
            submarineCoordinates.Add(new Coordinate(9, 5));

            List <Coordinate> smallAssaultShipCoordinates = new List <Coordinate>(1);

            smallAssaultShipCoordinates.Add(new Coordinate(8, 9));

            ShipFactoryCreator factory = new ShipFactoryCreator();

            ships[0] = (Ship)factory.CreateShip(ShipType.Carrier, carrierCoordinates);
            Console.WriteLine("Created {0}", ships[0].GetType().Name);
            ships[1] = (Ship)factory.CreateShip(ShipType.Battleship, battleshipCoordinates);
            Console.WriteLine("Created {0}", ships[1].GetType().Name);
            ships[2] = (Ship)factory.CreateShip(ShipType.Destroyer, destroyerCoordinates);
            Console.WriteLine("Created {0}", ships[2].GetType().Name);
            ships[3] = (Ship)factory.CreateShip(ShipType.Submarine, submarineCoordinates);
            Console.WriteLine("Created {0}", ships[3].GetType().Name);
            ships[4] = (Ship)factory.CreateShip(ShipType.SmallAssaultShip, smallAssaultShipCoordinates);
            Console.WriteLine("Created {0}", ships[4].GetType().Name);

            Fleet fleet = new BattleshipGrid.Fleet(ships);

            _battleshipGrid = new BattleshipGrid.BattleshipGrid(fleet);
        }
        public BattleshipGridModel(List <Coordinate> carrierCoordinates, List <Coordinate> battleshipCoordinates,
                                   List <Coordinate> destroyerCoordinates, List <Coordinate> submarineCoordinates, List <Coordinate> smallAssaultShipCoordinates)
        {
            Carrier          carrier;
            Battleship       battleship;
            Destroyer        destroyer;
            Submarine        submarine;
            SmallAssaultShip assaultShip;

            ShipFactoryCreator factory = new ShipFactoryCreator();

            carrier     = (Carrier)factory.CreateShip(ShipType.Carrier, carrierCoordinates);
            battleship  = (Battleship)factory.CreateShip(ShipType.Battleship, battleshipCoordinates);
            destroyer   = (Destroyer)factory.CreateShip(ShipType.Destroyer, destroyerCoordinates);
            submarine   = (Submarine)factory.CreateShip(ShipType.Submarine, submarineCoordinates);
            assaultShip = (SmallAssaultShip)factory.CreateShip(ShipType.SmallAssaultShip, smallAssaultShipCoordinates);

            _battleshipGrid = new BattleshipGrid.BattleshipGrid(new Fleet(carrier, battleship, destroyer, submarine, assaultShip));
        }