public static MineTable CreateRandomTable(int height, int width, int mines) { MineTable mt = new MineTable(height, width, mines); int total = height*width; int[] arr = new int[total]; for (var i=0; i<total; i++) arr[i]=i; Random rd = new Random(); for (var i = 0; i < mines; i++) { var c = rd.Next(i, total); mt.SetStatus(arr[c]%width, arr[c]/width, CellStatus.Mine); if (c!=i) arr[c] = arr[i]; } mt.FullDe(); return mt; }
public MineMaker(Bitmap bitmap) { _bitmap = bitmap; if(_mi.GetTableInfo(bitmap, out width, out height, out il, out it, out iw, out ih)){ //Console.WriteLine("{0},{1}-({2},{3})", il, it, iw, ih); dw = 1.0f*iw/width; dh = 1.0f*ih/height; _mt = new MineTable(height, width); for (var i=0; i<height; i++) for (var j=0; j<width; j++) { CellStatus status; int n; _mi.GetCellInfo(GetGrid(j, i), out status, out n); _mt.SetStatus(j, i, status, n); } } }
public static MineTable CreateFixedTable() { MineTable mineTable = new MineTable(3, 3, 2); mineTable.SetStatus(0, 0, CellStatus.Ground, 1); mineTable.SetStatus(0, 1, CellStatus.Ground, 1); mineTable.SetStatus(1, 0, CellStatus.Ground, 1); mineTable.SetStatus(1, 1, CellStatus.Mine); //MineTable mt = new MineTable(9, 9, 10); //mt.SetStatus(2, 0, CellStatus.Mine); //mt.SetStatus(4, 0, CellStatus.Mine); //mt.SetStatus(5, 0, CellStatus.Mine); //mt.SetStatus(7, 0, CellStatus.Mine); //mt.SetStatus(3, 1, CellStatus.Mine); //mt.SetStatus(5, 2, CellStatus.Mine); //mt.SetStatus(5, 3, CellStatus.Mine); //mt.SetStatus(8, 4, CellStatus.Mine); //mt.SetStatus(0, 6, CellStatus.Mine); //mt.SetStatus(4, 8, CellStatus.Mine); return mineTable; }