Пример #1
0
        private void RemoveSnakeSegment(Point point)
        {
            var rectangle = rectangles[point];

            canvas.Children.Remove(rectangle);
            rectangles.Remove(point);
        }
Пример #2
0
        private static Point[] GetEyesPoints(Point point, SnakeDirection direction)
        {
            Point TopLeft() => new Point(point.X + 1, point.Y + 1);
            Point TopRight() => new Point(point.X + 7, point.Y + 1);
            Point BottomLeft() => new Point(point.X + 1, point.Y + 7);
            Point BottomRight() => new Point(point.X + 7, point.Y + 7);

            if (direction == SnakeDirection.Up)
            {
                return new[] { TopLeft(), TopRight() }
            }
            ;
            if (direction == SnakeDirection.Down)
            {
                return new[] { BottomLeft(), BottomRight() }
            }
            ;
            if (direction == SnakeDirection.Left)
            {
                return new[] { TopLeft(), BottomLeft() }
            }
            ;
            return(new[] { TopRight(), BottomRight() });
        }
    }
}
Пример #3
0
        private void UpdateEyes(Point point, SnakeDirection direction)
        {
            var eye1 = new Ellipse
            {
                Width  = 2,
                Height = 2,
                Fill   = new SolidColorBrush(Colors.Black)
            };
            var eye2 = new Ellipse
            {
                Width  = 2,
                Height = 2,
                Fill   = new SolidColorBrush(Colors.Black)
            };
            var points = GetEyesPoints(point, direction);
            var point1 = points[0];
            var point2 = points[1];

            Canvas.SetTop(eye1, point1.Y);
            Canvas.SetLeft(eye1, point1.X);
            Canvas.SetZIndex(eye1, 1);
            Canvas.SetTop(eye2, point2.Y);
            Canvas.SetLeft(eye2, point2.X);
            Canvas.SetZIndex(eye2, 1);
            eyes[0] = eye1;
            eyes[1] = eye2;
        }
Пример #4
0
        private Rectangle CreateRectangle(Point point, double size)
        {
            var rectangle = new Rectangle
            {
                Width           = size,
                Height          = size,
                Fill            = new SolidColorBrush(color),
                Stroke          = new SolidColorBrush(Colors.Black),
                StrokeThickness = 0.2,
                RadiusX         = size / 3,
                RadiusY         = size / 3,
                Opacity         = 0.75
            };

            Canvas.SetTop(rectangle, point.Y * size);
            Canvas.SetLeft(rectangle, point.X * size);
            return(rectangle);
        }
Пример #5
0
 private void AddSnakeSegment(Point point, Rectangle rectangle)
 {
     canvas.Children.Add(rectangle);
     rectangles[point] = rectangle;
 }