Exemplo n.º 1
0
        public SnakeHead CalculateNewSnakeHead(Position nextDirection)
        {
            var       head         = this.Items.Last();
            var       position     = new Position(head.Position.x + nextDirection.x, head.Position.y + nextDirection.y);
            SnakeHead snakeNewHead = new SnakeHead(position);

            var finalPosition = snakeNewHead.Position;

            if (snakeNewHead.Position.y < 0)
            {
                finalPosition.y = Console.WindowWidth - 1;
            }
            if (snakeNewHead.Position.x < 0)
            {
                finalPosition.x = Console.WindowHeight - 1;
            }
            if (snakeNewHead.Position.x >= Console.WindowHeight)
            {
                finalPosition.x = 0;
            }
            if (snakeNewHead.Position.y >= Console.WindowWidth)
            {
                finalPosition.y = 0;
            }

            snakeNewHead.Position = finalPosition;

            return(snakeNewHead);
        }
Exemplo n.º 2
0
 public void UpdateHead(SnakeHead snakeHead)
 {
     this.sneakHead            = snakeHead;
     this.Items.Last().Display = GameDisplay.SnakeBody;
     ((Queue <GameObject>) this.Items).Enqueue(snakeHead);
 }