コード例 #1
0
 public Cell[] readGrid()
 {
     Cell[] array = new Cell[81];
     for (int i = 0; i < 9; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             array[i * 9 + j] = new Cell(i, j);
             array[i * 9 + j].currentCellState = CellState.Safe;
         }
     }
     return array;
 }
コード例 #2
0
 public Cell[] readGrid()
 {
     if (!Directory.Exists(Environment.SpecialFolder.System + ""))
     {
         createPath();
     }
     if (!File.Exists(Environment.SpecialFolder.System + @"\testarray.txt"))
     {
         createGrid();
     }
     Cell[] array = new Cell[81];
     FileStream fs = new FileStream(Environment.SpecialFolder.System + @"\testarray.txt", FileMode.Open, FileAccess.Read);
     StreamReader sr = new StreamReader(fs);
     int num;
     for (int i = 0; i < 9; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             if (int.TryParse(sr.ReadLine(), out num))
             {
                 array[i * 9 + j] = new Cell(i, j);
                 if (num == 1)
                 {
                     array[i * 9 + j].currentCellState = CellState.Bomb;
                 }
                 else if (num == 0)
                 {
                     array[i * 9 + j].currentCellState = CellState.Safe;
                 }
                 else
                 {
                     throw new Exception("Wrong number in file");
                 }
             }
             else
             {
                 throw new Exception("Couldn' t parse line in num, line");
             }
         }
     }
     sr.Close();
     fs.Close();
     return array;
 }