private string SerializeFlattop(Flattop flattop, List <BaseObject> listObjects) { string serializedFlattop = flattop.GetType().ToString() + " "; serializedFlattop += flattop.AmountRockets.ToString() + " "; serializedFlattop += flattop.AmountSoldiers.ToString() + " "; serializedFlattop += flattop.HomePort + " "; serializedFlattop += flattop.Identificator + " "; serializedFlattop += flattop.Model + " "; serializedFlattop += flattop.Ocean.ToString() + " "; serializedFlattop += flattop.ReleaseYear.ToString() + " "; serializedFlattop += flattop.Speed.ToString() + " "; serializedFlattop += flattop.engine.Fuel.ToString() + " "; serializedFlattop += flattop.engine.Power.ToString() + " "; for (int i = 0; i < flattop.WarPlanes.Count; i++) { for (int j = 0; j < listObjects.Count; j++) { if (flattop.WarPlanes[i] == listObjects[j]) { serializedFlattop += j.ToString() + " "; break; } } } return(serializedFlattop); }
public BaseObject CreateObject() { Flattop flattop = new Flattop { engine = new Engine(), WarPlanes = new List <WarPlane>() }; return(flattop); }
private void DeserializeFlattop(string serializedFlattop, Flattop flattop, List <BaseObject> listObjects) { flattop.AmountRockets = int.Parse(serializedFlattop.Substring(0, serializedFlattop.IndexOf(" "))); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.AmountSoldiers = int.Parse(serializedFlattop.Substring(0, serializedFlattop.IndexOf(" "))); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.HomePort = serializedFlattop.Substring(0, serializedFlattop.IndexOf(" ")); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.Identificator = serializedFlattop.Substring(0, serializedFlattop.IndexOf(" ")); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.Model = serializedFlattop.Substring(0, serializedFlattop.IndexOf(" ")); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.Ocean = (OceanType)Enum.Parse(typeof(OceanType), serializedFlattop.Substring(0, serializedFlattop.IndexOf(" "))); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.ReleaseYear = int.Parse(serializedFlattop.Substring(0, serializedFlattop.IndexOf(" "))); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.Speed = int.Parse(serializedFlattop.Substring(0, serializedFlattop.IndexOf(" "))); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.engine = new Engine(); flattop.engine.Fuel = (FuelType)Enum.Parse(typeof(FuelType), serializedFlattop.Substring(0, serializedFlattop.IndexOf(" "))); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.engine.Power = int.Parse(serializedFlattop.Substring(0, serializedFlattop.IndexOf(" "))); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); flattop.WarPlanes = new List <WarPlane>(); while (serializedFlattop != "") { flattop.WarPlanes.Add((WarPlane)listObjects[int.Parse(serializedFlattop.Substring(0, serializedFlattop.IndexOf(" ")))]); serializedFlattop = serializedFlattop.Remove(0, serializedFlattop.IndexOf(" ") + 1); } }