c# - Windows Forms - How do I save and load games? -


i starting code game in c# using windows forms (not using xna) , trying figure out how save/load.

right have main form, few user controls, , 1 class in separate project.

i have looked decent tutorial , best i've found:

http://www.codeproject.com/articles/1789/object-serialization-using-c

would method suitable windows form game? or there better approach me take?

also, if best route, how save data several different classes in single save file , read data in?

unfortunately don't have relevant code. tips appreciated.

serialize consecutively save class instance count , after save class instances, deserialize class count , it's instances. 1 method writing , 1 method reading using formatters serialize , deseialize.. save current state consist of life count , state of game , place of player , other properties. example see :
reading :

iformatter formatter = new binaryformatter(); stream stream = new filestream(op.filename, filemode.open, fileaccess.read, fileshare.read); fcnt = (int)formatter.deserialize(stream); (int = 0; < fcnt; i++) {    facility[i] = (facility)formatter.deserialize(stream); } stream.close(); 

writing :

iformatter formatter = new binaryformatter(); stream stream = new filestream(fn, filemode.create, fileaccess.write, fileshare.none); formatter.serialize(stream, fcnt); (int = 0; < fcnt; i++) { formatter.serialize(stream, facility[i]); } stream.close(); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -