在控制台应用程序中检查碰

时间:2015-07-03 11:34:17

标签: c# console-application

我现在正在修课程,我需要帮助代码。

他们告诉我创建一个Rectangles类,然后创建一个包含矩形数组的类 - 我做的没那么。

问题是我需要构建一个方法来检查它们是否发生碰撞。有人能帮助我吗?

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)
    {

    }
}

0 个答案:

没有答案