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; }
internal void LoadMap(PlanetsSystem[] systems, Texture2D SystemTexture, Texture2D RingTexture, Texture2D[] PlanetTextures) { NumSystems = systems.Length; AllSystems = systems; for (int i = 0; i < NumSystems; i++) { AllSystems[i].LoadSystem(SystemTexture, RingTexture, systems[i].Planets, systems[i].PlanetsList, systems[i].SystemRectangle, systems[i].SystemColour, PlanetTextures); } //possibly need to save and load AllCoords }
internal void Initialize(int numSystems, Texture2D SystemTexture, Texture2D RingTexture, Vector2 MapSize, Texture2D[] planetTextures, ref AIPlayer[] aiPlayers, ref Player player, Texture2D SectorTexture, SpriteFont Font, GraphicsDevice device, GraphicsDeviceManager graphics, SpriteBatch spriteBatch) { playerName = player.Name + " of " + player.faction.Name; font = Font; sectorTexture = SectorTexture; string playerSysID; NumSystems = numSystems; systex = SystemTexture; ringtex = RingTexture; AllSystems = new PlanetsSystem[NumSystems]; Width = (int)MapSize.X; Height = (int)MapSize.Y; selectedSystem = 0; PlanetTextures = planetTextures; string username = Environment.UserName; var PLANET_NAME_FILES = System.IO.File.ReadAllLines(@"C:\\Users\\" + username + "\\Documents\\RES\\TextAssets\\planetNames.txt"); var SYSTEM_NAME_FILES = System.IO.File.ReadAllLines(@"C:\\Users\\" + username + "\\Documents\\RES\\TextAssets\\systemNames.txt"); planetNames = new List<string>(PLANET_NAME_FILES); //Lit of all available planet names, each one is removed when used systemNames = new List<string>(SYSTEM_NAME_FILES); AIPlayerNumbers = new List<int>(aiPlayers.Length); //list is limited to number of AI planetMapGenerator = new MapGenerator(device, spriteBatch); List<Player> tempPlayerList = new List<Player>(); tempPlayerList.Add(player); foreach (Player p in aiPlayers) { tempPlayerList.Add(p); } int currentPlayer = 0; bool isPlayerSystem = true; PlayerNumber = StrategyGame.r.Next(0, NumSystems); #region AIPlayer list position setup for (int i = 0; i < aiPlayers.Length; i++) //Setting up the number in the list of systems where the AI Players will be { int tempIDNumber = 0; do { tempIDNumber = StrategyGame.r.Next(0, NumSystems); } while (tempIDNumber == PlayerNumber || AIPlayerNumbers.Contains(tempIDNumber)); AIPlayerNumbers.Add(tempIDNumber); } #endregion SetupMapPositions(MapSize); //Action action = () => //{ #region Player Systems size = PlayerSystemSize; SystemPosition = RandCoordinates(size, true); NumPlanets = 5; rect = new Rectangle(SystemPosition, new Point(size, size)); SystemColour = player.faction.colour; randomName = StrategyGame.r.Next(0, systemNames.Count); systemName = systemNames[randomName]; systemNames.RemoveAt(randomName); //make sure the name can't be assigned twice AllSystems[PlayerNumber] = new PlanetsSystem(rect, systex, ringtex, NumPlanets, planetTextures, SystemColour, ref planetNames, systemName, SystemIndex, gridPosition, new EventHandler(UpdateResources), PlayerNumber, planetMapGenerator, player); playerSysID = systemName; player.AddSystem(ref AllSystems[PlayerNumber]); for (int i = 0; i < AllSystems[PlayerNumber].Planets; i++) { if (AllSystems[PlayerNumber].PlanetsList[i].PlanetTier == 2) { player.AddPlanet(ref AllSystems[PlayerNumber], i); //add planet to player list } } #endregion for (int i = 0; i < NumSystems; i++) { #region AIPlayerSystems if (AIPlayerNumbers.Contains(i)) //coords are being all set the same and sizes are being set to 200 - fix { size = PlayerSystemSize; NumPlanets = 5; randomName = StrategyGame.r.Next(0, systemNames.Count); systemName = systemNames[randomName]; systemNames.RemoveAt(randomName); randomName = StrategyGame.r.Next(0, planetNames.Count); tempPlanetName = planetNames[randomName]; planetNames.RemoveAt(randomName); SystemPosition = RandAICoordinates(size); rect = new Rectangle(SystemPosition, new Point(size, size)); SystemColour = Color.Red; isPlayerSystem = true; currentPlayer++; } #endregion else if (i >= 0 && i < NumSystems && i != PlayerNumber) { size = StrategyGame.r.Next(MinSize, MaxSize); NumPlanets = StrategyGame.r.Next(1, 5); SystemColour = Color.White; randomName = StrategyGame.r.Next(0, systemNames.Count); systemName = systemNames[randomName]; systemNames.RemoveAt(randomName); SystemPosition = RandCoordinates(size); rect = new Rectangle(SystemPosition, new Point(size, size)); randomName = StrategyGame.r.Next(0, planetNames.Count); tempPlanetName = planetNames[randomName]; planetNames.RemoveAt(randomName); isPlayerSystem = false; } if (i != PlayerNumber) //players system has to be initialized first - don't want to override it { if (isPlayerSystem) { AllSystems[i] = new PlanetsSystem(rect, systex, ringtex, NumPlanets, planetTextures, SystemColour, ref planetNames, systemName, SystemIndex, gridPosition, new EventHandler(UpdateResources), i, planetMapGenerator, tempPlayerList[currentPlayer]); aiPlayers[currentPlayer - 1].AddSystem(ref AllSystems[i]); for (int index = 0; index < AllSystems[i].Planets; index++) { if (AllSystems[i].PlanetsList[index].PlanetTier == 2) { aiPlayers[currentPlayer - 1].AddPlanet(ref AllSystems[i], index); //add planet to player list } } } else { AllSystems[i] = new PlanetsSystem(rect, systex, ringtex, NumPlanets, planetTextures, SystemColour, ref planetNames, systemName, SystemIndex, gridPosition, new EventHandler(UpdateResources), i, planetMapGenerator); } } } selectedSystem = PlayerNumber; AllSystems[selectedSystem].OnSelected(); int systemCount = 0; foreach (PlanetsSystem system in AllSystems) { int sectorCount = 0; foreach (MapSector sector in SectorsList) { int count = 0; foreach (Point p in sector.ContainedCoords) { if (system.GridPosition == p) { sector.AddSystem(ref AllSystems[systemCount], count); system.Sector = Int32.Parse(sector.Name); AllSystems[systemCount].AllSystemsListIndex = systemCount; if (system.ID == playerSysID) { CurrentSector = sectorCount; } } count++; } sectorCount++; } systemCount++; } //}; //Task t = new Task(action); //t.RunSynchronously(); //t.Wait(); PLANET_NAME_FILES = null; SYSTEM_NAME_FILES = null; }
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; }
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, this); }
internal void GetSelectedSystemInfo(PlanetsSystem planetsSystem) { //List<string> tempList = new List<string>(); //foreach (Planet planet in planetsSystem.PlanetsList) //{ // tempList.Add(planet.PlanetName); //} ////model.OnSystemSelected("User", planetsSystem.Planets, planetsSystem.ID, tempList); }
public void GetZoomedSystemInfo(PlanetsSystem system) { Vector2 TempBackPosition = new Vector2(); if (system.SystemRectangle.Width > 100) { systemZoom = 1.1; TempBackPosition.X = (BackgroundPosition.X + (((centre.X + (Graphics.PreferredBackBufferWidth / 2)) - system.SystemRectangle.Center.X) / 90f)); TempBackPosition.Y = (BackgroundPosition.Y + (((centre.Y + (Graphics.PreferredBackBufferHeight / 2)) - system.SystemRectangle.Center.Y) / 90f)); centre = new Vector2((system.SystemRectangle.Center.X - (Graphics.PreferredBackBufferWidth / 2.2f)), (system.SystemRectangle.Center.Y - (Graphics.PreferredBackBufferHeight / 2.2f))); } else { systemZoom = 1.6; TempBackPosition.X = (BackgroundPosition.X + (((centre.X + (Graphics.PreferredBackBufferWidth / 2)) - system.SystemRectangle.Center.X) / 90f)); TempBackPosition.Y = (BackgroundPosition.Y + (((centre.Y + (Graphics.PreferredBackBufferHeight / 2)) - system.SystemRectangle.Center.Y) / 90f)); centre = new Vector2((system.SystemRectangle.Center.X - (Graphics.PreferredBackBufferWidth / 3.2f)), (system.SystemRectangle.Center.Y - (Graphics.PreferredBackBufferHeight / 3.2f))); } currentPlanetsList.Clear(); foreach (Planet planet in system.PlanetsList) { currentPlanetsList.Add(planet.PlanetName); } BackgroundPosition = TempBackPosition; model.OnSystemZoomed(system.controlledBy, system.Planets, system.ID, currentPlanetsList); }
internal void SystemHighlighted(PlanetsSystem hoveredSystem) { bool isPlayerSystem = false; if(hoveredSystem.controllingPlayer != null) { isPlayerSystem = true; } SystemInfo info = new SystemInfo(hoveredSystem.ID, hoveredSystem.Planets.ToString(), hoveredSystem.controlledBy, isPlayerSystem); model.SystemHighlighted(info); }
public void AddSystem(ref PlanetsSystem system, int listPosition) { ContainedSystems.Add(system); ContainedSystemListPositions.Add(listPosition); system.Sector--; }
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; }