public void GenerateRandomGrid_Generates10ShipsAndCallPlaceRandomlyForEveryShip()
        {
            var randomShipGeneratorStub = new Mock <IShipGenerator>();
            var fourDeckShip            = new FourDeckShip(ShipShape.Line, ShipRotation._0);
            var threeDeckShip           = new ThreeDeckShip(ShipShape.Line, ShipRotation._0);
            var twoDeckShip             = new TwoDeckShip(ShipRotation._0);
            var oneDeckShip             = new OneDeckShip();

            randomShipGeneratorStub.Setup(s => s.GenerateShipOfSize(4)).Returns(fourDeckShip);
            randomShipGeneratorStub.Setup(s => s.GenerateShipOfSize(3)).Returns(threeDeckShip);
            randomShipGeneratorStub.Setup(s => s.GenerateShipOfSize(2)).Returns(twoDeckShip);
            randomShipGeneratorStub.Setup(s => s.GenerateShipOfSize(1)).Returns(oneDeckShip);
            var shipPlacerStub = new Mock <IShipPlacer>();
            var emptyGrid      = EmptyGridGenerator.GenerateEmptyGridOfSize(Constants.GridSize);
            var seaBattleGame  = new SeaBattleGame(randomShipGeneratorStub.Object, shipPlacerStub.Object);

            seaBattleGame.GenerateRandomGrid();

            Assert.That(seaBattleGame.Grid, Is.EqualTo(emptyGrid));
            randomShipGeneratorStub.Verify(generator => generator.GenerateShipOfSize(4), Times.Exactly(1));
            randomShipGeneratorStub.Verify(generator => generator.GenerateShipOfSize(3), Times.Exactly(2));
            randomShipGeneratorStub.Verify(generator => generator.GenerateShipOfSize(2), Times.Exactly(3));
            randomShipGeneratorStub.Verify(generator => generator.GenerateShipOfSize(1), Times.Exactly(4));
            shipPlacerStub.Verify(placer => placer.PlaceRandomly(fourDeckShip, It.IsAny <bool[][]>()), Times.Exactly(1));
            shipPlacerStub.Verify(placer => placer.PlaceRandomly(threeDeckShip, It.IsAny <bool[][]>()), Times.Exactly(2));
            shipPlacerStub.Verify(placer => placer.PlaceRandomly(twoDeckShip, It.IsAny <bool[][]>()), Times.Exactly(3));
            shipPlacerStub.Verify(placer => placer.PlaceRandomly(oneDeckShip, It.IsAny <bool[][]>()), Times.Exactly(4));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            const int row    = 12;
            const int column = 12;

            string[,] array = new string[row, column];

            CreateBorder(array);
            Random random = new Random();

            FourDeckShip fourDeckShip = new FourDeckShip();

            fourDeckShip.GenerateShip(1, array, random);

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    Console.Write(array[i, j]);
                }

                Console.WriteLine("");
            }


            ThreeDeckShip threeDeckShip = new ThreeDeckShip();

            threeDeckShip.GenerateShip(2, array, random);

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    Console.Write(array[i, j]);
                }

                Console.WriteLine("");
            }

            OneDeckShip ship = new OneDeckShip();

            ship.GenerateShip(4, array, random);

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    Console.Write(array[i, j]);
                }

                Console.WriteLine("");
            }

            TwoDeckShip twoDeskShip = new TwoDeckShip();

            twoDeskShip.GenerateShip(3, array, random);

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    Console.Write(array[i, j]);
                }

                Console.WriteLine("");
            }



            Console.ReadKey();
        }