Exemplo n.º 1
0
 public void ClearBackupFiles(params SaveType[] deleteList)
 {
     this.GetStorageContainer();
     for (int i = 0; i < deleteList.Length; i++)
     {
         SaveType deleteType = deleteList[i];
         this.DeleteBackupData(deleteType);
     }
     this.m_storageContainer.Dispose();
     this.m_storageContainer = null;
 }
Exemplo n.º 2
0
        // I/F
        public void Select(string storageName)
        {
            var showSelectorResult = StorageDevice.BeginShowSelector(null, null);
            showSelectorResult.AsyncWaitHandle.WaitOne();

            var storageDevice = StorageDevice.EndShowSelector(showSelectorResult);
            showSelectorResult.AsyncWaitHandle.Close();

            var openContainerResult = storageDevice.BeginOpenContainer(storageName, null, null);
            openContainerResult.AsyncWaitHandle.WaitOne();

            container = storageDevice.EndOpenContainer(openContainerResult);
            openContainerResult.AsyncWaitHandle.Close();

            // 非同期呼び出しの可能性があるため同期を取ります。
            lock (syncRoot)
            {
                containerChanged = true;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if a save file for the game already exists - and loads it if so.
        /// Meant to be used solely on XBOX360.  Should be used as soon as we know what
        /// PlayerIndex the "gamer" is using (IE right after the title screen).
        /// 
        /// Note: if a save game does not exist the constructor for this class should have
        /// filled in the default values (0 stars, all but the first locked - on xbox our default xml file
        /// should always have the default values - we cannot save information to that file as it is a binary xnb file
        /// that can't be changed at run time)
        /// 
        /// Do not call this until we know the PlayerIndex the player is using!
        /// </summary>
        public bool CheckForSave()
        {
            IAsyncResult result;
            try
            {
                if (!mDeviceSelected && !Guide.IsVisible)
                {
                    StorageDevice.BeginShowSelector(((ControllerControl)mControls).ControllerIndex, this.SelectDevice, null);
                    mDeviceSelected = true;
                }
            }
            catch (Exception e)
            {
                string errTemp = e.ToString();
                mDeviceSelected = false;
                return false;
            }

            if (device == null || !device.IsConnected)
            {
            //mDeviceSelected = false;
                return false;
            }

            try
            {
                result = device.BeginOpenContainer("Mr Gravity", null, null);
                result.AsyncWaitHandle.WaitOne();
                container = device.EndOpenContainer(result);
                result.AsyncWaitHandle.Close();
            }
            catch (Exception e)
            {
                string execTemp = e.ToString();
                device = null;
                if (container != null)
                {
                    container.Dispose();
                }
                container = null;
                mDeviceSelected = false;
                return false;
            }

            try
            {
                if (container.FileExists("LevelList.xml"))
                {
                    Stream stream = container.OpenFile("LevelList.xml", FileMode.Open);
                    XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
                    SaveGameData data = (SaveGameData)serializer.Deserialize(stream);
                    stream.Close();
                    int i = 0;
                    foreach (XElement xLevels in data.SaveData.Elements())
                    {
                        foreach (XElement xLevelData in xLevels.Elements())
                        {
                            foreach (XElement xLevel in xLevelData.Elements())
                            {
                                if (xLevel.Name == XmlKeys.UNLOCKED && xLevel.Value == XmlKeys.TRUE)
                                    mLevels[i].Unlock();

                                if (xLevel.Name == XmlKeys.TIMERSTAR)
                                    mLevels[i].SetStar(LevelInfo.StarTypes.Time, Convert.ToInt32(xLevel.Value));

                                if (xLevel.Name == XmlKeys.COLLECTIONSTAR)
                                    mLevels[i].SetStar(LevelInfo.StarTypes.Collection, Convert.ToInt32(xLevel.Value));

                                if (xLevel.Name == XmlKeys.DEATHSTAR)
                                    mLevels[i].SetStar(LevelInfo.StarTypes.Death, Convert.ToInt32(xLevel.Value));

                            }
                            i++;
                        }
                    }

                }
            }
            catch (Exception e)
            {
                string exceTemp = e.ToString();
                if (container != null)
                {
                    container.Dispose();
                }
                container = null;
                device = null;
                mDeviceSelected = false;
                return false;
            }

            if (device.IsConnected)
            {
                container.Dispose();
            }
            else
            {
                device = null;
                container = null;
                mDeviceSelected = false;
            }

            this.UpdateStarCount();
            return true;
        }
Exemplo n.º 4
0
		// Private method to handle the creation of the StorageDevice.
		private StorageContainer Open(string displayName)
		{
			deviceContainer = new StorageContainer(
				this,
				displayName,
				storageRoot,
				devicePlayer
			);
			return deviceContainer;
		}
Exemplo n.º 5
0
 /// <summary>
 /// Opens the StorageContainer.
 /// </summary>
 /// <returns>Whether this operation was successful.</returns>
 public static bool OpenContainer()
 {
     try
     {
         IAsyncResult r = storageDevice.BeginOpenContainer(ContainerName, null, null);
         storageContainer = storageDevice.EndOpenContainer(r);
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
Exemplo n.º 6
0
        public void UpdateSaving()
        {
            switch (savingState)
            {
                case SavingState.ReadyToSelectStorageDevice:
                    {
                        asyncResult = StorageDevice.BeginShowSelector(playerIndex, null, null);
                        savingState = SavingState.SelectingStorageDevice;
                    }
                    break;

                case SavingState.SelectingStorageDevice:
                    if (asyncResult.IsCompleted)
                    {
                        storageDevice = StorageDevice.EndShowSelector(asyncResult);
                        savingState = SavingState.ReadyToOpenStorageContainer;
                    }
                    break;

                case SavingState.ReadyToOpenStorageContainer:
                    if (storageDevice == null || !storageDevice.IsConnected)
                    {
                        savingState = SavingState.ReadyToSelectStorageDevice;
                    }
                    else
                    {
                        asyncResult = storageDevice.BeginOpenContainer("Game1StorageContainer", null, null);
                        savingState = SavingState.OpeningStorageContainer;
                    }
                    break;

                case SavingState.OpeningStorageContainer:
                    if (asyncResult.IsCompleted)
                    {
                        storageContainer = storageDevice.EndOpenContainer(asyncResult);
                        savingState = SavingState.ReadyToSave;
                    }
                    break;

                case SavingState.ReadyToSave:
                    if (storageContainer == null)
                    {
                        savingState = SavingState.ReadyToOpenStorageContainer;
                    }
                    else
                    {
                        try
                        {
                            DeleteExisting();
                            Save();
                        }
                        catch (IOException e)
                        {
                            // Replace with in game dialog notifying user of error
                            Debug.WriteLine(e.Message);
                        }
                        finally
                        {
                            storageContainer.Dispose();
                            storageContainer = null;
                            savingState = SavingState.NotSaving;
                        }
                    }
                    break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Transitions the SavingState through the saving process. 
        /// Handles selecting the storage device, opening the storage container, and executing the save function
        /// </summary>
        private void UpdateSaving()
        {
            switch (savingState)
            {
                case SavingState.ReadyToSelectStorageDevice:
            #if XBOX
                    if (!Guide.IsVisible)
            #endif
                    {
                        asyncResult = StorageDevice.BeginShowSelector(playerIndex, null, null);
                        savingState = SavingState.SelectingStorageDevice;
                    }
                    break;

                case SavingState.SelectingStorageDevice:
                    if (asyncResult.IsCompleted)
                    {
                        storageDevice = StorageDevice.EndShowSelector(asyncResult);
                        savingState = SavingState.ReadyToOpenStorageContainer;
                    }
                    break;

                case SavingState.ReadyToOpenStorageContainer:
                    if (storageDevice == null || !storageDevice.IsConnected)
                    {
                        savingState = SavingState.ReadyToSelectStorageDevice;
                    }
                    else
                    {
                        asyncResult = storageDevice.BeginOpenContainer("EditorStorageContainer", null, null);
                        savingState = SavingState.OpeningStorageContainer;
                    }
                    break;

                case SavingState.OpeningStorageContainer:
                    if (asyncResult.IsCompleted)
                    {
                        storageContainer = storageDevice.EndOpenContainer(asyncResult);
                        savingState = SavingState.ReadyToSave;
                    }
                    break;

                case SavingState.ReadyToSave:
                    if (storageContainer == null)
                    {
                        savingState = SavingState.ReadyToOpenStorageContainer;
                    }
                    else
                    {
                        try
                        {
                            string filename = GetUniqueFileName();
                            Save(filename);
                        }
                        catch (IOException e)
                        {
                            // Replace with in game dialog notifying user of error
                            Console.Out.WriteLine(e.Message);
                        }
                        finally
                        {
                            storageContainer.Dispose();
                            storageContainer = null;
                            savingState = SavingState.NotSaving;
                        }
                    }
                    break;
            }
        }
        public static void XboxLoadCallback(IAsyncResult result)
        {
            StorageDevice device = StorageDevice.EndShowSelector( result );
            if (device.IsConnected)
            {
                IAsyncResult containerResult = device.BeginOpenContainer("SaveGame", null, null);
                containerResult.AsyncWaitHandle.WaitOne();
                StorageContainer container = device.EndOpenContainer(containerResult);
                containerResult.AsyncWaitHandle.Close();
                storageContainer = container;

                if (container.FileExists(filename))
                {
                    Stream stream = container.OpenFile(filename, FileMode.Open);
                    BinaryReader br = new BinaryReader(stream);
                    Load(br);
                }
                else
                {
                    tutorial = true;
                }
            }
        }
Exemplo n.º 9
0
        /*
         * Saves, Loads or Deletes a saveFile
         */
        private void UpdateSavingLoadingOrDeleting(SpectrumEnums.SaveLoadOrDelete saveLoadOrDelete)
        {
            switch (savingState)
            {
                case SpectrumEnums.SavingState.ReadyToSelectStorageDevice:
                    asyncResult = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
                    savingState = SpectrumEnums.SavingState.SelectingStorageDevice;
                    break;
                case SpectrumEnums.SavingState.SelectingStorageDevice:
                    if (asyncResult.IsCompleted)
                    {
                        storageDevice = StorageDevice.EndShowSelector(asyncResult);
                        savingState = SpectrumEnums.SavingState.ReadyToOpenStorageContainer;
                    }
                    break;
                case SpectrumEnums.SavingState.ReadyToOpenStorageContainer:
                    if (storageDevice == null || !storageDevice.IsConnected)
                    {
                        savingState = SpectrumEnums.SavingState.ReadyToSelectStorageDevice;
                    }
                    else
                    {
                        asyncResult = storageDevice.BeginOpenContainer("SpectrumSaveGame", null, null);
                        savingState = SpectrumEnums.SavingState.OpeningStorageContainer;
                    }
                    break;
                case SpectrumEnums.SavingState.OpeningStorageContainer:
                    if (asyncResult.IsCompleted)
                    {
                        storageContainer = storageDevice.EndOpenContainer(asyncResult);

                        if (saveLoadOrDelete == SpectrumEnums.SaveLoadOrDelete.save)
                        {
                            savingState = SpectrumEnums.SavingState.ReadyToSave;
                        }
                        else if (saveLoadOrDelete == SpectrumEnums.SaveLoadOrDelete.load)
                        {
                            savingState = SpectrumEnums.SavingState.ReadyToLoad;
                        }
                        else
                        {
                            savingState = SpectrumEnums.SavingState.ReadyToDelete;
                        }
                    }
                    break;
                case SpectrumEnums.SavingState.ReadyToLoad:
                    if (storageContainer == null)
                    {
                        savingState = SpectrumEnums.SavingState.ReadyToOpenStorageContainer;
                    }
                    else
                    {
                        Load();
                        storageContainer.Dispose();
                        storageContainer = null;
                        savingState = SpectrumEnums.SavingState.NotSaving;
                    }
                    break;
                case SpectrumEnums.SavingState.ReadyToDelete:
                    if (storageContainer == null)
                    {
                        savingState = SpectrumEnums.SavingState.ReadyToOpenStorageContainer;
                    }
                    else
                    {
                        try
                        {
                            DeleteExisting();
                        }
                        catch (IOException e)
                        {
                            // error
                        }
                        finally
                        {
                            storageContainer.Dispose();
                            storageContainer = null;
                            savingState = SpectrumEnums.SavingState.NotSaving;
                        }
                    }
                    break;
                case SpectrumEnums.SavingState.ReadyToSave:
                    if (storageContainer == null)
                    {
                        savingState = SpectrumEnums.SavingState.ReadyToOpenStorageContainer;
                    }
                    else
                    {
                        try
                        {
                            DeleteExisting();
                            Save();
                        }
                        catch (IOException e)
                        {
                            // error
                        }
                        finally
                        {
                            storageContainer.Dispose();
                            storageContainer = null;
                            savingState = SpectrumEnums.SavingState.NotSaving;
                        }
                    }
                    break;
            }
        }
Exemplo n.º 10
0
 private void GetStorageContainer()
 {
     if (this.m_storageContainer == null || this.m_storageContainer.IsDisposed)
     {
         IAsyncResult asyncResult = StorageDevice.BeginShowSelector(null, null);
         asyncResult.AsyncWaitHandle.WaitOne();
         StorageDevice storageDevice = StorageDevice.EndShowSelector(asyncResult);
         asyncResult.AsyncWaitHandle.Close();
         asyncResult = storageDevice.BeginOpenContainer("RogueLegacyStorageContainer", null, null);
         asyncResult.AsyncWaitHandle.WaitOne();
         this.m_storageContainer = storageDevice.EndOpenContainer(asyncResult);
         asyncResult.AsyncWaitHandle.Close();
     }
 }
Exemplo n.º 11
0
 private void CopyFile(StorageContainer storageContainer, string fileName, string profileName)
 {
     if (storageContainer.FileExists(fileName))
     {
         Stream stream = storageContainer.OpenFile(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
         Stream stream2 = storageContainer.CreateFile(profileName + "/" + fileName);
         stream.CopyTo(stream2);
         stream.Close();
         stream2.Close();
     }
 }
Exemplo n.º 12
0
 public void SaveFiles(params SaveType[] saveList)
 {
     if (!LevelEV.DISABLE_SAVING)
     {
         this.GetStorageContainer();
         try
         {
             for (int i = 0; i < saveList.Length; i++)
             {
                 SaveType saveType = saveList[i];
                 this.SaveData(saveType, false);
             }
             this.m_saveFailCounter = 0;
         }
         catch
         {
             if (this.m_saveFailCounter > 2)
             {
                 RCScreenManager screenManager = Game.ScreenManager;
                 screenManager.DialogueScreen.SetDialogue("Save File Error Antivirus");
                 Tween.RunFunction(0.25f, screenManager, "DisplayScreen", new object[]
                 {
                     13,
                     true,
                     typeof(List<object>)
                 });
                 this.m_saveFailCounter = 0;
             }
             else
             {
                 this.m_saveFailCounter++;
             }
         }
         finally
         {
             if (this.m_storageContainer != null && !this.m_storageContainer.IsDisposed)
             {
                 this.m_storageContainer.Dispose();
             }
             this.m_storageContainer = null;
         }
     }
 }
Exemplo n.º 13
0
 public void SaveBackupFiles(params SaveType[] saveList)
 {
     if (!LevelEV.DISABLE_SAVING)
     {
         this.GetStorageContainer();
         for (int i = 0; i < saveList.Length; i++)
         {
             SaveType saveType = saveList[i];
             this.SaveData(saveType, true);
         }
         this.m_storageContainer.Dispose();
         this.m_storageContainer = null;
     }
 }
Exemplo n.º 14
0
 public void LoadFiles(ProceduralLevelScreen level, params SaveType[] loadList)
 {
     if (LevelEV.ENABLE_BACKUP_SAVING)
     {
         this.GetStorageContainer();
         SaveType saveType = SaveType.None;
         try
         {
             try
             {
                 if (!LevelEV.DISABLE_SAVING)
                 {
                     for (int i = 0; i < loadList.Length; i++)
                     {
                         SaveType saveType2 = loadList[i];
                         saveType = saveType2;
                         this.LoadData(saveType2, level);
                     }
                 }
             }
             catch
             {
                 if (saveType == SaveType.Map || saveType == SaveType.MapData || saveType == SaveType.None)
                 {
                     throw new Exception();
                 }
                 if (!this.m_autosaveLoaded)
                 {
                     RCScreenManager screenManager = Game.ScreenManager;
                     screenManager.DialogueScreen.SetDialogue("Save File Error");
                     screenManager.DialogueScreen.SetConfirmEndHandler(this, "LoadAutosave", new object[0]);
                     screenManager.DisplayScreen(13, false, null);
                     Game.PlayerStats.HeadPiece = 0;
                 }
                 else
                 {
                     this.m_autosaveLoaded = false;
                     RCScreenManager screenManager2 = Game.ScreenManager;
                     screenManager2.DialogueScreen.SetDialogue("Save File Error 2");
                     screenManager2.DialogueScreen.SetConfirmEndHandler(this, "StartNewGame", new object[0]);
                     screenManager2.DisplayScreen(13, false, null);
                     Game.PlayerStats.HeadPiece = 0;
                 }
             }
             return;
         }
         finally
         {
             if (this.m_storageContainer != null && !this.m_storageContainer.IsDisposed)
             {
                 this.m_storageContainer.Dispose();
             }
         }
     }
     if (!LevelEV.DISABLE_SAVING)
     {
         this.GetStorageContainer();
         for (int j = 0; j < loadList.Length; j++)
         {
             SaveType loadType = loadList[j];
             this.LoadData(loadType, level);
         }
         this.m_storageContainer.Dispose();
         this.m_storageContainer = null;
     }
 }
Exemplo n.º 15
0
 public void Initialize()
 {
     if (LevelEV.RUN_DEMO_VERSION)
     {
         this.m_fileNamePlayer = "RogueLegacyDemoPlayer.rcdat";
         this.m_fileNameUpgrades = "RogueLegacyDemoBP.rcdat";
         this.m_fileNameMap = "RogueLegacyDemoMap.rcdat";
         this.m_fileNameMapData = "RogueLegacyDemoMapDat.rcdat";
         this.m_fileNameLineage = "RogueLegacyDemoLineage.rcdat";
     }
     if (this.m_storageContainer != null)
     {
         this.m_storageContainer.Dispose();
         this.m_storageContainer = null;
     }
     this.PerformDirectoryCheck();
 }
Exemplo n.º 16
0
        public static void SaveHighScores(HighScoreData data)
        {
            // Open the file, creating it if necessary
            //FileStream stream = File.Open(highScorePath, FileMode.Create);
            cachedData = data;

            try
            {
                IAsyncResult result =
                    HighScoreTracker.device.BeginOpenContainer("StorageDemo", null, null);
                result.AsyncWaitHandle.WaitOne();
                container = HighScoreTracker.device.EndOpenContainer(result);
                result.AsyncWaitHandle.Close();

                Stream stream = container.OpenFile("highscores.sav", FileMode.Create);

                try
                {
                    // Convert the object to XML data and put it in the stream
                    XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
                    serializer.Serialize(stream, data);
                }
                catch
                {
                }
                finally
                {
                    // Close the file
                    stream.Flush();
                    stream.Close();
                }
            }
            catch
            {
                return;
            }
            finally
            {
                if(container!=null)
                    container.Dispose();
            }
        }
Exemplo n.º 17
0
 private void LoadBackups()
 {
     Console.WriteLine("Replacing save file with back up saves");
     this.GetStorageContainer();
     if (this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/AutoSave_",
         this.m_fileNamePlayer
     })) && this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/",
         this.m_fileNamePlayer
     })))
     {
         Stream stream = this.m_storageContainer.OpenFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/AutoSave_",
             this.m_fileNamePlayer
         }), FileMode.Open);
         Stream stream2 = this.m_storageContainer.CreateFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNamePlayer
         }));
         stream.CopyTo(stream2);
         stream.Close();
         stream2.Close();
     }
     if (this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/AutoSave_",
         this.m_fileNameUpgrades
     })) && this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/",
         this.m_fileNameUpgrades
     })))
     {
         Stream stream3 = this.m_storageContainer.OpenFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/AutoSave_",
             this.m_fileNameUpgrades
         }), FileMode.Open);
         Stream stream4 = this.m_storageContainer.CreateFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNameUpgrades
         }));
         stream3.CopyTo(stream4);
         stream3.Close();
         stream4.Close();
     }
     if (this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/AutoSave_",
         this.m_fileNameMap
     })) && this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/",
         this.m_fileNameMap
     })))
     {
         Stream stream5 = this.m_storageContainer.OpenFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/AutoSave_",
             this.m_fileNameMap
         }), FileMode.Open);
         Stream stream6 = this.m_storageContainer.CreateFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNameMap
         }));
         stream5.CopyTo(stream6);
         stream5.Close();
         stream6.Close();
     }
     if (this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/AutoSave_",
         this.m_fileNameMapData
     })) && this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/",
         this.m_fileNameMapData
     })))
     {
         Stream stream7 = this.m_storageContainer.OpenFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/AutoSave_",
             this.m_fileNameMapData
         }), FileMode.Open);
         Stream stream8 = this.m_storageContainer.CreateFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNameMapData
         }));
         stream7.CopyTo(stream8);
         stream7.Close();
         stream8.Close();
     }
     if (this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/AutoSave_",
         this.m_fileNameLineage
     })) && this.m_storageContainer.FileExists(string.Concat(new object[]
     {
         "Profile",
         Game.GameConfig.ProfileSlot,
         "/",
         this.m_fileNameLineage
     })))
     {
         Stream stream9 = this.m_storageContainer.OpenFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/AutoSave_",
             this.m_fileNameLineage
         }), FileMode.Open);
         Stream stream10 = this.m_storageContainer.CreateFile(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNameLineage
         }));
         stream9.CopyTo(stream10);
         stream9.Close();
         stream10.Close();
     }
     this.m_autosaveLoaded = true;
     this.m_storageContainer.Dispose();
     this.m_storageContainer = null;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Reads the buffer, and overwrites the content of it.
        /// </summary>
        /// <param name="container">The container.</param>
        private void ReadOverwriteBuffer(StorageContainer container)
        {
            // Failsafe
            if (container == null)
            {
                return;
            }

            this.CheckBuffer();

            if (container.FileExists(filename))
            {
                Stream fileRead = container.OpenFile(filename, FileMode.Open);
                this.buffer = new byte[fileRead.Length];
                fileRead.Read(this.buffer, 0, buffer.Length);
                fileRead.Close();
            }

            this.hasBufferChanged = false;
            this.updateScoreboard = true;

            this.CheckBuffer();

            this.UpdateGamertagLookup();
        }
