Exemplo n.º 1
0
        public int GetWallDistance(Direction direction)
        {
            switch (direction)
            {
            case Direction.Left:
                return(SnakeHead.GetPosition().X);

            case Direction.Right:
                return(_gameSize.Width - SnakeHead.GetPosition().X);

            case Direction.Up:
                return(SnakeHead.GetPosition().X);

            case Direction.Down:
                return(_gameSize.Height - SnakeHead.GetPosition().Y);

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
        }
Exemplo n.º 2
0
        public int GetFoodDistance(Direction direction)
        {
            int FixNegative(int value) => value < 0 ? Math.Abs(value) * 2 : value;

            switch (direction)
            {
            case Direction.Left:
                return(FixNegative(SnakeHead.GetPosition().X - CurrentFood.GetPosition().X));

            case Direction.Right:
                return(FixNegative(CurrentFood.GetPosition().X - SnakeHead.GetPosition().X));

            case Direction.Up:
                return(FixNegative(SnakeHead.GetPosition().Y - CurrentFood.GetPosition().Y));

            case Direction.Down:
                return(FixNegative(CurrentFood.GetPosition().Y - SnakeHead.GetPosition().Y));

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
        }