Пример #1
0
 public void SaveToFile(Sudokee skd, string path)
 {
     FileStream fs = null;
     try
     {
         fs = new FileStream(path, FileMode.Create);
         using (var sw = new StreamWriter(fs))
         {
             fs = null;
             sw.WriteLine(skd.BaseSize);
             int l = skd.Size;
             for (var i = 0; i < l; i++)
             {
                 sw.Write(skd[0, i]);
                 for (var j = 1; j < l; j++)
                     sw.Write(",{0}", skd[j, i]);
                 sw.WriteLine();
             }
         }
     }
     finally
     {
         if (fs != null)
             fs.Dispose();
     }
 }
Пример #2
0
        public Sudokee LoadFromFile(string path)
        {
            FileStream fs = null;
            try
            {
                fs = new FileStream(path, FileMode.Open);
                using (var sw = new StreamReader(fs))
                {
                    fs = null;
                    var ba = int.Parse(sw.ReadLine());
                    var si = ba * ba;
                    var s = new Sudokee(ba);

                    for (var i = 0; i < si; i++)
                    {
                        var line = sw.ReadLine();
                        var data = line.Split(',');
                        var dat = data.Select(item => int.Parse(item));
                        int j = 0;
                        foreach (var item in dat)
                        {
                            if (item > 0) s[j, i] = item;
                            j++;
                        }
                    }
                    return s;
                }
            }
            finally
            {
                if (fs != null)
                    fs.Dispose();
            }
        }
Пример #3
0
 static void Main(string[] args)
 {
     var a = new Sudokee(3);
     Console.WriteLine(a);
     //a[2, 1] = 1;
     //var sm = SudokuManager.Instance;
     //sm.SaveToFile(a,fp);
     //var b = sm.LoadFromFile(fp);
     //Console.WriteLine(b);
 }
Пример #4
0
        public SudokuBoard(UIElementCollection coll)
        {
            string file = @"g:\1.txt";
            try
            {
                sudokee = sm.LoadFromFile(file);
            }
            catch (Exception)
            {
                MessageBox.Show("Error during loading.", "Error");
            }

            cell = new SudokuCell(coll,sudokee.BaseSize,this);
        }