C# 检查控制台应用程序中的冲突

C# 检查控制台应用程序中的冲突,c#,console-application,C#,Console Application,我现在正在学习一门课程,我需要代码方面的帮助 他们告诉我创建一个矩形类,然后创建一个包含一个矩形数组的类——我做得很好 问题是我需要建立一个方法来检查它们是否冲突。有人能帮我吗 public class Rectangle { public Point bottomRight; public Point topLeft; public ConsoleColor m_color; public int Width; public int Height;

我现在正在学习一门课程,我需要代码方面的帮助

他们告诉我创建一个矩形类,然后创建一个包含一个矩形数组的类——我做得很好

问题是我需要建立一个方法来检查它们是否冲突。有人能帮我吗

public class Rectangle
{
    public Point bottomRight;
    public Point topLeft;
    public ConsoleColor m_color;
    public int Width;
    public int Height;
    public int SurfaceArea;
    public int Perimeter;


    public Rectangle(Point tpLeft, Point btmRight, ConsoleColor clr)
    {
        if (tpLeft.X > 0 && tpLeft.Y > 0)
        {
            topLeft = tpLeft;
        }
        if (btmRight.X > 0 && btmRight.Y > 0)
        {
            bottomRight = btmRight;
        }
        m_color = clr;
        Width = bottomRight.X - topLeft.X;
        Height = Math.Abs(topLeft.Y - bottomRight.Y);
        SurfaceArea = Width * Height;
        Perimeter = 2 * (Width + Height);
    }
    public void Print()
    {
        Console.ForegroundColor = m_color;
        int c,a,b;
        for (c = 1; c < (topLeft.Y+1); c++)
        {
            Console.WriteLine();
        }
        for (c=0; c < Height; c++)
        {
            for (a = 0; a < topLeft.X; a++)
            {
                Console.Write(" ");
            }
            for (b=0; b < Width;b++)
            {
                    Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}

public class RectangleArray
{
    private Rectangle[] m_Arr;
    private int m_Counter;

    public RectangleArray()
    {
        m_Arr = new Rectangle[10];
    }

    public RectangleArray(int size)
    {
        if (size>10)
            m_ArR = new Rectangle[size];
        else
            Console.WriteLine("Error, size must be greater then zero");
    }

    public void Add(Rectangle r)
    {
        if (p == null)
            Console.WriteLine("Error, rectangle can't be null");
        if (m_Arr.Length <= m_Counter)
        {
            Array.Resize(ref m_Arr, m_Arr.Length + 10);
        }
        m_Arr[m_Counter++] = r;
    }

    public void CheckLegal(Rectangle r1, Rectangle r2)
    {

    }
}
公共类矩形
{
公共权利;
公共点左上角;
公共控制台颜色m_颜色;
公共整数宽度;
公众内部高度;
公共场所;
公共周界;
公共矩形(点tpLeft、点btmRight、控制台颜色clr)
{
如果(tpLeft.X>0&&tpLeft.Y>0)
{
左上=左上;
}
如果(btmRight.X>0&&btmRight.Y>0)
{
bottomRight=btmRight;
}
m_color=clr;
宽度=右下角.X-左上角.X;
高度=数学绝对值(左上角.Y-右下角.Y);
表面面积=宽度*高度;
周长=2*(宽度+高度);
}
公开作废印刷品()
{
Console.ForegroundColor=m_color;
INTC,a,b;
对于(c=1;c<(左上角.Y+1);c++)
{
Console.WriteLine();
}
对于(c=0;c10)
m_ArR=新矩形[尺寸];
其他的
Console.WriteLine(“错误,大小必须大于零”);
}
公共空白添加(矩形r)
{
if(p==null)
WriteLine(“错误,矩形不能为空”);

如果(m_Arr.Length)想一想两个矩形碰撞意味着什么。我建议你在纸上画很多矩形,碰撞的和非碰撞的,并想一想区别……如果你试图实现(但是
bool是相交的
version),那么如果你敢:)