Exemplo n.º 1
0
        /// <summary>
        /// 只需要对Blank和Wall更新,Robot和EndPoint用SetRobotPoint/SetEndPoint就行了
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static int UpdateMap(int x, int y, byte data)
        {
            IntPtr pMap    = IntPtr.Zero;
            int    _width  = DllAPI.getWidth();
            int    _height = DllAPI.getHeight();

            if (x < 0 || x >= _width)
            {
                return(-1);
            }
            if (y < 0 || y >= _height)
            {
                return(-1);
            }
            DllAPI.getMap(ref pMap);
            Marshal.WriteByte(pMap, x + y * _width, data);
            return(0);
        }
Exemplo n.º 2
0
        public static int ReadMapByte(int x, int y, ref byte data)
        {
            IntPtr pMap    = IntPtr.Zero;
            int    _width  = DllAPI.getWidth();
            int    _height = DllAPI.getHeight();

            if (x < 0 || x >= _width)
            {
                return(-1);
            }
            if (y < 0 || y >= _height)
            {
                return(-1);
            }
            DllAPI.getMap(ref pMap);
            data = Marshal.ReadByte(pMap, x + y * _width);
            return(0);
        }
Exemplo n.º 3
0
        public static int getMap(ref byte[] bmap)
        {
            int    nRet;
            IntPtr pMap = IntPtr.Zero;
            int    nLen = DllAPI.getWidth() * DllAPI.getHeight();

            if (nLen <= 0)
            {
                return(1);
            }
            bmap = new byte[nLen];
            if ((nRet = DllAPI.getMap(ref pMap)) != 0)
            {
                return(nRet);
            }
            Marshal.Copy(pMap, bmap, 0, nLen);
            return(0);
        }
        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            string         filePath;

            byte[] bMap = null;
            int    startX = 0, startY = 0, endX = 0, endY = 0;

            //
            ChangeState(State.Edit);
            //
            dialog.Filter           = "地图文件|*.mp|所有文件|*.*";
            dialog.CheckFileExists  = true;
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                filePath = dialog.FileName;
                DllAPI.RobotLoadMap(filePath, ref startX, ref startY, ref endX, ref endY);
                m_pntRobot.X    = startX;
                m_pntRobot.Y    = startY;
                m_pntEndPoint.X = endX;
                m_pntEndPoint.Y = endY;
                m_nWidth        = DllAPI.getWidth();
                m_nHeight       = DllAPI.getHeight();
                if (DllAPI.getMap(ref bMap) != 0)
                {
                    return;
                }
                //
                m_bmpDrawingSpace = new Bitmap(m_nWidth * m_nBlockPixel, m_nHeight * m_nBlockPixel);
                //
                RePaint(bMap);
                ReSizeForm();
                this.Invalidate();
                this.Update();
            }
        }