openchess_Click() 打不开 savechess_Click()中保存的棋局,大概结构是这样的
namespace 练习1
{
class public partial class Form1 : Form
{
private void savechess_Click(object sender, EventArgs e)
{
SaveFileDialog s = new SaveFileDialog();
s.Filter = "五子棋|*.wzq";
s.ShowDialog();
FileStream fs = new FileStream(s.FileName, FileMode.Create, FileAccess.Write);
Chess c = new Chess(chesslist, formqipan);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, c);
fs.Close();
}
private void openchess_Click(object sender, EventArgs e)
{
OpenFileDialog o = new OpenFileDialog();
o.Filter = "五子棋|*.wzq";
if (o.ShowDialog() == DialogResult.OK)
{
FileStream fs = new FileStream(o.FileName, FileMode.Open, FileAccess.Read);
//Chess c = new Chess(chesslist, formqipan);
BinaryFormatter bf = new BinaryFormatter();
Chess c = (Chess)bf.Deserialize(fs);
fs.Close();
}
Invalidate();
}
}
[Serializable]
public struct Point
{
public int X;
public int Y;
}
[Serializable]
class Chess
{
public int width = 640;
public int height = 600;
public ChessState[,] qipan = new ChessState[15, 15];
public List<Point> pointlist = new List<Point>(500);
public Chess(List<Point> l, ChessState[,] fq)
{
pointlist = l;
qipan = fq;
}
}
}