Exemplo n.º 19
0
 public bool FileExists(SaveType saveType)
 {
     bool flag = true;
     if (this.m_storageContainer != null && !this.m_storageContainer.IsDisposed)
     {
         flag = false;
     }
     this.GetStorageContainer();
     bool result = false;
     switch (saveType)
     {
     case SaveType.PlayerData:
         result = this.m_storageContainer.FileExists(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNamePlayer
         }));
         break;
     case SaveType.UpgradeData:
         result = this.m_storageContainer.FileExists(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNameUpgrades
         }));
         break;
     case SaveType.Map:
         result = this.m_storageContainer.FileExists(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNameMap
         }));
         break;
     case SaveType.MapData:
         result = this.m_storageContainer.FileExists(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNameMapData
         }));
         break;
     case SaveType.Lineage:
         result = this.m_storageContainer.FileExists(string.Concat(new object[]
         {
             "Profile",
             Game.GameConfig.ProfileSlot,
             "/",
             this.m_fileNameLineage
         }));
         break;
     }
     if (flag)
     {
         this.m_storageContainer.Dispose();
         this.m_storageContainer = null;
     }
     return result;
 }
Exemplo n.º 20
0
        public void InitializeXbox(StorageContainer c)
        {
            if (!c.FileExists("save.txt"))
            {
                c.CreateFile("save.txt").Close();

                StreamWriter writer = new StreamWriter(c.OpenFile("save.txt", FileMode.Open));

                WriteTheSave(writer);
            }

            StreamReader reader = new StreamReader(c.OpenFile("save.txt", FileMode.Open));
            ReadTheSave(reader);
        }
