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;
        }