Serialization/Deserialization
I have a Windows Forms C# application, where I have multiple classes(like Board, Context, Layout, Referee, and so on). The thing is that I need to Save Game/Load Game, and my assignment is about serialization, but never did it before. Which classes should I json convert, and where to store all that .json information? So that I can Load that game. Thanks.
2 Replies
Have you done a simple json serialize/deserialize? If not, get that to work in your code. There are a bunch of examples and if your approach doesn't work, you can post the code here. If you want to save a game state, it makes sense to make a class specific for this, unless most of the info in other classes is relevant. Then you can have one root class which has them inside which gets serialized
I'm going to do more examples with serialize/deserialize in order to get more familiar with it, thanks. So the architecture is like that : Context.cs ( the context of the game ) initializes the current player and the layout of the chessboard
the ChessLayout.cs creates the pieces
the Coordinate.cs holds a data structure like this: private static Dictionary<int, Dictionary<int, Coordinate>> _instances;
the Initialize method from Board.cs contains initialization of ChessLayout and Context.
But i literally don't know how to hold all the jsons for the context,layout,pieces etc, so that I can save/load the game.