Exemplo n.º 21
0
        private void OpenContainer()
        {
            storageDevice = null;
            this.ShowSelectorResult = StorageDevice.BeginShowSelector( PlayerIndex.One, null, null );
            storageDevice = StorageDevice.EndShowSelector( this.ShowSelectorResult );
            if( storageDevice == null || !( storageDevice.IsConnected ) )
                throw new Exception( "StorageDevice was null or not connected." );

            IAsyncResult r = storageDevice.BeginOpenContainer( containerName, null, null );
            this.ShowSelectorResult.AsyncWaitHandle.WaitOne();

            this.container = storageDevice.EndOpenContainer( r );
        }
Exemplo n.º 22
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit

            #if (false)
            if (Mouse.GetState().LeftButton == ButtonState.Pressed && _mouseStatePrevious.LeftButton == ButtonState.Released)
            {
                _firstClick = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            }
            else if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                _release = new Vector2(Mouse.GetState().X, Mouse.GetState().Y) - _firstClick;
            }
            else
            {
                _firstClick = Vector2.Zero;
                _release = Vector2.Zero;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.E))
            {
                _firstClick.X += 0.1f;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                _firstClick.X -= 0.1f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.OemComma))
            {
                _firstClick.Y -= 0.1f;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.O))
            {
                _firstClick.Y += 0.1f;
            }
            #endif

            switch (GameState)
            {
                case GameState.MAINMENU:
                    switch (MenuState)
                    {
                        case MenuState.MAIN:
                            if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start)
                                || GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Start))
                                MenuState = MenuState.NEWLOAD;
                            if ((!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePrevious.IsButtonDown(Buttons.Back))
                                || (!GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePreviousP2.IsButtonDown(Buttons.Back)))
                            {
                                //this.Exit();
                            }
                            break;
                        case MenuState.NEWLOAD:
                            if ((!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePrevious.IsButtonDown(Buttons.Back))
                                || (!GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePreviousP2.IsButtonDown(Buttons.Back)))
                            {
                                MenuState = MenuState.MAIN;
                            }
            #if (XBOX360)
                            if (!Guide.IsVisible && !_storageDeviceWaiting && _storageDevice == null)
                            {
                                _storageResult = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
                                _storageDeviceWaiting = true;
                            }
            #endif
                            if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickDown) &&
                                    !_gamePadStatePrevious.IsButtonDown(Buttons.LeftThumbstickDown))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.LeftThumbstickDown) &&
                                    !_gamePadStatePreviousP2.IsButtonDown(Buttons.LeftThumbstickDown)))
                            {
                                _menuOption++;
            #if (!XBOX360)
                                if (_menuOption == 1)
                                    _menuOption = 2;
            #endif
                                if (_menuOption > 2)
                                    _menuOption = 0;
                            }
                            else if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickUp) &&
                                      !_gamePadStatePrevious.IsButtonDown(Buttons.LeftThumbstickUp))
                                  || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.LeftThumbstickUp) &&
                                      !_gamePadStatePreviousP2.IsButtonDown(Buttons.LeftThumbstickUp)))
                            {
                                _menuOption--;
            #if (!XBOX360)
                                if (_menuOption == 1)
                                    _menuOption = 0;
            #endif
                                if (_menuOption < 0)
                                    _menuOption = 2;
                            }

                            if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.A)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.A))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.B))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.X)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.X))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Y)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.Y))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.A)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.A))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.B)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.B))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.X)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.X))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Y)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.Y)))
                            {
                                if (_menuOption == 0)
                                {
            #if (XBOX360)
                                    if (_storageDevice != null)
                                    {
                                        MenuState = MenuState.NEW;
                                    }
            #else
                                    SaveGame saveGame = new SaveGame();
                                    saveGame.PlayerOne = new PlayerLoad();
                                    saveGame.PlayerOne.Position = new Vector2(-2, -6);
                                    saveGame.PlayerOne.NextScreen = new Vector2(6, 3);
                                    saveGame.PlayerTwo = new PlayerLoad();
                                    saveGame.PlayerTwo.Position = new Vector2(2, -6);
                                    saveGame.PlayerTwo.NextScreen = new Vector2(6, 3);
                                    saveGame.Health = 100;
                                    saveGame.PlayerOne.Collectables = Collectable.JUMP;
                                    saveGame.PlayerTwo.Collectables = Collectable.GRAB;
                                    CurrentSave = saveGame;

                                    _health = new Health();
                                    _health.MaxHealth = CurrentSave.Health;
                                    _health.CurrentHealth = CurrentSave.Health;

                                    _playerOne = new PlayerOne() { SaveGame = CurrentSave };
                                    _playerOne.Position = CurrentSave.PlayerOne.Position;
                                    _playerOne.NextScreen = CurrentSave.PlayerOne.NextScreen;
                                    _playerOne.Collectables = CurrentSave.PlayerOne.Collectables;
                                    _playerOne._content = Content;

                                    _playerTwo = new PlayerTwo() { SaveGame = CurrentSave };
                                    _playerTwo.Position = CurrentSave.PlayerTwo.Position;
                                    _playerTwo.NextScreen = CurrentSave.PlayerTwo.NextScreen;
                                    _playerTwo.Collectables = CurrentSave.PlayerTwo.Collectables;
                                    _playerTwo._content = Content;

                                    GameSwitches = CurrentSave.GameSwitches;

                                    UpdateGameSave();

                                    _playerOne.Create(_world);
                                    _playerTwo.Create(_world);

                                    _playerOne.SharedHealth = _health;
                                    _playerTwo.SharedHealth = _health;

                                    _playerOne._textures = _textures;
                                    _playerTwo._textures = _textures;
                                    GameState = GameState.PLAY;
            #endif

            #if (XBOX360)
            #endif

                                }
                                else if (_menuOption == 1)
                                {
            #if (XBOX360)
                                    if (_storageDevice != null)
                                    {
                                        MenuState = MenuState.LOAD;
                                    }
            #else
                                    MenuState = MenuState.LOAD;
            #endif
                                }
                                else
                                {
                                    // Instructions
                                    MenuState = MenuState.INSTRUCTIONS;
                                }
                            }
            #if (XBOX360)

                            //if (_storageWaiting && _storageResult.IsCompleted)
                            //{
                            //    _storageContainer = _storageDevice.EndOpenContainer(_storageResult);

                            //    Stream saveFile = _storageContainer.OpenFile(((int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString() + ".xml", FileMode.Create);
                            //    SaveGame saveGame = new SaveGame();
                            //    saveGame.Health = 100;
                            //    saveGame.PlayerOne = new PlayerLoad();
                            //    saveGame.PlayerOne.NextScreen = new Vector2(6, 3);
                            //    saveGame.PlayerOne.Position = new Vector2(0, 0);
                            //    saveGame.PlayerTwo = new PlayerLoad();
                            //    saveGame.PlayerTwo.NextScreen = new Vector2(6, 3);
                            //    saveGame.PlayerTwo.Position = new Vector2(0, 0);
                            //    XmlSerializer xmlSerializer = new XmlSerializer(saveGame.GetType());
                            //    xmlSerializer.Serialize(saveFile, saveGame);
                            //    saveFile.Close();

                            //    _storageWaiting = false;
                            //    _storageContainer.Dispose();
                            //}
                            if (_storageDeviceWaiting && _storageResult.IsCompleted)
                            {
                                _storageDevice = StorageDevice.EndShowSelector(_storageResult);
                                if (_storageDevice != null && _storageDevice.IsConnected)
                                {
                                    _storageDeviceWaiting = false;
                                }
                            }

            #endif
                            break;
                        case MenuState.INSTRUCTIONS:
                            if ((!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePrevious.IsButtonDown(Buttons.Back))
                                || (!GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePreviousP2.IsButtonDown(Buttons.Back)))
                            {
                                MenuState = MenuState.NEWLOAD;
                            }
                            break;
                        case MenuState.NEW:
            #if (XBOX360)
                            if (!_storageWaiting && (_storageContainer == null || _storageContainer.IsDisposed))
                            {
                                _storageResult = _storageDevice.BeginOpenContainer("Fariss_SaveData", null, null);
                                _storageWaiting = true;
                            }

                            if (_storageWaiting && _storageResult.IsCompleted)
                            {
                                _storageContainer = _storageDevice.EndOpenContainer(_storageResult);

                                Stream fileStream = _storageContainer.CreateFile(((int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString() + ".xml");
                                SaveGame saveGame = new SaveGame();
                                saveGame.Health = 100;
                                saveGame.PlayerOne = new PlayerLoad();
                                saveGame.PlayerOne.NextScreen = new Vector2(6, 3);
                                saveGame.PlayerOne.Position = new Vector2(3, -6);
                                saveGame.PlayerOne.Collectables = Collectable.JUMP;
                                saveGame.PlayerTwo = new PlayerLoad();
                                saveGame.PlayerTwo.NextScreen = new Vector2(6, 3);
                                saveGame.PlayerTwo.Position = new Vector2(8, -6);
                                saveGame.PlayerTwo.Collectables = Collectable.GRAB;
                                XmlSerializer xmlSerializer = new XmlSerializer(saveGame.GetType());
                                xmlSerializer.Serialize(fileStream, saveGame);
                                fileStream.Close();

                                CurrentSave = saveGame;

                                _health = new Health();
                                _health.MaxHealth = CurrentSave.Health;
                                _health.CurrentHealth = CurrentSave.Health;

                                _playerOne = new PlayerOne() { SaveGame = CurrentSave };
                                _playerOne.Position = CurrentSave.PlayerOne.Position;
                                _playerOne.NextScreen = CurrentSave.PlayerOne.NextScreen;
                                _playerOne.Collectables = CurrentSave.PlayerOne.Collectables;
                                _playerOne._content = Content;

                                _playerTwo = new PlayerTwo() { SaveGame = CurrentSave };
                                _playerTwo.Position = CurrentSave.PlayerTwo.Position;
                                _playerTwo.NextScreen = CurrentSave.PlayerTwo.NextScreen;
                                _playerTwo.Collectables = CurrentSave.PlayerTwo.Collectables;
                                _playerTwo._content = Content;

                                GameSwitches = CurrentSave.GameSwitches;

                                UpdateGameSave();

                                _playerOne.Create(_world);
                                _playerTwo.Create(_world);

                                _playerOne.SharedHealth = _health;
                                _playerTwo.SharedHealth = _health;

                                _playerOne._textures = _textures;
                                _playerTwo._textures = _textures;

                                GameState = GameState.PLAY;

                                _storageContainer.Dispose();
                                _storageWaiting = false;
                            }
            #endif
                            break;
                        case MenuState.LOAD:

                            if (_saveFiles.Count <= 0 && !_noSaves)
                            {
                                _menuOption = 0;
            #if (XBOX360)
                                if (!_storageWaiting && (_storageContainer == null || _storageContainer.IsDisposed))
                                {
                                    _storageResult = _storageDevice.BeginOpenContainer("Fariss_SaveData", null, null);
                                    _storageWaiting = true;
                                }

                                if (_storageWaiting && _storageResult.IsCompleted)
                                {
                                    _storageContainer = _storageDevice.EndOpenContainer(_storageResult);

                                    string[] fileList = _storageContainer.GetFileNames("*.xml");
                                    if (fileList.Length <= 0)
                                    {
                                        _noSaves = true;
                                        break;
                                    }
                                    foreach (string fileName in fileList)
                                    {
                                        _saveFiles.Add(fileName);
                                    }

                                    _saveFiles.Sort();
                                    _saveFiles.Reverse();

                                    _storageWaiting = false;
                                }
            #else
                                //DirectoryInfo directoryInfo = new DirectoryInfo("SaveGames");
                                //FileInfo[] directoryFiles = directoryInfo.GetFiles("*.xml");
                                //foreach (FileInfo file in directoryFiles)
                                //{
                                //    saveFiles.Add(file);
                                //    Console.WriteLine(file.Name);
                                //}
            #endif
                            }
                            if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickDown) &&
                                    !_gamePadStatePrevious.IsButtonDown(Buttons.LeftThumbstickDown))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.LeftThumbstickDown) &&
                                    !_gamePadStatePreviousP2.IsButtonDown(Buttons.LeftThumbstickDown)))
                            {
                                if (_menuOption + 1 < _saveFiles.Count)
                                    _menuOption++;
                            }
                            else if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickUp) &&
                                      !_gamePadStatePrevious.IsButtonDown(Buttons.LeftThumbstickUp))
                                  || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.LeftThumbstickUp) &&
                                      !_gamePadStatePreviousP2.IsButtonDown(Buttons.LeftThumbstickUp)))
                            {
                                if (_menuOption > 0)
                                    _menuOption--;
                            }

                            if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.A)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.A))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.B))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.X)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.X))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Y)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.Y))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.A)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.A))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.B)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.B))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.X)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.X))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Y)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.Y)))
                            {
                                // Load selected save file
            #if (XBOX360)
                                if (_saveFiles.Count > 0)
                                {
                                    if (_storageContainer != null)
                                    {
                                        Stream fileStream = _storageContainer.OpenFile(_saveFiles[_menuOption], FileMode.OpenOrCreate);
                                        SaveGame saveGame = new SaveGame();
                                        XmlSerializer xmlSerializer = new XmlSerializer(saveGame.GetType());
                                        saveGame = (SaveGame)xmlSerializer.Deserialize(fileStream);
                                        CurrentSave = saveGame;

                                        _health = new Health();
                                        _health.MaxHealth = CurrentSave.Health;
                                        _health.CurrentHealth = CurrentSave.Health;

                                        _playerOne = new PlayerOne() { SaveGame = CurrentSave };
                                        _playerOne.Position = CurrentSave.PlayerOne.Position;
                                        _playerOne.NextScreen = CurrentSave.PlayerOne.NextScreen;
                                        _playerOne.Collectables = CurrentSave.PlayerOne.Collectables;
                                        _playerOne._content = Content;

                                        _playerTwo = new PlayerTwo() { SaveGame = CurrentSave };
                                        _playerTwo.Position = CurrentSave.PlayerTwo.Position;
                                        _playerTwo.NextScreen = CurrentSave.PlayerTwo.NextScreen;
                                        _playerTwo.Collectables = CurrentSave.PlayerTwo.Collectables;
                                        _playerTwo._content = Content;

                                        GameSwitches = CurrentSave.GameSwitches;
                                        CurrentSave.CurrentGameSwitches = CurrentSave.GameSwitches;

                                        _playerOne.Create(_world);
                                        _playerTwo.Create(_world);

                                        _playerOne.SharedHealth = _health;
                                        _playerTwo.SharedHealth = _health;

                                        _playerOne._textures = _textures;
                                        _playerTwo._textures = _textures;

                                        UpdateGameSave();

                                        _storageContainer.Dispose();
                                        GameState = GameState.PLAY;
                                        _saveFiles.Clear();
                                    }
                                }
            #endif

                            }
                            // Exit
                            if ((!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePrevious.IsButtonDown(Buttons.Back))
                                || (!GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePreviousP2.IsButtonDown(Buttons.Back)))
                            {
            #if (XBOX360)
                                _storageDeviceWaiting = false;
                                _storageWaiting = false;
                                _noSaves = false;
                                _saveFiles.Clear();
                                if (_storageContainer != null && !_storageContainer.IsDisposed)
                                    _storageContainer.Dispose();
            #endif
                                MenuState = MenuState.NEWLOAD;
                            }
                            break;
                        case MenuState.GAMEOVER:
                            UnloadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y);
                            UnloadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y);
                            _playerOne.Dispose();
                            _playerTwo.Dispose();
                            if (_gameInitialOverTimer <= 2000)
                            {
                                _gameInitialOverTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
                            }
                            if (_gameInitialOverTimer > 2000)
                            {
                                _gameOverTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
                                if (_gameOverTimer > 100)
                                {
                                    _gameOverTimer = 0;
                                    _gameOverColour = new Color(255, 255, 255, _gameOverColour.A - 25);
                                }
                                if (_gameOverColour.A == 0)
                                {
                                    _gameOverColour = Color.White;
                                    _gameOverTimer = 0;
                                    MenuState = MenuState.MAIN;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    break;
                case GameState.PLAY:
                    if ((CurrentSave.CurrentGameSwitches & GameSwitches.GOT_COG) == GameSwitches.GOT_COG
                        && (CurrentSave.CurrentGameSwitches & GameSwitches.GOT_BLOB) == GameSwitches.GOT_BLOB
                        && (CurrentSave.CurrentGameSwitches & GameSwitches.GOT_POWER_CELL) == GameSwitches.GOT_POWER_CELL)
                    {
                        UnloadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y);
                        UnloadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y);
                        GameState = GameState.MAINMENU;
                        MenuState = MenuState.GAMEOVER;
                    }
            #if (XBOX360)
                    if (_trySave && _storageResult != null && _storageResult.IsCompleted)
                    {
                        _trySave = false;

                        _storageContainer = _storageDevice.EndOpenContainer(_storageResult);
                        CurrentSave.GameSwitches = CurrentSave.CurrentGameSwitches;
                        CurrentSave.PlayerOne.Position = _playerOne.Position;
                        CurrentSave.PlayerOne.NextScreen = _playerOne.NextScreen;
                        CurrentSave.PlayerOne.Collectables = _playerOne.Collectables;
                        CurrentSave.PlayerTwo.Position = _playerTwo.Position;
                        CurrentSave.PlayerTwo.NextScreen = _playerTwo.NextScreen;
                        CurrentSave.PlayerTwo.Collectables = _playerTwo.Collectables;
                        CurrentSave.Health = _playerOne.SharedHealth.MaxHealth;

                        Stream stream = _storageContainer.CreateFile(((int)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString() + ".xml");
                        XmlSerializer xmlSerializer = new XmlSerializer(CurrentSave.GetType());
                        xmlSerializer.Serialize(stream, CurrentSave);
                        _storageContainer.Dispose();
                    }
                    if (!_trySave
                        && GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Y) && _playerOne.SavePointContact
                        && GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Y) && _playerTwo.SavePointContact)
                    {
                        _trySave = true;
                        _storageResult = _storageDevice.BeginOpenContainer("Fariss_SaveData", null, null);
                    }
            #endif

                    // If both players are holding back, increment counter
                    if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back) && GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back))
                    {
                        _backCounter += gameTime.ElapsedGameTime.TotalMilliseconds;
                    }
                    else
                    {
                        _backCounter = 0;
                    }

                    if (_backCounter > 500)
                    {
                        _playerOne.Dispose();
                        _playerTwo.Dispose();
                        UnloadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y);
                        UnloadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y);
                        GameState = GameState.MAINMENU;
                        MenuState = MenuState.MAIN;
                    }

                    // Check players haven't gameovered
                    if (_health.CurrentHealth <= 0)
                    {
                        UnloadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y);
                        UnloadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y);
                        GameState = GameState.MAINMENU;
                        MenuState = MenuState.GAMEOVER;
                    }
                    // Check player hasn't gone off screen and stuff
                    UpdatePlayerScreen(_playerOne, _playerTwo);
                    UpdatePlayerScreen(_playerTwo, _playerOne);

                    // If both players are transitioning to new screens
                    if (_playerOne.NextScreen != _playerOne.CurrentScreen && _playerTwo.NextScreen != _playerTwo.CurrentScreen)
                    {
                        _playerOne.HeldObject = null;
                        _playerTwo.HeldObject = null;
                        // If both are transitioning to the same screen
                        if (_playerOne.NextScreen == _playerTwo.NextScreen)
                        {
                            // Then use virtual screen one
                            if (_playerOne.VirtualScreen == VirtualScreen.TWO)
                                _playerOne.X -= _blockScreenSize.X * 2;
                            if (_playerTwo.VirtualScreen == VirtualScreen.TWO)
                                _playerTwo.X -= _blockScreenSize.X * 2;
                            _playerOne.VirtualScreen = VirtualScreen.ONE;
                            _playerTwo.VirtualScreen = VirtualScreen.ONE;
                            UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            LoadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y, 0);
                        }
                        // If they're transitioning to different screens
                        else
                        {
                            if (_playerOne.VirtualScreen == VirtualScreen.TWO)
                                _playerOne.X -= _blockScreenSize.X * 2;
                            if (_playerTwo.VirtualScreen == VirtualScreen.ONE)
                                _playerTwo.X += _blockScreenSize.X * 2;
                            _playerOne.VirtualScreen = VirtualScreen.ONE;
                            _playerTwo.VirtualScreen = VirtualScreen.TWO;
                            UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            LoadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y, 0);
                            LoadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y, _blockScreenSize.X * 2.0f);
                        }
                    }
                    // If just one of them is
                    else if (_playerOne.NextScreen != _playerOne.CurrentScreen || _playerTwo.NextScreen != _playerTwo.CurrentScreen)
                    {
                        // If it's player one
                        if (_playerOne.NextScreen != _playerOne.CurrentScreen)
                        {
                            _playerOne.HeldObject = null;
                            // If they're moving to the same screen as player two
                            if (_playerOne.NextScreen == _playerTwo.CurrentScreen)
                            {
                                if (_playerOne.VirtualScreen == VirtualScreen.TWO && _playerTwo.VirtualScreen == VirtualScreen.ONE)
                                    _playerOne.X -= _blockScreenSize.X * 2;
                                else if (_playerOne.VirtualScreen == VirtualScreen.ONE && _playerTwo.VirtualScreen == VirtualScreen.TWO)
                                    _playerOne.X += _blockScreenSize.X * 2;
                                _playerOne.VirtualScreen = _playerTwo.VirtualScreen;
                                UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            }
                            // Otherwise if player two is on virtual screen one
                            else if (_playerTwo.VirtualScreen == VirtualScreen.ONE)
                            {
                                // Load level on virtual screen 2
                                if (_playerOne.VirtualScreen == VirtualScreen.ONE)
                                    _playerOne.X += _blockScreenSize.X * 2;
                                _playerOne.VirtualScreen = VirtualScreen.TWO;
                                LoadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y, _blockScreenSize.X * 2);
                                if (_playerOne.CurrentScreen != _playerTwo.CurrentScreen)
                                    UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            }
                            else
                            {
                                // Load level on virtual screen 1
                                if (_playerOne.VirtualScreen == VirtualScreen.TWO)
                                    _playerOne.X -= _blockScreenSize.X * 2;
                                _playerOne.VirtualScreen = VirtualScreen.ONE;
                                LoadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y, 0);
                                if (_playerOne.CurrentScreen != _playerTwo.CurrentScreen)
                                    UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            }
                        }
                        // Otherwise if it's player 2
                        else
                        {
                            _playerTwo.HeldObject = null;
                            // If they're moving to the same screen as player one
                            if (_playerTwo.NextScreen == _playerOne.CurrentScreen)
                            {
                                if (_playerTwo.VirtualScreen == VirtualScreen.TWO && _playerOne.VirtualScreen == VirtualScreen.ONE)
                                    _playerTwo.X -= _blockScreenSize.X * 2;
                                else if (_playerTwo.VirtualScreen == VirtualScreen.ONE && _playerOne.VirtualScreen == VirtualScreen.TWO)
                                    _playerTwo.X += _blockScreenSize.X * 2;
                                _playerTwo.VirtualScreen = _playerOne.VirtualScreen;
                                UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            }
                            // Otherwise if player one is on virtual screen one
                            else if (_playerOne.VirtualScreen == VirtualScreen.ONE)
                            {
                                // Load level on virtual screen 2
                                if (_playerTwo.VirtualScreen == VirtualScreen.ONE)
                                    _playerTwo.X += _blockScreenSize.X * 2;
                                _playerTwo.VirtualScreen = VirtualScreen.TWO;
                                LoadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y, _blockScreenSize.X * 2);
                                if (_playerTwo.CurrentScreen != _playerOne.CurrentScreen)
                                    UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            }
                            else
                            {
                                // Load level on virtual screen 1
                                if (_playerTwo.VirtualScreen == VirtualScreen.TWO)
                                    _playerTwo.X -= _blockScreenSize.X * 2;
                                _playerTwo.VirtualScreen = VirtualScreen.ONE;
                                LoadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y, 0);
                                if (_playerTwo.CurrentScreen != _playerOne.CurrentScreen)
                                    UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            }
                        }
                    }
                    _playerOne.CurrentScreen = _playerOne.NextScreen;
                    _playerTwo.CurrentScreen = _playerTwo.NextScreen;

                    _playerOneLevel = _levels[(int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y];
                    _playerTwoLevel = _levels[(int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y];

            #if (DEBUG)
                    if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Released && _gamePadStatePrevious.Buttons.B == ButtonState.Pressed)
                        _debugViewVisible = !_debugViewVisible;
            #endif

                    _playerOne.Update(gameTime);
                    _playerTwo.Update(gameTime);
                    UpdateView(_playerOne, _playerTwo);

                    _playerOneLevel.Update(gameTime);
                    if (_playerOne.CurrentScreen != _playerTwo.CurrentScreen)
                        _playerTwoLevel.Update(gameTime);

                    _world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f);

                    break;
                default:
                    this.Exit();
                    break;
            }

            _mouseStatePrevious = Mouse.GetState();
            _gamePadStatePrevious = GamePad.GetState(PlayerIndex.One);
            _gamePadStatePreviousP2 = GamePad.GetState(PlayerIndex.Two);

            base.Update(gameTime);
        }
