Beispiel #1
0
        public void Show(SnakeJsonModel snake, double size)
        {
            foreach (var point in snake.Body)
            {
                AddSnakeSegment(point, CreateRectangle(point, size));
            }

            DrawEyes(snake);
        }
Beispiel #2
0
        public void Update(SnakeJsonModel snake, double size)
        {
            if (snake.IsDead)
            {
                snake.Body = new List <Point>();
            }
            var points         = snake.Body.ToHashSet();
            var pointsToAdd    = points.Except(rectangles.Keys).ToList();
            var pointsToRemove = rectangles.Keys.Except(points).ToList();

            foreach (var point in pointsToAdd)
            {
                AddSnakeSegment(point, CreateRectangle(point, size));
            }

            foreach (var point in pointsToRemove)
            {
                RemoveSnakeSegment(point);
            }

            DrawEyes(snake, true);
        }
Beispiel #3
0
        private void DrawEyes(SnakeJsonModel snake, bool update = false)
        {
            if (update)
            {
                foreach (var eye in eyes)
                {
                    canvas.Children.Remove(eye);
                }
            }

            var head = snake.Body.FirstOrDefault();

            if (head == null)
            {
                return;
            }

            UpdateEyes(new Point(head.X * 10, head.Y * 10), snake.Direction);
            foreach (var eye in eyes)
            {
                canvas.Children.Add(eye);
            }
        }