Exemple #1
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;
            if (e.Button == MouseButtons.Left)
            {
                for (int widthTrav = 0; widthTrav < width; widthTrav++)
                {
                    for (int heightTrav = 0; heightTrav < height; heightTrav++)
                    {
                        if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
                        {
                            m_lastBoxType   = m_rectangles[widthTrav][heightTrav].boxType;
                            m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
                            switch (m_lastBoxType)
                            {
                            case BoxType.Normal:
                            case BoxType.Wall:
                                m_rectangles[widthTrav][heightTrav].SwitchBox();
                                this.Invalidate();

                                break;

                            case BoxType.Start:
                            case BoxType.End:

                                break;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
 private void Form1_MouseUp(object sender, MouseEventArgs e)
 {
     isMouseDown = false;
     if (e.Button == MouseButtons.Left)
     {
         m_lastBoxSelect = null;
     }
     //   Redraw();
 }
Exemple #3
0
 public GridLine(GridBox iFrom, GridBox iTo)
 {
     this.fromX = iFrom.boxRec.X + 4;
     this.fromY = iFrom.boxRec.Y + 4;
     this.toX   = iTo.boxRec.X + 4;
     this.toY   = iTo.boxRec.Y + 4;
     pen        = new Pen(Color.Yellow);
     pen.Width  = 2;
 }
Exemple #4
0
        private void Init()
        {
            DoubleBuffered = true;

            m_resultBox = new List <ResultBox>();
            Width       = (width + 1) * 10;
            Height      = (height + 1) * 10 + 100;
            MaximumSize = new Size(Width, Height);
            MaximizeBox = false;

            m_rectangles = new GridBox[width][];
            for (int widthTrav = 0; widthTrav < width; widthTrav++)
            {
                m_rectangles[widthTrav] = new GridBox[height];
                for (int heightTrav = 0; heightTrav < height; heightTrav++)
                {
                    if (widthTrav == 10 && heightTrav == 10)
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 10, heightTrav * 10 + 50, BoxType.Start);
                    }
                    else if (widthTrav == 100 && heightTrav == 50)
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 10, heightTrav * 10 + 50, BoxType.End);
                    }
                    else
                    {
                        m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 10, heightTrav * 10 + 50, BoxType.Normal);
                    }
                }
            }


            m_resultLine = new List <GridLine>();

            searchGrid = new StaticGrid(width, height);

            jumpParam = new AStarParam(searchGrid, 50, HeuristicMode.EUCLIDEAN);
        }
Exemple #5
0
        private void Import()
        {
            ofd_importmap.Filter   = "kagv Map (*.kmap)|*.kmap";
            ofd_importmap.FileName = "";

            if (ofd_importmap.ShowDialog() == DialogResult.OK)
            {
                bool   proceed = false;
                string line    = "";
                char[] sep     = { ':', ' ' };

                StreamReader reader = new StreamReader(ofd_importmap.FileName);
                do
                {
                    line = reader.ReadLine();
                    if (line.Contains("Width blocks:") && line.Contains("Height blocks:") && line.Contains("BlockSide:"))
                    {
                        proceed = true;
                    }
                } while (!(line.Contains("Width blocks:") && line.Contains("Height blocks:") && line.Contains("BlockSide:")) &&
                         !reader.EndOfStream);
                string[] lineArray = line.Split(sep);


                if (proceed)
                {
                    // FullyRestore();


                    char[] delim = { ' ' };
                    reader.ReadLine();
                    _importmap = new BoxType[width, height];
                    string[] words = reader.ReadLine().Split(delim);

                    for (int z = 0; z < _importmap.GetLength(0); z++)
                    {
                        int i = 0;
                        foreach (string s in words)
                        {
                            if (i < _importmap.GetLength(1))
                            {
                                if (s == "Start")
                                {
                                    _importmap[z, i] = BoxType.Start;
                                }
                                else if (s == "End")
                                {
                                    _importmap[z, i] = BoxType.End;
                                }
                                else if (s == "Normal")
                                {
                                    _importmap[z, i] = BoxType.Normal;
                                }
                                else if (s == "Wall")
                                {
                                    _importmap[z, i] = BoxType.Wall;
                                }
                                i++;
                            }
                        }
                        if (z == _importmap.GetLength(0) - 1)
                        {
                        }
                        else
                        {
                            words = reader.ReadLine().Split(delim);
                        }
                    }
                    reader.Close();


                    //  Init();

                    for (var widthTrav = 0; widthTrav < width; widthTrav++)
                    {
                        m_rectangles[widthTrav] = new GridBox[height];
                        for (var heightTrav = 0; heightTrav < height; heightTrav++)
                        {
                            m_rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * 10), heightTrav * 10 + 50, _importmap[widthTrav, heightTrav]);
                        }
                    }

                    Redraw();
                }
                else
                {
                    MessageBox.Show(this, "You have chosen an incompatible file import.\r\nPlease try again.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #6
0
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (m_lastBoxSelect == null)
                    {
                        for (int widthTrav = 0; widthTrav < width; widthTrav++)
                        {
                            for (int heightTrav = 0; heightTrav < height; heightTrav++)
                            {
                                if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
                                {
                                    m_lastBoxType   = m_rectangles[widthTrav][heightTrav].boxType;
                                    m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
                                    switch (m_lastBoxType)
                                    {
                                    case BoxType.Normal:
                                    case BoxType.Wall:
                                        m_rectangles[widthTrav][heightTrav].SwitchBox();
                                        this.Invalidate();
                                        break;

                                    case BoxType.Start:
                                    case BoxType.End:

                                        break;
                                    }
                                }
                            }
                        }

                        return;
                    }
                    else
                    {
                        for (int widthTrav = 0; widthTrav < width; widthTrav++)
                        {
                            for (int heightTrav = 0; heightTrav < height; heightTrav++)
                            {
                                if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
                                {
                                    if (m_rectangles[widthTrav][heightTrav] == m_lastBoxSelect)
                                    {
                                        return;
                                    }
                                    else
                                    {
                                        switch (m_lastBoxType)
                                        {
                                        case BoxType.Normal:
                                        case BoxType.Wall:
                                            if (m_rectangles[widthTrav][heightTrav].boxType == m_lastBoxType)
                                            {
                                                m_rectangles[widthTrav][heightTrav].SwitchBox();
                                                m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
                                                this.Invalidate();
                                            }
                                            break;

                                        case BoxType.Start:
                                            m_lastBoxSelect.SetNormalBox();
                                            m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
                                            m_lastBoxSelect.SetStartBox();
                                            this.Invalidate();
                                            break;

                                        case BoxType.End:
                                            m_lastBoxSelect.SetNormalBox();
                                            m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
                                            m_lastBoxSelect.SetEndBox();
                                            this.Invalidate();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //  Redraw();
            }
        }