示例#1
0
        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            int x = e.X / blockSize, y = e.Y / blockSize;

            if (nodeToolStripButton.Checked)
            {
                if (x >= 0 && x < mapWidth && y >= 0 && y < mapHeight)
                {
                    if (!map.Exists(x, y))
                    {
                        map.AddPosition(x, y);
                        drawNode_refreshTags(x, y);
                    }
                }
                return;
            }
            if (connectionToolStripButton.Checked)
            {
                if (connecting)
                {
                    connecting = false;
                    if (map.Exists(x, y) && map.Exists(x1, y1) && (x != x1 || y != y1))
                    {
                        map.AddConnection(x1, y1, x, y, (float)Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)));
                        ClearPath();
                        drawMap();
                    }
                    else
                    {
                        refreshBlock(x1, y1);
                    }
                }
                else
                {
                    if (map.Exists(x, y))
                    {
                        x1         = x;
                        y1         = y;
                        connecting = true;
                    }
                }
                return;
            }
            if (doubleConnectionToolStripButton.Checked)
            {
                if (connecting)
                {
                    connecting = false;
                    if (map.Exists(x, y) && map.Exists(x1, y1) && (x != x1 || y != y1))
                    {
                        map.AddDoubleConnection(x1, y1, x, y, (float)Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)));
                        ClearPath();
                        drawMap();
                    }
                    else
                    {
                        refreshBlock(x1, y1);
                    }
                }
                else
                {
                    if (map.Exists(x, y))
                    {
                        x1         = x;
                        y1         = y;
                        connecting = true;
                    }
                }
                return;
            }
            if (eraserToolStripButton.Checked)
            {
                if (map.Exists(x, y))
                {
                    IPosition_Connected p = map.GetPosition(x, y);
                    if (p == map.GetStartPosition())
                    {
                        map.ClearStartPosition();
                    }
                    if (p == map.GetEndPosition())
                    {
                        map.ClearEndPosition();
                    }
                    map.RemovePosition(x, y);
                    ClearPath();
                    drawMap();
                }
                return;
            }
            if (startPositionToolStripButton.Checked)
            {
                if (map.Exists(x, y))
                {
                    map.SetStartPosition(x, y);
                    ClearPath();
                    refreshTags();
                }
                return;
            }
            if (endPositionToolStripButton.Checked)
            {
                if (map.Exists(x, y))
                {
                    map.SetEndPosition(x, y);
                    ClearPath();
                    refreshTags();
                }
                return;
            }
        }