用c#编程,怎么实现取档和保存游戏。我想实现保存用户下次再耍还能继续
命名空间:using System.IO;
//退出游戏时保存游戏角色
FileStream fs = new FileStream("路径", FileMode.Create, FileAccess.Write);//创建流(路径比如:d:\RPG.game)//后缀随便
StreamWriter sw = new StreamWriter(fs); //写入器
sw.WriteLine("要保存的内容"); //这里面保存游戏角色,怪物状态等等,该存的都存。
sw.WriteLine("");
sw.WriteLine(""); //可以有多句
......
sw.Close();
fs.Close();
//当用户不开始新游戏,要继续上一次游戏时,读取上次保存的角色信息。
FileStream fs = new FileStream("路径", FileMode.Create, FileAccess.Write);//创建流(路径比如:d:\RPG.game)//后缀随便
StreamReader sw = new StreamReader(fs); //写入器
sw.ReadLine("读取角色信息"); //这里面保存游戏角色,怪物状态等等,该存的都存。
sw.ReadLine("");
sw.ReadLine(""); //可以有多句
sw.Close();
fs.Close();
fs.Close();
//将怪物存到集合里面
Dictionary 集合名 = new Dictionary();
遍历集合读取角色信息,加载到你的窗体里面。
方法很多,这只是一种,不知道你会不会序列化会的话代码就可以少很多。我就说这么多,不知道你能否看懂。