public void FirstItemFromExternalGridShouldEqualWithLast([Values(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)]int bottomRowSize)
        {
            // Given
            var cellsCount = PositionHelper.GetCellsCount(bottomRowSize);

            var generator = new GridGenerator(cellsCount, new PortableSize(1, 1));

            // When
            var externalGrid = generator.ExternalGrid;

            // Then
            externalGrid.First().ShouldBe(externalGrid.Last());
        }
        public void ShouldGetCenterOfAllCells([Values(1, 3, 5, 8, 9, 10)]int triangleSize)
        {
            // Given
            var cellsCount = PositionHelper.GetCellsCount(triangleSize);

            var generator = new GridGenerator(cellsCount, new PortableSize(1, 1));

            var positions = Enumerable.Range(0, cellsCount).Select(i => PositionHelper.GetTrianglePosition(i, triangleSize)).ToImmutableArray();

            // When
            var centres = positions.Select(generator.GetCenterOfCell).ToImmutableArray();

            // Then
            centres.Length.ShouldBe(positions.Length);
        }
        public void CheckBallCenterX([Values(1, 3, 5)]int triangleSize)
        {
            // Given
            var cellsCount = PositionHelper.GetCellsCount(triangleSize);

            var generator = new GridGenerator(cellsCount, new PortableSize(1, 10));
            var column = triangleSize / 2;
            var trianglePosition = new TrianglePosition(0, column, triangleSize);

            // When
            var centerOfMiddle = generator.GetCenterOfCell(trianglePosition);

            // Then
            centerOfMiddle.X.ShouldBe(0.5);
        }
 public DragAndDropManager([NotNull] GridGenerator gridGenerator, [NotNull] GameColorViewModel colorsModel)
 {
     _gridGenerator = gridGenerator;
     _colorsModel = colorsModel;
 }
Beispiel #5
0
        private void GenerateGridBalls(GameColorViewModel[] gameColors, Style style, GridGenerator gridGenerator)
        {
            var triangleSize = PositionHelper.GetMaxTriangleSize(gameColors.Length);

            var colorsCount = gameColors.Length;
            var size = gridGenerator.EllipseSize;

            for (var index = 0; index < colorsCount; index++)
            {
                var circle = new Ellipse();

                var targetModel = gameColors[index];

                circle.DataContext = targetModel;
                circle.Style = style;
                circle.Margin = new Thickness(0, 0, 0, -.75);
                circle.Width = size.Width;
                circle.Height = size.Height;

                targetModel.PropertyChanged += (_, __) => UpdateView(circle, targetModel);

                var trianglePosition = PositionHelper.GetTrianglePosition(index, triangleSize);
                var position = gridGenerator.GetCenterOfCell(trianglePosition);

                ConfigureAndAddElement(GameCanvas, circle, position);

                UpdateView(circle, targetModel);
            }
        }
Beispiel #6
0
        private PathFigureCollection CreatePathFigure(GridGenerator pointsGenerator)
        {
            var result = new PathFigureCollection();

            result.Add(GetExternalGridFigure(pointsGenerator.ExternalGrid));

            foreach (var points in pointsGenerator.InternalPathes)
            {
                result.Add(GetInteralGridFigure(points));
            }

            return result;
        }
Beispiel #7
0
        private void BuildGrid(GameColorViewModel[] gameColors)
        {
            GameCanvas.Children.Clear();

            var pointsGenerator = new GridGenerator(gameColors.Length, RootContainer.RenderSize.ToSize());

            var path = new Path();

            path.Data = new PathGeometry()
            {
                Figures = CreatePathFigure(pointsGenerator),
            };

            path.Stroke = new SolidColorBrush(Colors.White);
            path.Fill = new SolidColorBrush(Colors.Green);

            GameCanvas.Children.Add(path);

            GameCanvas.Width = pointsGenerator.Size.Width;
            GameCanvas.Height = pointsGenerator.Size.Height;

            GenerateGridBalls(gameColors, (Style) Resources["CellStyle"], pointsGenerator);
        }