Exemplo n.º 23
0
        public GameController(float mScale)
        {
            this.mScale = mScale;
            GameObject.Scale = mScale;
            asyncResult = StorageDevice.BeginShowSelector(playerIndex, null, null);
            storageDevice = StorageDevice.EndShowSelector(asyncResult);

            asyncResult = storageDevice.BeginOpenContainer("Game1StorageContainer", null, null);
            if (asyncResult.IsCompleted)
            {
                storageContainer = storageDevice.EndOpenContainer(asyncResult);
            }
        }
Exemplo n.º 24
0
 public void OpenContainer()
 {
     StorageDeviceResult = StorageDevice.BeginOpenContainer("RPG_Game_XNA", null, null);
     StorageDeviceResult.AsyncWaitHandle.WaitOne();
     StorageContainer = StorageDevice.EndOpenContainer(StorageDeviceResult);
     StorageDeviceResult.AsyncWaitHandle.Close();
 }
Exemplo n.º 25
0
        public static void LoadSaveGame()
        {
            if (!storageContainer.FileExists(filename))
            {
                FromSaveGameState = FromSaveGame.NEWGAME;

                #region Default Save Game Data

                saveGameData = new SaveGameData()
                {
                    mWaveNumber = 1,
                    // HeroAttribute data
                    mExperience = 0,
                    mGold = 1000,
                    mLevel = 1,
                    mDefaultSpeed = 4,
                    mSpellLevel = 1,
                    mHeroAttackUpgradeLevel = 1,
                    mHeroDefenseUpgradeLevel = 1,
                    mOwnedDragonCaves = 0,
                    mOwnedWolfPens = 0,
                    mOwnedBarracks = 0,
                    mOwnedArmories = 0,
                    mOwnedLibraries = 0,
                    mOwnedBonePit = 0,
                    mOwnedAbbey = 0,
                    mOwnedFireTemple = 0,
                    // Hero's Attribute data
                    mHeroMaxHealthPoints = 150,
                    mHeroMaxMana = 40,
                    mHeroBaseMinimumDamage = 55,
                    mHeroBaseMaximumDamage = 86,
                    mHeroCurrentArmor = 4,

                    // Wolf's  data
                    mWolfAttackUpgradeLevel = 1,
                    mWolfDefenseUpgradeLevel = 1,
                    mWolfAttackSpeed = 1000,
                    // Wolf's Attribute data
                    mWolfMaxHealthPoints = 60,
                    mWolfBaseMinimumDamage = 10,
                    mWolfBaseMaximumDamage = 15,
                    mWolfBaseDamageModifier = (10 + 15) / 2.0f,
                    mWolfCurrentArmor = 1,

                    // Berserker's  data
                    mBerserkerAttackUpgradeLevel = 1,
                    mBerserkerDefenseUpgradeLevel = 1,
                    mBerserkerAttackSpeed = 1100,
                    // Berserker's Attribute data
                    mBerserkerMaxHealthPoints = 120,
                    mBerserkerBaseMinimumDamage = 30,
                    mBerserkerBaseMaximumDamage = 55,
                    mBerserkerBaseDamageModifier = (33 + 55) / 2.0f,
                    mBerserkerCurrentArmor = 1,

                    // Axe Thrower's  data
                    mAxeThrowerAttackUpgradeLevel = 1,
                    mAxeThrowerDefenseUpgradeLevel = 1,
                    mAxeThrowerAttackSpeed = 1200,
                    // Axe Thrower's Attribute data
                    mAxeThrowerMaxHealthPoints = 230,
                    mAxeThrowerBaseMinimumDamage = 3,
                    mAxeThrowerBaseMaximumDamage = 10,
                    mAxeThrowerBaseDamageModifier = (13 / 2.0f),
                    mAxeThrowerCurrentArmor = 1,

                    // Arcane Mage's  data
                    mArcaneMageAttackUpgradeLevel = 1,
                    mArcaneMageDefenseUpgradeLevel = 1,
                    mArcaneMageAttackSpeed = 2300,
                    // Arcane Mage's Attribute data
                    mArcaneMageMaxHealthPoints = 180,
                    mArcaneMageBaseMinimumDamage = 60,
                    mArcaneMageBaseMaximumDamage = 80,
                    mArcaneMageBaseDamageModifier = 140 / 2.0f,
                    mArcaneMageCurrentArmor = 1,

                    // Cleric's  data
                    mClericAttackUpgradeLevel = 1,
                    mClericDefenseUpgradeLevel = 1,
                    mClericAttackSpeed = 4000,
                    // Cleric's Attribute data
                    mClericMaxHealthPoints = 300,
                    mClericBaseMinimumDamage = 10,
                    mClericBaseMaximumDamage = 30,
                    mClericBaseDamageModifier = 40 / 2.0f,
                    mClericCurrentArmor = 1,

                    // Necromancer's  data
                    mNecromancerAttackUpgradeLevel = 1,
                    mNecromancerDefenseUpgradeLevel = 1,
                    mNecromancerAttackSpeed = 2800,
                    // Necromancer's Attribute data
                    mNecromancerMaxHealthPoints = 300,
                    mNecromancerBaseMinimumDamage = 15,
                    mNecromancerBaseMaximumDamage = 35,
                    mNecromancerBaseDamageModifier = 50 / 2.0f,
                    mNecromancerCurrentArmor = 1,

                    // Fire Mage's  data
                    mFireMageAttackUpgradeLevel = 1,
                    mFireMageDefenseUpgradeLevel = 1,
                    mFireMageAttackSpeed = 2300,
                    // Fire Mage's Attribute data
                    mFireMageMaxHealthPoints = 180,
                    mFireMageBaseMinimumDamage = 60,
                    mFireMageBaseMaximumDamage = 80,
                    mFireMageBaseDamageModifier = 140 / 2.0f,
                    mFireMageCurrentArmor = 1,

                    // Dragon's  data
                    mDragonAttackUpgradeLevel = 1,
                    mDragonDefenseUpgradeLevel = 1,
                    mDragonAttackSpeed = 40000,
                    // Fire Mage's Attribute data
                    mDragonMaxHealthPoints = 700,
                    mDragonBaseMinimumDamage = 275,
                    mDragonBaseMaximumDamage = 300,
                    mDragonBaseDamageModifier = (275 + 300) / 2.0f,
                    mDragonCurrentArmor = 1
                };

                #endregion

            }

            else
            {

                Stream stream = storageContainer.OpenFile(filename, FileMode.Open);
                XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
                saveGameData = (SaveGameData)serializer.Deserialize(stream);
                stream.Close();
                storageContainer.Dispose();
                storageContainer = null;

                FromSaveGameState = FromSaveGame.SAVEGAME;

                #region Load Save Game Data

                // simplfying data
                HeroAttribute tempHeroAttribute = mHero.HeroAttribute;
                FriendlyAttribute tempWolfAttribute = FriendlyPool[0].FriendlyAttribute;
                FriendlyAttribute tempBerserkerAttribute = FriendlyPool[1].FriendlyAttribute;
                FriendlyAttribute tempArcaneMageAttribute = FriendlyPool[2].FriendlyAttribute;
                FriendlyAttribute tempAxeThrowerAttribute = FriendlyPool[3].FriendlyAttribute;
                FriendlyAttribute tempClericAttribute = FriendlyPool[4].FriendlyAttribute;
                FriendlyAttribute tempNecromancerAttribute = FriendlyPool[5].FriendlyAttribute;
                FriendlyAttribute tempFireMageAttribute = FriendlyPool[6].FriendlyAttribute;
                FriendlyAttribute tempDragonAttribute = FriendlyPool[7].FriendlyAttribute;

                WaveController.WaveNumber = saveGameData.mWaveNumber;

                // HeroAttribute data
                tempHeroAttribute.Experience = saveGameData.mExperience;
                tempHeroAttribute.Gold = saveGameData.mGold;
                tempHeroAttribute.Level = saveGameData.mLevel;
                tempHeroAttribute.MaxMana = saveGameData.mHeroMaxMana;
                tempHeroAttribute.DefaultSpeed = saveGameData.mDefaultSpeed;
                tempHeroAttribute.SpellLevel = saveGameData.mSpellLevel;
                tempHeroAttribute.AttackUpgradeLevel = saveGameData.mHeroAttackUpgradeLevel;
                tempHeroAttribute.DefenseUpgradeLevel = saveGameData.mHeroDefenseUpgradeLevel;
                tempHeroAttribute.OwnedDragonCaves = saveGameData.mOwnedDragonCaves;
                tempHeroAttribute.OwnedWolfPens = saveGameData.mOwnedWolfPens;
                tempHeroAttribute.OwnedBarracks = saveGameData.mOwnedBarracks;
                tempHeroAttribute.OwnedArmories = saveGameData.mOwnedArmories;
                tempHeroAttribute.OwnedLibraries = saveGameData.mOwnedLibraries;
                tempHeroAttribute.OwnedBonePit = saveGameData.mOwnedBonePit;
                tempHeroAttribute.OwnedAbbey = saveGameData.mOwnedAbbey;
                tempHeroAttribute.OwnedFireTemple = saveGameData.mOwnedFireTemple;
                // Hero's Attribute data
                tempHeroAttribute.MaxHealthPoints = saveGameData.mHeroMaxHealthPoints;
                tempHeroAttribute.BaseMinimumDamage = saveGameData.mHeroBaseMinimumDamage;
                tempHeroAttribute.BaseMaximumDamage = saveGameData.mHeroBaseMaximumDamage;
                tempHeroAttribute.CurrentArmor = saveGameData.mHeroCurrentArmor;

                // Wolf's data
                tempWolfAttribute.AttackSpeed = saveGameData.mWolfAttackSpeed;
                tempWolfAttribute.AttackUpgradeLevel = saveGameData.mWolfAttackUpgradeLevel;
                tempWolfAttribute.DefenseUpgradeLevel = saveGameData.mWolfDefenseUpgradeLevel;
                // Wolf's Attribute data
                tempWolfAttribute.MaxHealthPoints = saveGameData.mWolfMaxHealthPoints;
                tempWolfAttribute.BaseMinimumDamage = saveGameData.mWolfBaseMinimumDamage;
                tempWolfAttribute.BaseMaximumDamage = saveGameData.mWolfBaseMaximumDamage;
                tempWolfAttribute.CurrentArmor = saveGameData.mWolfCurrentArmor;

                //Berserker's data
                tempBerserkerAttribute.AttackSpeed = saveGameData.mBerserkerAttackSpeed;
                tempBerserkerAttribute.AttackUpgradeLevel = saveGameData.mBerserkerAttackUpgradeLevel;
                tempBerserkerAttribute.DefenseUpgradeLevel = saveGameData.mBerserkerDefenseUpgradeLevel;
                //Berserker's Attribute data
                tempBerserkerAttribute.MaxHealthPoints = saveGameData.mBerserkerMaxHealthPoints;
                tempBerserkerAttribute.BaseMinimumDamage = saveGameData.mBerserkerBaseMinimumDamage;
                tempBerserkerAttribute.BaseMaximumDamage = saveGameData.mBerserkerBaseMaximumDamage;
                tempBerserkerAttribute.CurrentArmor = saveGameData.mBerserkerCurrentArmor;

                //Axe Thrower's Data
                tempAxeThrowerAttribute.AttackSpeed = saveGameData.mAxeThrowerAttackSpeed;
                tempAxeThrowerAttribute.AttackUpgradeLevel = saveGameData.mAxeThrowerAttackUpgradeLevel;
                tempAxeThrowerAttribute.DefenseUpgradeLevel = saveGameData.mAxeThrowerDefenseUpgradeLevel;
                //Axe Thrower's Attribute data
                tempAxeThrowerAttribute.MaxHealthPoints = saveGameData.mAxeThrowerMaxHealthPoints;
                tempAxeThrowerAttribute.BaseMinimumDamage = saveGameData.mAxeThrowerBaseMinimumDamage;
                tempAxeThrowerAttribute.BaseMaximumDamage = saveGameData.mAxeThrowerBaseMaximumDamage;
                tempAxeThrowerAttribute.CurrentArmor = saveGameData.mAxeThrowerCurrentArmor;

                //Arcane Mage's data
                tempArcaneMageAttribute.AttackSpeed = saveGameData.mArcaneMageAttackSpeed;
                tempArcaneMageAttribute.AttackUpgradeLevel = saveGameData.mArcaneMageAttackUpgradeLevel;
                tempArcaneMageAttribute.DefenseUpgradeLevel = saveGameData.mArcaneMageDefenseUpgradeLevel;
                //Arcane Mage's Attribute data
                tempArcaneMageAttribute.MaxHealthPoints = saveGameData.mArcaneMageMaxHealthPoints;
                tempArcaneMageAttribute.BaseMinimumDamage = saveGameData.mArcaneMageBaseMinimumDamage;
                tempArcaneMageAttribute.BaseMaximumDamage = saveGameData.mArcaneMageBaseMaximumDamage;
                tempArcaneMageAttribute.CurrentArmor = saveGameData.mArcaneMageCurrentArmor;

                //Cleric's data
                tempClericAttribute.AttackSpeed = saveGameData.mClericAttackSpeed;
                tempClericAttribute.AttackUpgradeLevel = saveGameData.mClericAttackUpgradeLevel;
                tempClericAttribute.DefenseUpgradeLevel = saveGameData.mClericDefenseUpgradeLevel;
                //Cleric's Attributes data
                tempClericAttribute.MaxHealthPoints = saveGameData.mClericMaxHealthPoints;
                tempClericAttribute.BaseMinimumDamage = saveGameData.mClericBaseMinimumDamage;
                tempClericAttribute.BaseMaximumDamage = saveGameData.mClericBaseMaximumDamage;
                tempClericAttribute.CurrentArmor = saveGameData.mClericCurrentArmor;

                //Necromancer's data
                tempNecromancerAttribute.AttackSpeed = saveGameData.mNecromancerAttackSpeed;
                tempNecromancerAttribute.AttackUpgradeLevel = saveGameData.mNecromancerAttackUpgradeLevel;
                tempNecromancerAttribute.DefenseUpgradeLevel = saveGameData.mNecromancerDefenseUpgradeLevel;
                //Necromancer's Attribute data
                tempNecromancerAttribute.MaxHealthPoints = saveGameData.mNecromancerMaxHealthPoints;
                tempNecromancerAttribute.BaseMinimumDamage = saveGameData.mNecromancerBaseMinimumDamage;
                tempNecromancerAttribute.BaseMaximumDamage = saveGameData.mNecromancerBaseMaximumDamage;
                tempNecromancerAttribute.CurrentArmor = saveGameData.mNecromancerCurrentArmor;

                //Fire Mage's data
                tempFireMageAttribute.AttackSpeed = saveGameData.mFireMageAttackSpeed;
                tempFireMageAttribute.AttackUpgradeLevel = saveGameData.mFireMageAttackUpgradeLevel;
                tempFireMageAttribute.DefenseUpgradeLevel = saveGameData.mFireMageDefenseUpgradeLevel;
                //Fire Mage's Attribute data
                tempFireMageAttribute.MaxHealthPoints = saveGameData.mFireMageMaxHealthPoints;
                tempFireMageAttribute.BaseMinimumDamage = saveGameData.mFireMageBaseMinimumDamage;
                tempFireMageAttribute.BaseMaximumDamage = saveGameData.mFireMageBaseMaximumDamage;
                tempFireMageAttribute.CurrentArmor = saveGameData.mFireMageCurrentArmor;

                //Dragon's data
                tempDragonAttribute.AttackSpeed = saveGameData.mDragonAttackSpeed;
                tempDragonAttribute.AttackUpgradeLevel = saveGameData.mDragonAttackUpgradeLevel;
                tempDragonAttribute.DefenseUpgradeLevel = saveGameData.mDragonDefenseUpgradeLevel;
                //Dragon's Attribute data
                tempDragonAttribute.MaxHealthPoints = saveGameData.mDragonMaxHealthPoints;
                tempDragonAttribute.BaseMinimumDamage = saveGameData.mDragonBaseMinimumDamage;
                tempDragonAttribute.BaseMaximumDamage = saveGameData.mDragonBaseMaximumDamage;
                tempDragonAttribute.CurrentArmor = saveGameData.mDragonCurrentArmor;

                #endregion

            }
        }
