public void Show(SnakeJsonModel snake, double size) { foreach (var point in snake.Body) { AddSnakeSegment(point, CreateRectangle(point, size)); } DrawEyes(snake); }
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); }
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); } }