Example #1
0
        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;
        }
Example #2
0
 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;
 }
Example #3
0
        public override void LoadContent(Account acc, NewGameDetails details)
        {
            user = acc;
            SysTex = content.Load<Texture2D>("sun");
            RingTex = content.Load<Texture2D>("ring");
            background = content.Load<Texture2D>("galaxyBackground");
            Font = content.Load<SpriteFont>("Font");
            ShipTex = content.Load<Texture2D>("Ship1");
            base.sf = content.Load<SpriteFont>("Font");
            Texture2D sectorOutline = content.Load<Texture2D>("outline");

            for (int i = 1; i <= 20; i++)
            {
                planetTextures[i - 1] = content.Load<Texture2D>("Planets/planet" + i);
            }

            HumanPlayer = new Player(details.playerFaction, 1);
            AllPlayers.Add(HumanPlayer);
            HumanPlayer.playerListPosition = AllPlayers.Count - 1;
            screentitle = "OVERVIEW SCREEN";
            data = user.SaveData;
            prev = new SaveGameData();
            aiPlayers = new AIPlayer[details.NumAI]; //plus 1 so the player can be added to the array when serializing 
            for (int i = 0; i < details.NumAI; i++)
            {
                aiPlayers[i] = new AIPlayer();
                aiPlayers[i].playerNumber = i;
                AllPlayers.Add(aiPlayers[i]);
                aiPlayers[i].playerListPosition = AllPlayers.Count - 1;
            }
            map.Initialize(details.NumSystems, SysTex, RingTex, details.MapSizeVector, 
                planetTextures, ref aiPlayers, ref humanPlayer, sectorOutline, Font,
                device, graphics, spriteBatch);
            zoom = 1.0f;
            Systems = map.AllSystems;
            selectedSystem = map.AllSystems[map.selectedSystem];

            BackgroundRec = new Rectangle(
                0 - (graphics.PreferredBackBufferWidth / 3),
                0 - (graphics.PreferredBackBufferHeight / 3),
                background.Width, background.Height);
            UpdateResourcesDetails();
            UpdateEndDayResources();
            gameSpeed = 1f;
            CurrentView = ViewType.MapView;
            elapsedDays = 0;
            elapsedHours = 0;
            paused = false;
            planetsTaxChange.Clear();
            planetsTaxChangeNames.Clear();
        }