예제 #1
0
        public void AddShip_ThrowsShipPlacementCollisionException(int pointX, int pointY, ShipRotation shipRotation)
        {
            var shipStorage = new ShipsStorage();

            shipStorage.AddShip(ShipType.FourDecks, 1);
            shipStorage.AddShip(ShipType.TwoDecks, 1);

            _builder.SetDimension(5, 5);
            _builder.SetShipsStorage(shipStorage);

            var shipPlacementInfoFirst = new ShipPlacementInfo
            {
                Point        = new Point(3, 3),
                ShipRotation = ShipRotation.Horizontal,
                ShipType     = ShipType.TwoDecks
            };

            _builder.AddShip(shipPlacementInfoFirst);

            var shipPlacementInfoSecond = new ShipPlacementInfo
            {
                Point        = new Point(pointX, pointY),
                ShipRotation = shipRotation,
                ShipType     = ShipType.FourDecks
            };


            void Action() => _builder.AddShip(shipPlacementInfoSecond);


            Assert.Throws <ShipPlacementCollisionException>(Action);
        }
예제 #2
0
        public void AddShip_SurroundShipWithClosedCells(int pointX, int pointY, ShipRotation shipRotation, ShipType shipType)
        {
            var shipStorage = new ShipsStorage();

            shipStorage.AddShip(shipType, 1);

            _builder.SetDimension(5, 5);
            _builder.SetShipsStorage(shipStorage);

            var shipPlacementInfo = new ShipPlacementInfo
            {
                Point        = new Point(pointX, pointY),
                ShipRotation = shipRotation,
                ShipType     = shipType
            };


            _builder.AddShip(shipPlacementInfo);

            var listOfCells = GetListOfCellsAroundShip(shipPlacementInfo);

            foreach (var cell in listOfCells)
            {
                Assert.False(cell.CanPlaceShip);
            }
        }
예제 #3
0
        public void AddShip_RightShipPlacementInfo(int pointX, int pointY, ShipRotation shipRotation, ShipType shipType)
        {
            var shipStorage = new ShipsStorage();

            shipStorage.AddShip(shipType, 1);

            _builder.SetDimension(5, 5);
            _builder.SetShipsStorage(shipStorage);

            var shipPlacementInfo = new ShipPlacementInfo
            {
                Point        = new Point(pointX, pointY),
                ShipRotation = shipRotation,
                ShipType     = shipType
            };


            _builder.AddShip(shipPlacementInfo);

            var listOfCells = GetListOfCellsWhereShipShouldBe(shipPlacementInfo);

            foreach (var cell in listOfCells)
            {
                Assert.True(cell.CellState == CellState.Ship);
            }
        }
예제 #4
0
        private void SetGameRules() //TODO
        {
            _gameRules = new GameRules();

            ShipsStorage shipsStorage = new ShipsStorage();

            /*
             * shipsStorage.AddShip(ShipType.FourDecks, 1);
             * shipsStorage.AddShip(ShipType.ThreeDecks, 2);
             * shipsStorage.AddShip(ShipType.TwoDecks, 3);
             * shipsStorage.AddShip(ShipType.OneDeck, 4);
             *
             * _gameRules.FieldHeight = 10;
             * _gameRules.FieldWidth = 10;
             */
            shipsStorage.AddShip(ShipType.TwoDecks, 1);
            shipsStorage.AddShip(ShipType.OneDeck, 2);

            _gameRules.FieldHeight = 5;
            _gameRules.FieldWidth  = 5;

            _gameRules.ShipsStorage = shipsStorage;
        }
예제 #5
0
        public void AddShip_ThrowsShipPlacementOutOfBoundsException(int pointX, int pointY, ShipRotation shipRotation)
        {
            var shipStorage = new ShipsStorage();

            shipStorage.AddShip(ShipType.FourDecks, 1);


            _builder.SetDimension(5, 5);
            _builder.SetShipsStorage(shipStorage);

            var shipPlacementInfo = new ShipPlacementInfo
            {
                Point        = new Point(pointX, pointY),
                ShipRotation = shipRotation,
                ShipType     = ShipType.FourDecks
            };


            void Action() => _builder.AddShip(shipPlacementInfo);


            Assert.Throws <ShipPlacementOutOfBoundsException>(Action);
        }