private void InitializeMap() { byte[] bmap = null; int startX = 0; int startY = 0; int endX = 0; int endY = 0; // m_nWidth = m_nCnstWidth; m_nHeight = m_nCnstHeight; // this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles(); // m_bmpDrawingSpace = new Bitmap(m_nWidth * m_nBlockPixel, m_nHeight * m_nBlockPixel); // if (DllAPI.RobotCreateEmptyMap(m_nWidth, m_nHeight, ref startX, ref startY, ref endX, ref endY) != 0) { return; } m_pntRobot.X = startX; m_pntRobot.Y = startY; m_pntEndPoint.X = endX; m_pntEndPoint.Y = endY; if (DllAPI.getMap(ref bmap) != 0) { return; } RePaint(bmap); ReSizeForm(); }
private void 随机生成地图ToolStripMenuItem_Click(object sender, EventArgs e) { byte[] bmap = null; int startX = 0; int startY = 0; int endX = 0; int endY = 0; ChangeState(State.Edit); // m_nWidth = m_nCnstWidth; m_nHeight = m_nCnstHeight; // if (DllAPI.RobotCreateRandomMap(m_nWidth, m_nHeight, ref startX, ref startY, ref endX, ref endY, 0.2f) != 0) { return; } m_pntRobot.X = startX; m_pntRobot.Y = startY; m_pntEndPoint.X = endX; m_pntEndPoint.Y = endY; if (DllAPI.getMap(ref bmap) != 0) { return; } RePaint(bmap); ReSizeForm(); this.Invalidate(); this.Update(); }
/// <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); }
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); }
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); }
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(); } }