Exemple #1
0
 public void ManipulationStarted(Point origin)
 {
     foreach (var point in GameCore.dashPoints)
     {
         if (point.IsInside(origin.X, origin.Y) && point.GetAvailableMoves(_fieldSize, GameCore.dashPoints) != Sides.None)
         {
             startPoint           = point;
             startPointNeighbours = point.GetNeighbours(_fieldSize, GameCore.dashPoints, true);
             previewLine          = new Line()
             {
                 X1                 = point.Center.X, Y1 = point.Center.Y,
                 X2                 = point.Center.X, Y2 = point.Center.Y,
                 Stroke             = brush,
                 StrokeThickness    = _linesWidth * Consts.DashWidthRatio / 2,
                 StrokeStartLineCap = PenLineCap.Round,
                 StrokeEndLineCap   = PenLineCap.Round
             };
             lineStartCircle = new Ellipse()
             {
                 HorizontalAlignment = HorizontalAlignment.Left,
                 VerticalAlignment   = VerticalAlignment.Top,
                 Margin = new Thickness(point.Center.X - halfCircleSize,
                                        point.Center.Y - halfCircleSize, 0, 0),
                 Width = circleSize, Height = circleSize, Fill = brush
             };
             _fieldGrid.Children.Add(previewLine);
             _fieldGrid.Children.Add(lineStartCircle);
             endPosition     = point.Center;
             movesVisualizer = new AvailableMovesVisualizer(point.Center, _fieldSize, _linesWidth, ref _fieldGrid);
             movesVisualizer.StartAnimation(point.GetAvailableMoves(_fieldSize, GameCore.dashPoints));
             break;
         }
     }
 }
 public bool IsNeighbour(DashPoint point)
 {
     if (Math.Abs(point.IIndex - this.IIndex) == 1 ||
         Math.Abs(point.JIndex - this.JIndex) == 1)
     {
         return(true);
     }
     return(false);
 }
 public static DashPoint MinPoint(ref DashPoint point1, ref DashPoint point2)
 {
     if (point1.IIndex < point2.IIndex || point1.JIndex < point2.JIndex)
     {
         return(point1);
     }
     else
     {
         return(point2);
     }
 }
Exemple #4
0
 public ManipulationHandler(int fieldSize, double linesWidth, ref Grid fieldGrid)
 {
     _fieldSize    = fieldSize;
     _fieldGrid    = fieldGrid;
     linesSpace    = fieldGrid.Width / fieldSize;
     _linesWidth   = linesWidth;
     startPoint    = null;
     endPoint      = null;
     lineEndCircle = new Ellipse();
     lineEndCircle.UseLayoutRounding = true;
     circleSize     = linesSpace * Consts.LineCirclesSizeRatio;
     halfCircleSize = circleSize / 2;
     brush          = new SolidColorBrush(GameCore.GetCurrentPlayerColor());
 }
Exemple #5
0
 private static void InitDashPoints()
 {
     dashPoints = new DashPoint[fieldSize + 1, fieldSize + 1];
     for (int i = 0; i < fieldSize + 1; i++)
     {
         for (int j = 0; j < fieldSize + 1; j++)
         {
             dashPoints[i, j] = new DashPoint()
             {
                 Center = new Point(i * linesSpace, j * linesSpace),
                 Size   = linesSpace * Consts.PointHitboxSizeRatio,
                 IIndex = i, JIndex = j
             };
         }
     }
 }
Exemple #6
0
        public void ManipulationDelta(Point deltaPos)
        {
            if (previewLine == null)
            {
                return;
            }
            endPosition.X += deltaPos.X;
            endPosition.Y += deltaPos.Y;
            Point startPosition = new Point(startPoint.Center.X, startPoint.Center.Y);
            Point limited       = LimitLine(startPosition, endPosition, linesSpace);

            previewLine.X2 = limited.X;
            previewLine.Y2 = limited.Y;
            if (startPointNeighbours != null)
            {
                bool found = false;
                foreach (var point in startPointNeighbours)
                {
                    if (point.IsInside(limited.X, limited.Y))
                    {
                        found          = true;
                        endPoint       = point;
                        previewLine.X2 = point.Center.X;                // Snap to dash point
                        previewLine.Y2 = point.Center.Y;
                        lineEndCircle.HorizontalAlignment = HorizontalAlignment.Left;
                        lineEndCircle.VerticalAlignment   = VerticalAlignment.Top;
                        lineEndCircle.Margin = new Thickness(point.Center.X - halfCircleSize,
                                                             point.Center.Y - halfCircleSize, 0, 0);
                        lineEndCircle.Width  = circleSize;
                        lineEndCircle.Height = circleSize;
                        lineEndCircle.Fill   = brush;
                        if (!_fieldGrid.Children.Contains(lineEndCircle))
                        {
                            _fieldGrid.Children.Add(lineEndCircle);
                        }
                        break;
                    }
                }
                if (!found)
                {
                    endPoint = null;
                    _fieldGrid.Children.Remove(lineEndCircle);
                }
            }
        }
Exemple #7
0
 public static bool IsThereDash(DashPoint point1, DashPoint point2)
 {
     foreach (var i in vertDashes)
     {
         if (i?.HasPoints(point1, point2) ?? false)
         {
             return(true);
         }
     }
     foreach (var i in horDashes)
     {
         if (i?.HasPoints(point1, point2) ?? false)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #8
0
        public static void CreateDash(ref DashPoint point1, ref DashPoint point2)
        {
            Dash      dash     = new Dash(ref point1, ref point2);
            DashPoint minPoint = DashPoint.MinPoint(ref point1, ref point2);

            GetDashesByType(dash.Type)[minPoint.IIndex, minPoint.JIndex] = dash;
            Line line = new Line()
            {
                X1                 = point1.Center.X, Y1 = point1.Center.Y,
                X2                 = point2.Center.X, Y2 = point2.Center.Y,
                Stroke             = new SolidColorBrush(GetCurrentPlayerColor()),
                StrokeThickness    = GetLinesWidth() * Consts.DashWidthRatio / 2,
                StrokeStartLineCap = PenLineCap.Round,
                StrokeEndLineCap   = PenLineCap.Round
            };

            fieldGrid.Children.Add(line);
            if (!HandleClosesCells())
            {
                SwapPlayers();
            }
        }
Exemple #9
0
 public bool HasPoints(DashPoint point1, DashPoint point2)
 {
     return((point1.IsIndexesEquals(StartPoint) && point2.IsIndexesEquals(EndPoint)) ||
            (point1.IsIndexesEquals(EndPoint) && point2.IsIndexesEquals(StartPoint)));
 }
Exemple #10
0
 public bool HasPoint(DashPoint point)
 {
     return(point.IsIndexesEquals(StartPoint) || point.IsIndexesEquals(EndPoint));
 }
Exemple #11
0
 public Dash(ref DashPoint start, ref DashPoint end)
 {
     StartPoint = start;
     EndPoint   = end;
 }
Exemple #12
0
 public bool IsIndexesEquals(DashPoint point)
 {
     return((IIndex == point.IIndex) && (JIndex == point.JIndex));
 }