Exemplo n.º 26
0
        private void OpenContainer()
        {
            if (!containerOpen)
                //container = device.OpenContainer("ZombieSmashers");
                container = OpenContainer(device,"ZombieSmashers");

            containerOpen = true;
        }
Exemplo n.º 27
0
 public Reader(StorageContainer sc)
 {
     storageContainer = sc;
 }
Exemplo n.º 28
0
		// Private method to handle the creation of the StorageDevice
		private StorageContainer Open (string displayName) 
		{
			storageContainer = new StorageContainer(this, displayName, this.player);
			return storageContainer;
		}
Exemplo n.º 29
0
        public static HighScoreData LoadHighScores()
        {
            HighScoreTracker.InitializeHighScores();

            HighScoreData data = null;

            try
            {
                IAsyncResult result =
                            HighScoreTracker.device.BeginOpenContainer("StorageDemo", null, null);
                result.AsyncWaitHandle.WaitOne();
                container = HighScoreTracker.device.EndOpenContainer(result);
                result.AsyncWaitHandle.Close();

                // Open the file
                Stream stream = container.OpenFile("highscores.sav", FileMode.Open);
                //FileStream stream = File.Open(highScorePath, FileMode.OpenOrCreate,
                //FileAccess.Read);
                try
                {

                    // Read the data from the file
                    XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
                    data = (HighScoreData)serializer.Deserialize(stream);
                    if (data != null)
                        cachedData = data;
                }
                catch(Exception e)
                {
                }
                finally
                {
                    // Close the file
                    stream.Close();
                }
            }
            catch
            {
            }
            finally
            {
                if(container!=null)
                    container.Dispose();
                if(data == null)
                    data = cachedData;
            }

            return data;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Saves level unlock and scoring information
        /// 
        /// PC saving is straightforward - but xDoc.Save() will not work on xbox360.
        /// Instead we use the built in XmlSerializer class to serialize an element out to an xml file.
        /// We build our Xelement like normal - but instead of saving that directly using XDocument.Save()
        /// we place this XElement into a struct, and use XmlSerializer to serialize the data out into a storage
        /// device on the xbox.
        /// </summary>
        /// 
        public void Save()
        {
            XElement xLevels = new XElement(XmlKeys.LEVELS);
            foreach (LevelInfo l in mLevels)
                xLevels.Add(l.Export());
            XDocument xDoc = new XDocument();
            xDoc.Add(xLevels);

            #if XBOX360
            IAsyncResult result;
            try
            {
                if (!mDeviceSelected)
                {
                    StorageDevice.BeginShowSelector(((ControllerControl)mControls).ControllerIndex, this.SelectDevice, null);
                    mDeviceSelected = true;
                }
            }
            catch (Exception e)
            {
                string errTemp = e.ToString();
                return;
            }

            if (device == null || !device.IsConnected)
            {
                return;
            }
            try
            {
                result = device.BeginOpenContainer("Mr Gravity", null, null);
                result.AsyncWaitHandle.WaitOne();
                container = device.EndOpenContainer(result);

                //container.DeleteFile("TrialLevelList.xml");
                //container.DeleteFile("LevelList.xml");

                Stream stream;
                if (container.FileExists("LevelList.xml"))
                {
                    container.DeleteFile("LevelList.xml");
                }
                stream = container.CreateFile("LevelList.xml");
                XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
                SaveGameData data = new SaveGameData();
                data.SaveData = xLevels;
                serializer.Serialize(stream, data);
                stream.Close();
                container.Dispose();
                result.AsyncWaitHandle.Close();
            }
            catch (Exception e)
            {
                string execTemp = e.ToString();
                return;
            }

            #else
            xDoc.Save("..\\..\\..\\Content\\Levels\\Info\\LevelList.xml");
            #endif
        }
Exemplo n.º 31
0
 // Private method to handle the creation of the StorageDevice
 private StorageContainer Open(string displayName)
 {
     storageContainer = new StorageContainer(this, displayName, this.player);
     return(storageContainer);
 }