//写DAT二进制文件 //参数1:文件名(包含文件路径) //参数2:需要写入的数据 public static void WritePosData(string FileName, mPostion WriteData) { int Filenumber = 0; try { Filenumber = FileSystem.FreeFile(); //获取空闲可用的文件号 FileSystem.FileOpen(Filenumber, FileName, OpenMode.Binary); //以二进制的形式打开文件 //long lens = FileSystem.LOF(Filenumber); FileSystem.FilePut(Filenumber, WriteData); FileSystem.FileClose(Filenumber); //写入完成关闭当前打开的文件 } catch { FileSystem.FileClose(Filenumber); //写入出错关闭当前打开的文件 } }
//读DAT二进制文件 //参数1:文件名(包含文件路径) //参数2:读取的数据存储地址 public static void ReadPosData(string FileName, System.ValueType ReadData) { int Filenumber = 0; ReDimData(); try { Filenumber = FileSystem.FreeFile(); //获取空闲可用的文件号 Microsoft.VisualBasic.FileSystem.FileOpen(Filenumber, FileName, OpenMode.Binary); //以二进制的形式打开文件 FileSystem.FileGet(Filenumber, ref ReadData); mFunction.Pos = (mFunction.mPostion)ReadData; Microsoft.VisualBasic.FileSystem.FileClose(Filenumber); //读取完成关闭当前打开的文件 PVar.IsReadPosData = true; } catch { FileSystem.FileClose(Filenumber); //读取出错关闭当前打开的文件 } }
void GenerateMap() { List <mPostion> paths = new List <mPostion>(); //save stepped positions. Means this is PATH. List <mPostion> walls = new List <mPostion>(); //save wall positions. int startX = UnityEngine.Random.Range(0, row); int startY = UnityEngine.Random.Range(0, col); //Generate paths for (int i = 0; i < chooseStartTimes; ++i) { //after first loop, choose one path tile as start point. if (i != 0 && paths.Count != 0) { mPostion tempStart = paths[UnityEngine.Random.Range(paths.Count * 99 / 100, paths.Count)]; startX = tempStart.x; startY = tempStart.y; } int curX = startX, curY = startY; for (int j = 0; j < initPathTimes; ++j) { int dir = UnityEngine.Random.Range(0, 4); for (int k = 0; k < PathLength; ++k) { //random dir if (dir == 0) { curX = curX - 1; } else if (dir == 1) { curX = curX + 1; } else if (dir == 2) { curY = curY - 1; } else if (dir == 3) { curY = curY + 1; } //detect out of edge if (curY < 0) { curY = 0; break; } if (curY >= col) { curY = col - 1; break; } if (curX < 0) { curX = 0; break; } if (curX >= row) { curX = row - 1; break; } //Init Path and put it in Paths list mPostion temp = new mPostion(curX, curY); paths.Add(temp); } } } //Mark mapArray for (int i = 0; i < paths.Count; ++i) { mPostion tempPos = paths[i]; mapArray[tempPos.x, tempPos.y] = Tile.Floor; if (i == 0) { GameController.instance.SetPlayerPositon(tempPos.x, tempPos.y); } } //Init Map for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { if (mapArray[i, j] == Tile.Floor) { PutObjectAt(floorTiles, i, j); } else if (mapArray[i, j] == Tile.Wall) { PutObjectAt(outerWallTiles, i, j); } } } }