public static SlitherlinkPuzzle FromTXT(StreamReader inputStream) { SlitherlinkPuzzle puzzle; { string[] dim = inputStream.ReadLine().Split(' '); puzzle = new SlitherlinkPuzzle(int.Parse(dim[0]), int.Parse(dim[1])); puzzle.Hint = new int[puzzle.X + 2, puzzle.Y + 2]; for (int i = 0; i <= puzzle.X + 1; ++i) { for (int j = 0; j <= puzzle.Y + 1; ++j) { puzzle.Hint[i, j] = -1; } } for (int i = 1; i <= puzzle.X; ++i) { string[] source = inputStream.ReadLine().Split(' '); for (int j = 1; j <= puzzle.Y; ++j) { if (source[j - 1][0] != '-') { puzzle.Hint[i, j] = int.Parse(source[j - 1]); } } } puzzle.factPool = new FactPool(puzzle); //xr.ReadToFollowing("solution"); //MessageBox.Show(xr.ReadElementString()); } return(puzzle); }
private void button7_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { using (StreamReader sr = new StreamReader(openFileDialog1.FileName)) { slp = null; slp = SlitherlinkPuzzle.FromXML(sr); } button1_Click(null, null); engine = null; } catch { MessageBox.Show("文件不存在或文件格式不正确!"); } } }
void LoadByID(string id) { if (id == null) { id = "test.txt"; } else { throw new NotSupportedException(); } //try { using (StreamReader sr = new StreamReader(id)) { slp = SlitherlinkPuzzle.FromTXT(sr); } button1_Click(null, null); engine = null; } //catch { } }