public void DoSave(SaveGameData data, PlanetsSystem[] systems, Player[] players) { fileName = "SAVE" + data.Slot + ".sav"; fullpath = "C:\\Users\\" + username + "\\Documents\\Saves\\"; Directory.CreateDirectory(Path.GetDirectoryName(fullpath + fileName)); if (File.Exists(fullpath + fileName)) { File.Delete(fullpath + fileName); //If there's already a file in that slot, delete it first! or.. //...if the new file is shorter than the original, junk characters get added to the end of the xml file! } FileStream stream = File.Open(fullpath + fileName, FileMode.OpenOrCreate); XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData), extratypes); //Player[] playerArray = new Player[1]; //playerArray[0] = player; //Have to put the player object into an array because Info is an array of object arrays :/ object[][] info = new object[2][]; info[0] = systems; info[1] = players; data.Info = info; try { serializer.Serialize(stream, data); } finally { stream.Close(); } }
public void SaveAccount(SaveGameData data, PlanetsSystem[] systems, Player[] AIPlayers) { Player[] players = new Player[AIPlayers.Length + 1]; for (int i = 0; i < players.Length; i++) { if (i < players.Length - 1) { players[i] = AIPlayers[i]; } else players[i] = player; } SaveData.Score = data.Score; if (SaveData.Score != 0) { saveGame.DoSave(SaveData, systems, players); } else return; }
public SaveGameData LoadAccount(SaveGameData data, int Slot, ref PlanetsSystem[] systems, ref Player player, ref AIPlayer[] aiplayers) { slot = Slot; data = saveGame.LoadData(slot, ref systems, ref player, ref aiplayers); return data; }
internal void AddSystem(ref PlanetsSystem planetsSystem) { OwnedSystems.Add(planetsSystem); }
internal void AddPlanet(ref PlanetsSystem system, int index) { OwnedPlanets.Add(system.PlanetsList[index]); system.PlanetsList[index].Captured(Name + " of " + faction.Name); }
public SaveGameData LoadData(int slot, ref PlanetsSystem[] systems, ref Player player, ref AIPlayer[] AIPlayers) { object[][] info = new object[2][]; SaveGameData data; data = new SaveGameData(); string Fullpath = "C:\\Users\\" + username + "\\Documents\\Saves\\SAVE" + slot + ".sav"; if (File.Exists(Fullpath)) { FileStream stream = File.Open(Fullpath, FileMode.Open, FileAccess.Read); XmlReader reader = new XmlTextReader(stream); try { if (File.Exists(Fullpath)) { // Read the data from the file XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData), extratypes); if (serializer.CanDeserialize(reader)) { data = (SaveGameData)serializer.Deserialize(reader); // info[0] = (object[])data.Info[0]; //array of additional objects systems = new PlanetsSystem[data.Info[0].Length]; // for (int i = 0; i < data.Info[0].Length; i++) { systems[i] = (PlanetsSystem)info[0][i]; } Player[] playerArray = (Player[])data.Info[1][0]; List<Player> playerList = playerArray.ToList(); player = playerList[playerList.Count - 1]; playerList.RemoveAt(playerList.Count - 1); for (int i = 0; i < playerList.Count; i++) { AIPlayers[i] = (AIPlayer)playerList[i]; } } } } finally { // Close the file stream.Close(); } } return data; }