Пример #1
0
 private void SaveToDevice(IAsyncResult result)
 {
     device = StorageDevice.EndShowSelector(result);
     if (device != null && device.IsConnected)
     {
         SaveGame SaveData = new SaveGame()
         {
             IsFirstTime = false,
         };
     IAsyncResult r = device.BeginOpenContainer(ContainerName,null,null);
     result.AsyncWaitHandle.WaitOne();
     StorageContainer container = device.EndOpenContainer(r);
     if(container.FileExists(Filename))
         container.DeleteFile(Filename);
     Stream stream = container.CreateFile(Filename);
     XmlSerializer serializer = new XmlSerializer(typeof(SaveGame));
     serializer.Serialize(stream,SaveData);
     stream.Close();
     container.Dispose();
     result.AsyncWaitHandle.Close();
     }
 }
Пример #2
0
 /// <summary>
 /// load all files
 /// </summary>
 private void Load()
 {
     gameState = new SwitchGameState(GraphicsDevice, graphics, Content);
     music = new Music(graphics, GraphicsDevice, Content);
     button = new ButtonSetUp(graphics, GraphicsDevice, Content);
     popup = new FirstPopup(gameState);
     timer = new Timer(200);
     save = new SaveGame("..\\..\\..\\save.xml", "root");
     justFinshed = true;
 }
Пример #3
0
 private void Replace()
 {
     saveData = new SaveGame();
     IsFirstTime = saveData.IsFirstTime;
 }
Пример #4
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)
        {
            //sets the mouse handle
            Mouse.WindowHandle = Window.Handle;

            //loading logic
            if (!loadingThread.IsAlive)
            {
                if ((justFinshed) && (!isDoneLoading))
                {
                    save = new SaveGame("C:/Users/" + Environment.UserName + "/Documents/RubikCube/save.xml", "root");
                    isDoneLoading = true;
                    Debug.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); //should upgrade to DebbugBorders (~~~) but too afraid to StuckOverflow the game.
                }
                //load bools from save file
                foreach (Tuple<string, string> b in save.LoadBools())
                {
                    if (b.Item1 == "isFirstTime")
                        isFirstTime = Convert.ToBoolean(b.Item2);
                }

                // checks if the loading & the Clocks are done
                if (justFinshed && clocks.CallTimer(gameTime))
                {
                    MediaPlayer.Resume();
                    if (isFirstTime)
                    {
                        save.AddBool("isFirstTime", "false");
                    }
                    justFinshed = false;
                }
                //neccesary updates
                button.BtnMute.Update(true, gameTime);
                button.BtnUnMute.Update(true, gameTime);
                MuteEvent();
                gameState.Update(gameTime, GraphicsDevice,music);
            }
            else
            {
                //loading animation
                loading.Update(gameTime);
                //pause media player to prevent bugs
                if (MediaPlayer.State != MediaState.Paused)
                    MediaPlayer.Pause();
            }
            base.Update(gameTime);
        }