Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public override Field GetPlayerField(GameRules gameRules)
        {
            IFieldBuilder fieldBuilder = new FieldBuilder();

            fieldBuilder.SetDimension(gameRules.FieldHeight, gameRules.FieldWidth);
            fieldBuilder.SetShipsStorage(gameRules.ShipsStorage);

            View.ShowConcreteCellsMatrix(fieldBuilder.GetResult().CellsMatrix);

            foreach (var shipAvailable in gameRules.ShipsStorage.ShipsAvailable)
            {
                int i = 0;
                while (i < shipAvailable.Value)
                {
                    View.ShowInfo("Place " + shipAvailable.Key + " ship:");

                    var shipPlacementInfo = new ShipPlacementInfo
                    {
                        ShipType     = shipAvailable.Key,
                        ShipRotation = View.GetRotationInput(),
                        Point        = View.GetPointInput()
                    };

                    try
                    {
                        fieldBuilder.AddShip(shipPlacementInfo);
                    }
                    catch (Exception e)
                    {
                        View.ShowInfo(e.Message);
                        continue;
                    }

                    View.Clear();

                    View.ShowConcreteCellsMatrix(fieldBuilder.GetResult().CellsMatrix);

                    i++;
                }
            }

            return(fieldBuilder.GetResult());
        }