Beispiel #1
0
        public void GivenDesiredSize_GeneratedGridHasCorrectSize(int size)
        {
            var cells = gridGenerator.Generate(size, size);

            cells.Length.Should().Be(size * size);
            cells.GetLength(0).Should().Be(size);
        }
Beispiel #2
0
        public BattleshipGameEngine(IGridGenerator gridGenerator, ICpuMovementLogic cpuMovementLogic)
        {
            _gridGenerator    = gridGenerator ?? throw new ArgumentNullException(nameof(gridGenerator));
            _cpuMovementLogic = cpuMovementLogic ?? throw new ArgumentNullException(nameof(cpuMovementLogic));

            CpuGrid    = _gridGenerator.Generate(forPlayer: false);
            PlayerGrid = _gridGenerator.Generate(forPlayer: true);

            Status = new Random().Next(0, 2) == 0 ? GameStatus.PlayerMovement : GameStatus.CpuMovement;
        }
Beispiel #3
0
        public void GetCell_IsNotNull()
        {
            const int size      = 3;
            const int mineCount = 3;
            var       cells     = gridGenerator.Generate(size, mineCount);
            var       g         = new Grid(size, cells);

            var cell = g.GetCell(0, 0);

            cell.Should().NotBeNull();
        }
Beispiel #4
0
        public BattleshipOneSideGameEngine(IGridGenerator gridGenerator)
        {
            _gridGenerator = gridGenerator ?? throw new ArgumentNullException(nameof(gridGenerator));
            Grid           = _gridGenerator.Generate(forPlayer: false);

            Status = GameStatus.PlayerMovement;
        }
        private void InitializeGrid(int size)
        {
            var mineCount = GenerateRandomMineCount(size);
            var cells     = gridGenerator.Generate(size, mineCount);

            grid = new Grid(size, cells);
        }
Beispiel #6
0
        public ShapeSearchResultModel Search(ShapeSearchRequestModel search)
        {
            var grid = _gridGenerator.Generate(_appConfig.GridSize);

            ITriangle result = null;

            if (search.SearchBy.Equals("name", System.StringComparison.InvariantCultureIgnoreCase))
            {
                result = grid.FindTriangleByName(search.Name);
            }
            else if (search.SearchBy.Equals("coordinates", System.StringComparison.InvariantCultureIgnoreCase))
            {
                var searchVertex = new TriangularVertex(new Coordinates(search.Vertex1), new Coordinates(search.Vertex2), new Coordinates(search.Vertex3));
                result = grid.FindTriangleByCoordinates(searchVertex);
            }

            if (result == null)
            {
                return(null);
            }

            return(new ShapeSearchResultModel
            {
                Name = result.Name,
                IsBottom = result.IsBottom,
                Vertex1 = result.Vertices.Vertex1,
                Vertex2 = result.Vertices.Vertex2,
                Vertex3 = result.Vertices.Vertex3,
                ParentCellX = result.ParentCell.Coordinates.X,
                ParentCellY = result.ParentCell.Coordinates.Y
            });
        }