Exemple #1
0
        public void Move()
        {
            var newHead = GetNewHead();

            // If an object on the ground exists, interact with it.
            Arena.GetCell(newHead.X, newHead.Y)?.Interact(this);

            // Set the currently visited cell as the player's.
            Arena.UpdateCell(newHead.X, newHead.Y, new SnekBody(Color, this, Body.AddLast(newHead)));

            // Free the tail cell if snake is not growing.
            var tail = Body.First.Value;

            if (Growth > 0)
            {
                Growth--;
            }
            else
            {
                Arena.UpdateCell(tail.X, tail.Y, null);
                Body.RemoveFirst();
            }

            CurrentDirection = NextDirection;
        }
Exemple #2
0
        public void TrimTail(LinkedListNode <Point> cutoffPoint)
        {
            // Trim the list until snake was eaten
            while (Body.First != cutoffPoint && Body.Last?.Previous != null)
            {
                var cell = Body.First.Value;
                Body.RemoveFirst();
                Arena.UpdateCell(cell.X, cell.Y, null);
            }

            // Trim it once more, because it was trimmed up until the trim point. Exempt if it would obliterate the snake.
            if (Body.Last?.Previous != null)
            {
                var cell = Body.First.Value;
                Body.RemoveFirst();
                Arena.UpdateCell(cell.X, cell.Y, null);
            }
        }