Пример #1
0
        public void drawPathFromPoints(IList <C2DPoint> points)
        {
            C2DPoint previous = null;

            if (points?.Count < 2)
            {
                return;
            }
            if (viewModel.IsFirstPoint && viewModel.StartingPoint != null)
            {
                previous = viewModel.StartingPoint;
            }
            else
            {
                previous = points[0];
            }
            for (var i = 1; i < points.Count; ++i)
            {
                var temp = new Line();
                temp.Stroke          = Brushes.Black;
                temp.StrokeThickness = 2;
                temp.X1  = previous.X;
                temp.Y1  = previous.Y;
                temp.X2  = points[i].X;
                temp.Y2  = points[i].Y;
                previous = points[i];
                canvas.Children.Add(temp);
            }
            viewModel.Points = points.ToList();
        }
Пример #2
0
    void makeMove(C2DPoint pos, Constants.StoneColor color, List <C2DHoledPolyArc> blackShape, List <C2DHoledPolyArc> whiteShape)
    {
        C2DHoledPolyArc stoneShape = makeCircle(pos, 1);

        List <C2DHoledPolyArc> ownShape;

        if (color == Constants.StoneColor.Black)
        {
            ownShape = blackShape;
        }
        else
        {
            ownShape = whiteShape;
        }

        List <C2DHoledPolyArc> shapesToMerge = new List <C2DHoledPolyArc> ();

        foreach (C2DHoledPolyArc poly in ownShape)
        {
            if (poly.Overlaps(stoneShape))
            {
                shapesToMerge.Add(poly);
            }
        }

        merge(stoneShape, shapesToMerge, ownShape);
    }
Пример #3
0
 void afterMove(C2DPoint pos, Constants.StoneColor color)
 {
     forbiddenShapes.Add(makeCircle(pos, Constants.stoneSize));
     if (color == Constants.StoneColor.Black)
     {
         toPlay = Constants.StoneColor.White;
     }
     else
     {
         toPlay = Constants.StoneColor.Black;
     }
     Debug.Log(blackShape.Count);
     Debug.Log(whiteShape.Count);
 }
Пример #4
0
    public bool addStone(C2DPoint pos)
    {
        Constants.StoneColor color = toPlay;
        //TODO: copy here
        List <C2DHoledPolyArc> _blackShape = blackShape;
        List <C2DHoledPolyArc> _whiteShape = whiteShape;

        if (HasPlace(pos) && isLegal(pos, color, _blackShape, _whiteShape))
        {
            makeMove(pos, color, blackShape, whiteShape);
            afterMove(pos, color);
            return(true);
        }
        return(false);
    }
Пример #5
0
    C2DHoledPolyArc makeCircle(C2DPoint pos, float radius)
    {
        C2DPolyArc shape = new C2DPolyArc();

        shape.SetStartPoint(new C2DPoint(pos.x + radius, pos.y));

        for (int i = 0; i < 16; i++)
        {
            shape.LineTo(new C2DPoint(pos.x + Mathf.Cos(Mathf.PI * 2 * i / 16) * radius, pos.y + Mathf.Sin(Mathf.PI * 2 * i / 16) * radius), radius, false, true);
        }
        shape.Close(radius, false, true);

        C2DHoledPolyArc result = new C2DHoledPolyArc();

        result.Rim = shape;
        return(result);
    }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        if (guiController.IsMenu())
        {
            return;
        }

        var screenPos = Camera.main.ScreenToWorldPoint(inputController.GetPosition());
        var worldPos  = new Vector3(screenPos.x, screenPos.y, -2);

        if (inputController.IsEventStart())
        {
            if (_stone == null)
            {
                _stone = GameObjectManager.CreateStone(logicController.toPlay, worldPos);
            }
        }
        else
        {
            if (_stone != null)
            {
                _stone.transform.localPosition          = worldPos;
                _stone.GetComponent <StoneView>().Legal = logicController.HasPlace(new C2DPoint(worldPos.x, worldPos.y));

                if (inputController.IsEventEnd())
                {
                    var point = new C2DPoint(_stone.transform.position.x,
                                             _stone.transform.position.y);
                    if (logicController.addStone(point))
                    {
                        networkController.SendPoint(point);
                        _stone.transform.localPosition = new Vector3(worldPos.x, worldPos.y, 0);
                        _stone.GetComponent <StoneView>().HideBackground();
                        _stone = null;
                    }
                    else
                    {
                        GameObject.Destroy(_stone);
                    }
                }
            }
        }
    }
Пример #7
0
        public void SnapToOriginInPlace(IList <C2DPoint> input)
        {
            var minXy = MinMax(input);

            for (var i = 0; i < input.Count; ++i)
            {
                input[i] = new C2DPoint(input[i].X - minXy.Item1, input[i].Y - minXy.Item2);
            }
            var poly = new C2DPolygon(input.ToList(), true);

            poly.RandomPerturb();
            var pointsCopy = new C2DPointSet();

            poly.GetPointsCopy(pointsCopy);
            for (var i = 0; i < pointsCopy.Count; ++i)
            {
                input[i] = pointsCopy[i];
            }
        }
Пример #8
0
 /// <summary>
 /// Distance to a point
 /// </summary>
 public abstract double Distance(C2DPoint Point);
Пример #9
0
 /// <summary>
 /// Reflection in a point
 /// </summary>
 public abstract void Reflect(C2DPoint Point);
Пример #10
0
 /// <summary>
 /// Grows the entity
 /// </summary>
 public abstract void Grow(double dFactor, C2DPoint Origin);
Пример #11
0
 /// <summary>
 /// Rotates this to the right about the origin provided.
 /// </summary>
 /// <param name="dAng">The angle through which to rotate.</param>
 /// <param name="Origin">The origin about which to rotate.</param>
 public abstract void RotateToRight(double dAng, C2DPoint Origin);
Пример #12
0
 public void SendPoint(C2DPoint point)
 {
     networkView.RPC("ReceivePoint", RPCMode.Others, (float)point.x, (float)point.y);
 }
Пример #13
0
 bool isLegal(C2DPoint pos, Constants.StoneColor color, List <C2DHoledPolyArc> _blackShape, List <C2DHoledPolyArc> _whiteShape)
 {
     return(true);
 }
Пример #14
0
 public bool HasPlace(C2DPoint pos)
 {
     return(!forbiddenShapes.Any((shape) => shape.Contains(pos)));
 }