C#C
C#4y ago
Xellez

❔ Is this the right way to implement an Interface

    interface IObstacles
    {
        void Draw(Graphics g);
    }

    class Redbox : IObstacles
    {
        Pen Pen = new Pen(Color.Red);

        Random Random = new Random();
        Position Position;

        float width;
        float height;

        public Redbox(float x, float y)
        {
            Position = new Position(x, y);

            width = Random.Next(30, 100);
            height = Random.Next(30, 100);
        }


        public void Draw(Graphics g)
        {
            g.DrawRectangle(Pen, Position.X , Position.Y, width, height);
        }
    }

    class Bluebox: IObstacles
    {
        Pen Pen = new Pen(Color.Blue);

        Random Random = new Random();
        Position Position;

        float width;
        float height;

        public Bluebox(float x, float y)
        {
            Position = new Position(x, y);

            width = Random.Next(30, 100);
            height = Random.Next(30, 100);
        }

        public void Draw(Graphics g)
        {
            g.DrawRectangle(Pen, Position.X, Position.Y, width, height);
        }

    }

    class VerticaLine : IObstacles
    {
        Pen Pen = new Pen(Color.Yellow);

        Position Position;

        float Radius;

        public VerticaLine(float x, float y, float radius)
        {
            Position = new Position(x, y);
            Radius = radius;
        }

        public void Draw(Graphics g)
        {
            g.DrawLine(Pen, Position.X, Position.Y, Position.X, Radius);
        }
    }

    class HorizonaLine : IObstacles 
    {
        Pen Pen = new Pen(Color.Green);

        Position Position;

        float Radius;

        public HorizonaLine(float x, float y, float radius)
        {
            Position = new Position(x, y);
            Radius = radius;
        }

        public void Draw(Graphics g)
        {
            g.DrawLine(Pen, Position.X, Position.Y, Radius, Position.Y);
        }
    }
Was this page helpful?