Exemple #1
0
 /// <summary>
 /// Construct the manager with the basic save file.
 /// </summary>
 public SaveManager(bool loadData = false)
 {
     if (!loadData || IsEmpty())
     {
         statisticsManager = null;
     }
     else
     {
         LoadData();
     }
 }
Exemple #2
0
 /// <summary>
 /// Constructor that resets all stats if there is no specified statistics manager 
 /// and loads all data if there is one.
 /// </summary>
 public StatisticsManager(StatisticsManager statisticsManager = null)
 {
     if (statisticsManager == null)
     {
         ResetDeathCount();
         ResetTotalTime();
         SetLevelIndex(0);
         SetStageIndex(0);
         ResetPosition();
         ResetShotCount();
         UpdateEnemies(null);
         UpdateObjects(null);
     }
     else
     {
         copyStats(statisticsManager);
     }
 }
Exemple #3
0
        /// <summary>
        /// Load the data from the save file.
        /// </summary>
        public void LoadData()
        {
            StreamReader reader = new StreamReader(TitleContainer.OpenStream(levelPath + fileName));
            string line = reader.ReadLine();
            statisticsManager = new StatisticsManager();

            while (line != null)
            {
                if (line == "Level Index:")
                {
                    StatisticsManager.SetLevelIndex(int.Parse(reader.ReadLine()));
                }
                else if (line == "Stage Index:")
                {
                    StatisticsManager.SetStageIndex(int.Parse(reader.ReadLine()));
                }
                else if (line == "Position:")
                {
                    string[] position = reader.ReadLine().Split(' ');
                    StatisticsManager.SetPosition(new Vector2(float.Parse(position[0]), float.Parse(position[1])));
                }
                else if (line == "Death Count:")
                {
                    StatisticsManager.SetDeathCount(int.Parse(reader.ReadLine()));
                }
                else if (line == "Shot Count:")
                {
                    StatisticsManager.SetShotCount(int.Parse(reader.ReadLine()));
                }
                else if (line == "Total Time:")
                {
                    StatisticsManager.SetTotalTime(new TimeSpan(long.Parse(reader.ReadLine())));
                }
                line = reader.ReadLine();
            }

            reader.Close();
        }
Exemple #4
0
        /// <summary>
        /// Constructs a level from the given statistics.
        /// </summary>
        public Level(ContentManager content, Viewport windowData, StatisticsManager statistics)
        {
            levelIndex = statistics.LevelIndex;
            stageIndex = statistics.StageIndex;
            Content = content;
            window = windowData;

            LoadContent();

            //Set the current start position of the player to the one provided by the statisticsManager if it exists
            if (statistics.Position.X >= 0 && statistics.Position.Y >= 0)
            {
                start = statistics.Position;
                Session.LastSavedStats.SetPosition(start);
            }
            Player.Reset(start);

            try
            {
                MediaPlayer.IsRepeating = true;
                MediaPlayer.Play(Content.Load<Song>(string.Format("Sounds/Levels/{0}", Session.StatisticsManager.LevelIndex)));
            }
            catch { }
        }
Exemple #5
0
 /// <summary>
 /// Copy stats from a provided statistics manager.
 /// </summary>
 private void copyStats(StatisticsManager statisticsManager)
 {
     levelIndex = statisticsManager.levelIndex;
     stageIndex = statisticsManager.stageIndex;
     position = statisticsManager.position;
     deathCount = statisticsManager.deathCount;
     totalTime = statisticsManager.totalTime;
     shotCount = statisticsManager.shotCount;
     UpdateEnemies(statisticsManager.enemies);
     UpdateObjects(statisticsManager.objects);
 }
Exemple #6
0
        /// <summary>
        /// Start a new session based on the data provided.
        /// </summary>
        public static void StartSession(StatisticsManager statisticsManager, 
            ScreenManager screenManager, GameplayScreen gameplayScreen)
        {
            // check the parameters
            if (statisticsManager == null)
            {
                throw new ArgumentNullException("statisticsManager");
            }
            if (statisticsManager.LevelIndex < 0 || statisticsManager.LevelIndex >= Game.totalStages.Length)
            {
                throw new ArgumentNullException("levelIndex");
            }
            if (screenManager == null)
            {
                throw new ArgumentNullException("screenManager");
            }
            if (gameplayScreen == null)
            {
                throw new ArgumentNullException("gameplayScreen");
            }

            // end any existing session
            EndSession();

            // create a new singleton
            singleton = new Session(screenManager, gameplayScreen);

            // load the singleton's stats with the provided stats
            singleton.statisticsManager = statisticsManager;
            singleton.lastSavedStats = new StatisticsManager(statisticsManager);

            // set up the initial level
            LoadLevel();

            // set up the HUD of the game.
            HUD = new HUD();
        }
Exemple #7
0
 /// <summary>
 /// Set the stats of the current save.
 /// </summary>
 public void SetStatistics(StatisticsManager statisticsManager)
 {
     this.statisticsManager = new StatisticsManager(statisticsManager);
 }