示例#1
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);
        }
示例#2
0
        static void Main(string[] args)
        {
            Program p = new Program();

            p.InitializeTheFleet();
            BattleshipGrid.BattleshipGrid battleshipGrid = new BattleshipGrid.BattleshipGrid(p._fleet);

            Coordinate hitPoint = new Coordinate(7, 5);

            Console.WriteLine("Attack(7,5) " + battleshipGrid.Attack(hitPoint));
            hitPoint = new Coordinate(8, 9);
            Console.WriteLine("Attack(8,9) " + battleshipGrid.Attack(hitPoint));
        }
示例#3
0
        public void TestCleanup()
        {
            _carrierCoordinatesMock     = null;
            _battleshipCoordinatesMock  = null;
            _destroyerCoordinatesMock   = null;
            _submarineCoordinatesMock   = null;
            _assaultShipCoordinatesMock = null;

            _carrierMock      = null;
            _battleshipMock   = null;
            _destroyerMock    = null;
            _submarineMock    = null;
            _assaultSipMock   = null;
            _fleetMock        = null;
            _subjectUnderTest = null;
        }
        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));
        }
示例#5
0
        public void TestInitialize()
        {
            _carrierCoordinatesMock     = new Mock <List <Coordinate> >(5);
            _battleshipCoordinatesMock  = new Mock <List <Coordinate> >(4);
            _destroyerCoordinatesMock   = new Mock <List <Coordinate> >(3);
            _submarineCoordinatesMock   = new Mock <List <Coordinate> >(3);
            _assaultShipCoordinatesMock = new Mock <List <Coordinate> >(1);

            _carrierMock    = new Mock <Carrier>(_carrierCoordinatesMock.Object);
            _battleshipMock = new Mock <Battleship>(_battleshipCoordinatesMock.Object);
            _destroyerMock  = new Mock <Destroyer>(_destroyerCoordinatesMock.Object);
            _submarineMock  = new Mock <Submarine>(_submarineCoordinatesMock.Object);
            _assaultSipMock = new Mock <SmallAssaultShip>(_assaultShipCoordinatesMock.Object);
            _fleetMock      = new Mock <Fleet>(_carrierMock.Object, _battleshipMock.Object, _destroyerMock.Object,
                                               _submarineMock.Object, _assaultSipMock.Object);

            _pointOfAttack = new Coordinate(1, 1);

            _subjectUnderTest = new BattleshipGrid.BattleshipGrid(_fleetMock.Object);
        }