Example #1
0
        public void CreatePoint(int width, int heigth)
        {
            if (_lstDinh == null)
            {
                _lstDinh = new List <Dinh>();
            }
            int    nameUnicode = 65;
            int    bacCuaDinh, banBacVao = 0, banBacRa = 0;
            Dinh   item;
            Random rand  = new Random();
            Point  pRand = new Point();

            for (int i = 0; i < _soDinh; ++i)
            {
                pRand.X = rand.Next(width - 30);
                pRand.Y = rand.Next(heigth - 30);
                if (_coHuong)
                {
                    banBacVao = 0;
                    banBacRa  = 0;
                    for (int j = 0; j < _soDinh; ++j)
                    {
                        if (_maTran[i, j] != 0)
                        {
                            banBacRa++;
                        }
                        if (_maTran[j, i] != 0)
                        {
                            banBacVao++;
                        }
                    }
                    bacCuaDinh = banBacVao + banBacRa;
                    _tongBac  += bacCuaDinh;
                }
                else
                {
                    bacCuaDinh = 0;
                    for (int j = 0; j < _soDinh; ++j)
                    {
                        if (_maTran[i, j] != 0)
                        {
                            bacCuaDinh++;
                        }
                    }
                    _tongBac += bacCuaDinh;
                }
                item = new Dinh(((char)(nameUnicode + i)).ToString(), bacCuaDinh, banBacVao, banBacRa, pRand);
                lstDinh.Add(item);
            }
        }
Example #2
0
 private void pnlGraph_MouseDown(object sender, MouseEventArgs e)
 {
     mouseDownLocation = e.Location;
     isMouseDown       = true;
     if (tool == Tool.DiChuyen)
     {
         for (int i = 0; i < _doThi.soDinh; ++i)
         {
             int x = _doThi.lstDinh[i].pos.X;
             int y = _doThi.lstDinh[i].pos.Y;
             if (mouseDownLocation.X > x && mouseDownLocation.X < x + 30 &&
                 mouseDownLocation.Y > y && mouseDownLocation.Y < y + 30)
             {
                 curSelectedNode = i;
                 break;
             }
         }
     }
     if (tool == Tool.VeNode && mode == Mode.VeTrucTiep)
     {
         if (curNodeAmount == 0)
         {
             _doThi.lstDinh = new List <Dinh>();
         }
         Dinh dinh = new Dinh(((char)(nameUnicode + curNodeAmount)).ToString(), 0, 0, 0, e.Location);
         dinh.DrawNode(grs, sb);
         dinh.AddNodeName(grs);
         curNodeAmount++;
         _doThi.lstDinh.Add(dinh);
         if (_doThi.MaTranBangKhong())
         {
             _doThi.maTran = new int[curNodeAmount, curNodeAmount];
             for (int i = 0; i < curNodeAmount; ++i)
             {
                 for (int j = 0; j < curNodeAmount; ++j)
                 {
                     _doThi.maTran[i, j] = 0;
                 }
             }
         }
         else
         {
             int[,] temMatrix = new int[curNodeAmount - 1, curNodeAmount - 1];
             for (int i = 0; i < curNodeAmount - 1; ++i)
             {
                 for (int j = 0; j < curNodeAmount - 1; ++j)
                 {
                     temMatrix[i, j] = _doThi.maTran[i, j];
                 }
             }
             _doThi.maTran = new int[curNodeAmount, curNodeAmount];
             for (int i = 0; i < curNodeAmount - 1; ++i)
             {
                 for (int j = 0; j < curNodeAmount - 1; ++j)
                 {
                     _doThi.maTran[i, j] = temMatrix[i, j];
                 }
             }
         }
         _doThi.soDinh = curNodeAmount;
     }
     if (tool == Tool.VeCanh)
     {
         for (int i = 0; i < curNodeAmount; ++i)
         {
             int x = _doThi.lstDinh[i].pos.X;
             int y = _doThi.lstDinh[i].pos.Y;
             if (mouseDownLocation.X > x && mouseDownLocation.X < x + 30 &&
                 mouseDownLocation.Y > y && mouseDownLocation.Y < y + 30)
             {
                 nodeDau = i;
                 break;
             }
         }
     }
 }