Exemple #1
0
        //public static void SetCurrentProgress(GameProgress gameProgress)
        //{
        //    var iss = IsolatedStorageSync.GetInstance();
        //    iss.SaveGame(File, gameProgress);
        //}

        //public static GameProgress GetCurrentProgress()
        //{
        //    GameProgress gp;
        //    var iss = IsolatedStorageSync.GetInstance();
        //    if(iss!=null) return iss.LoadGame(File);
        //    var defaultItems = new[]
        //    {
        //        new GameItem(0,1),
        //        new GameItem(1,1),
        //        new GameItem(2,1),
        //        new GameItem(3,1),
        //        new GameItem(4,1)
        //    };

        //    var defaultStartGameProgress = new GameProgress
        //    {
        //        CurrentLevel = 1,
        //        CurrentWorld = 1,
        //        TotalMoves = 0,
        //        LevelsPuntuations = new Dictionary<int, int>
        //                {
        //                   { 1, 0 }
        //                },
        //        GameItems = defaultItems
        //    };

        //    SetCurrentProgress(defaultStartGameProgress);

        //    return defaultStartGameProgress;
        //}

        public static GameProgress GetCurrentProgress()
        {
            GameProgress gp;

            IsolatedStorageSettings.ApplicationSettings.TryGetValue(CurrentProgress, out gp);
            if (gp != null)
            {
                return(gp);
            }

            var defaultItems = new[]
            {
                new GameItem(0, Int32.MaxValue),
                new GameItem(1, 1),
                new GameItem(2, 1),
                new GameItem(3, 1),
                new GameItem(4, 1)
            };

            var defaultStartGameProgress = new GameProgress
            {
                CurrentLevel      = 1,
                CurrentWorld      = 1,
                TotalMoves        = 0,
                LevelsPuntuations = new Dictionary <int, int>
                {
                    { 1, 0 }
                },
                GameItems = defaultItems
            };

            SetSetting(CurrentProgress, defaultStartGameProgress);

            return(defaultStartGameProgress);
        }
Exemple #2
0
        public GameProgress LoadGame(string filePath)
        {
            var          store = IsolatedStorageFile.GetUserStoreForApplication();
            GameProgress gp    = null;

            if (store.FileExists(filePath))
            {
                using (var stream = new IsolatedStorageFileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, store))
                {
                    var serializer = new XmlSerializer(typeof(GameProgress));
                    gp = (GameProgress)serializer.Deserialize(stream);
                }
            }
            return(gp);
        }
Exemple #3
0
        public void SaveGame(string filePath, GameProgress gameProgress)
        {
            var store = IsolatedStorageFile.GetUserStoreForApplication();

            if (store.FileExists(filePath))
            {
                store.DeleteFile(filePath);
            }
            store.CreateFile(filePath);

            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(GameProgress));

            using (var stream = new IsolatedStorageFileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, store))
            {
                serializer.Serialize(stream, gameProgress);
            }
        }
Exemple #4
0
        public static GameProgress GetCurrentProgress()
        {
            var defaultItems = new GameItem[]
            {
                new GameItem(0, 1),
                new GameItem(1, 0),
                new GameItem(2, 0),
                new GameItem(3, 1),
                new GameItem(4, 1)
            };

            var defaultStartGameProgress = new GameProgress
            {
                CurrentLevel      = 1,
                CurrentWorld      = 1,
                TotalMoves        = 0,
                LevelsPuntuations = new Dictionary <int, int>
                {
                    { 1, 0 }
                },
                GameItems = defaultItems
            };

            if (!IsolatedStorageSettings.ApplicationSettings.Contains(CurrentProgress))
            {
                SetSetting(CurrentProgress, defaultStartGameProgress);
            }
            else
            {
                var gp = (GameProgress)IsolatedStorageSettings.ApplicationSettings[CurrentProgress];
                if (gp != null)
                {
                    defaultStartGameProgress = gp;
                }
            }
            if (defaultStartGameProgress.GameItems == null)
            {
                defaultStartGameProgress.GameItems = defaultItems;
            }
            return(defaultStartGameProgress);
        }
Exemple #5
0
 public static void SetCurrentProgress(GameProgress gameProgress)
 {
     SetSetting(CurrentProgress, gameProgress);
 }
Exemple #6
0
 public static void Save(GameProgress value)
 {
     Save(CurrentProgress, value);
 }
Exemple #7
0
 public static void SetSetting(string setting, GameProgress value)
 {
     IsolatedStorageSettings.ApplicationSettings[setting] = value;
 }
Exemple #8
0
 public static void AddSetting(string setting, GameProgress value)
 {
     IsolatedStorageSettings.ApplicationSettings.Add(setting, value);
     IsolatedStorageSettings.ApplicationSettings.Save();
 }