public static void SaveShip(ShipProperties properties) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(SHIPS_PROPERTIES_PATH, FileMode.Create); formatter.Serialize(stream, properties); stream.Close(); }
public static ShipProperties LoadShip(ShipType type) { string file = SHIPS_PROPERTIES_PATH; if (!File.Exists(file)) { ShipProperties newShip = new ShipProperties(); SaveShip(newShip); } BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(file, FileMode.Open); ShipProperties ship = (ShipProperties)formatter.Deserialize(stream); stream.Close(); return(ship); }