Example #1
0
        private void AddRect_Click(object sender, EventArgs e)
        {
            AddRectangle AddRectangles = new AddRectangle();

            if (AddRectangles.ShowDialog() == DialogResult.OK)
            {
                Obstacles NewOb = new Obstacles();

                NewOb.Xvel = Convert.ToInt32(AddRectangles.XVelocity);
                NewOb.Yvel = Convert.ToInt32(AddRectangles.YVelocity);
                NewOb.p1.X = Convert.ToInt32(AddRectangles.X1);
                NewOb.p2.X = Convert.ToInt32(AddRectangles.X2);
                NewOb.p3.X = Convert.ToInt32(AddRectangles.X3);
                NewOb.p4.X = Convert.ToInt32(AddRectangles.X4);
                NewOb.p1.Y = Convert.ToInt32(AddRectangles.Y1);
                NewOb.p2.Y = Convert.ToInt32(AddRectangles.Y2);
                NewOb.p3.Y = Convert.ToInt32(AddRectangles.Y3);
                NewOb.p4.Y = Convert.ToInt32(AddRectangles.Y4);

                SqObst.Add(NewOb);
            }
            else
            {
                return;
            }
        }
Example #2
0
        private int[,] MapBuild()
        {
            int width  = pictureBox1.Width / set + 1;
            int height = pictureBox1.Height / set + 1;

            int[,] Map = new int[width, height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    int close = 0;
                    foreach (Obstacles obst in SqObst)
                    {
                        Obstacles NewOb = new Obstacles();

                        NewOb.Xvel = obst.Xvel;
                        NewOb.Yvel = obst.Yvel;
                        NewOb.p1.X = obst.p1.X;
                        NewOb.p2.X = obst.p2.X;
                        NewOb.p3.X = obst.p3.X;
                        NewOb.p4.X = obst.p4.X;
                        NewOb.p1.Y = obst.p1.Y;
                        NewOb.p2.Y = obst.p2.Y;
                        NewOb.p3.Y = obst.p3.Y;
                        NewOb.p4.Y = obst.p4.Y;


                        if (cross(NewOb.p1.X, NewOb.p1.Y, NewOb.p2.X, NewOb.p2.Y, i * set, j * set, i * set + set, j * set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p2.X, NewOb.p2.Y, NewOb.p3.X, NewOb.p3.Y, i * set, j * set, i * set + set, j * set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p3.X, NewOb.p3.Y, NewOb.p4.X, NewOb.p4.Y, i * set, j * set, i * set + set, j * set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p4.X, NewOb.p4.Y, NewOb.p1.X, NewOb.p1.Y, i * set, j * set, i * set + set, j * set) == true)
                        {
                            close++;
                        }

                        if (cross(NewOb.p1.X, NewOb.p1.Y, NewOb.p2.X, NewOb.p2.Y, i * set + set, j * set, i * set + set, j * set + set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p2.X, NewOb.p2.Y, NewOb.p3.X, NewOb.p3.Y, i * set + set, j * set, i * set + set, j * set + set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p3.X, NewOb.p3.Y, NewOb.p4.X, NewOb.p4.Y, i * set + set, j * set, i * set + set, j * set + set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p4.X, NewOb.p4.Y, NewOb.p1.X, NewOb.p1.Y, i * set + set, j * set, i * set + set, j * set + set) == true)
                        {
                            close++;
                        }

                        if (cross(NewOb.p1.X, NewOb.p1.Y, NewOb.p2.X, NewOb.p2.Y, i * set + set, j * set + set, i * set, j * set + set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p2.X, NewOb.p2.Y, NewOb.p3.X, NewOb.p3.Y, i * set + set, j * set + set, i * set, j * set + set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p3.X, NewOb.p3.Y, NewOb.p4.X, NewOb.p4.Y, i * set + set, j * set + set, i * set, j * set + set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p4.X, NewOb.p4.Y, NewOb.p1.X, NewOb.p1.Y, i * set + set, j * set + set, i * set, j * set + set) == true)
                        {
                            close++;
                        }

                        if (cross(NewOb.p1.X, NewOb.p1.Y, NewOb.p2.X, NewOb.p2.Y, i * set, j * set + set, i * set, j * set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p2.X, NewOb.p2.Y, NewOb.p3.X, NewOb.p3.Y, i * set, j * set + set, i * set, j * set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p3.X, NewOb.p3.Y, NewOb.p4.X, NewOb.p4.Y, i * set, j * set + set, i * set, j * set) == true)
                        {
                            close++;
                        }
                        if (cross(NewOb.p4.X, NewOb.p4.Y, NewOb.p1.X, NewOb.p1.Y, i * set, j * set + set, i * set, j * set) == true)
                        {
                            close++;
                        }
                    }
                    if (close == 0)
                    {
                        Map[i, j] = 1;
                    }
                    else
                    {
                        Map[i, j] = 0;
                    }
                }
            }

            for (int i = 0; i < width; i++)
            {
                Map[i, 0]          = 0;
                Map[i, height - 1] = 0;
            }
            for (int j = 0; j < height; j++)
            {
                Map[0, j]         = 0;
                Map[width - 1, j] = 0;
            }
            //1 - ячейка свободна
            //0 - ячейка занята
            return(Map);
        }