Ejemplo n.º 1
0
        public bool WalkSnake()
        {
            var newX = _snake.Head.X;
            var newY = _snake.Head.Y;

            switch (_snake.Facing)
            {
            case Direction.North:
                newY--;
                break;

            case Direction.South:
                newY++;
                break;

            case Direction.West:
                newX--;
                break;

            case Direction.East:
                newX++;
                break;

            default:
                break;
            }


            if (_snake.IsSnake(newX, newY) || IsWall(newX, newY))
            {
                return(false);
            }

            _snake.AddNewHead(newX, newY);
            _drawSnakeHead(_snake);

            if (newX == _food.X && newY == _food.Y)
            {
                MoveFood();
                _drawFood(_food);
            }
            else
            {
                _removeSnakeTail(_snake);
                _snake.Tail = _snake.Tail.Next;
            }

            return(true);
        }