Ejemplo n.º 1
0
        /// <summary>
        /// A callback for the BeginStorageDeviceSelectorPrompt.
        /// </summary>
        /// <param name="result">The result of the prompt.</param>
        private void StorageDeviceSelectorCallback(IAsyncResult result)
        {
            //get the storage device
            storageDevice = Guide.EndShowStorageDeviceSelector(result);

            // if we got a valid device, fire off the DeviceSelected event so
            // that the game knows we have a device
            if (storageDevice != null && storageDevice.IsConnected)
            {
                if (DeviceSelected != null)
                {
                    DeviceSelected(this, null);
                }
            }

            // if we don't have a valid device
            else
            {
                // prepare our event arguments for use
                PrepareEventArgs(eventArgs);

                // let the game know the device selector was cancelled so it
                // can tell us how to handle this
                if (DeviceSelectorCanceled != null)
                {
                    DeviceSelectorCanceled(this, eventArgs);
                }

                // handle the result of the event
                HandleEventArgResults();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Callback method for loading the high scores from the drive.
        /// </summary>
        private static void LoadHighScoresCallback(IAsyncResult result)
        {
            if ((result != null) && result.IsCompleted)
            {
#if !MONOMAC
                MarbletsGame.StorageDevice = Guide.EndShowStorageDeviceSelector(result);
#endif
            }
            if ((MarbletsGame.StorageDevice != null) &&
                MarbletsGame.StorageDevice.IsConnected)
            {
                using (StorageContainer storageContainer =
                           MarbletsGame.StorageDevice.OpenContainer("Marblets"))
                {
                    string highscoresPath = Path.Combine(storageContainer.Path,
                                                         "highscores.xml");
                    if (File.Exists(highscoresPath))
                    {
                        using (FileStream file =
                                   File.Open(highscoresPath, FileMode.Open))
                        {
                            XmlSerializer serializer =
                                new XmlSerializer(typeof(List <int>));
                            HighScores = (List <int>)serializer.Deserialize(file);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /* Completion on the storage selection request.
         */
        protected virtual void SelectedStorage(IAsyncResult ar)
        {
            StorageDevice dev = Guide.EndShowStorageDeviceSelector(ar);

            Queue(delegate()
            {
                SetDevice(dev);
            }, mainActions);
        }
Ejemplo n.º 4
0
        //* -----------------------------------------------------------------------*
        /// <summary>
        /// ストレージ セレクター ユーザー インターフェイスの表示を終了します。
        /// </summary>
        ///
        /// <param name="result">
        /// メソッドの進行状況の追跡に使用されるオブジェクト。
        /// </param>
        public StorageDevice EndShowStorageDeviceSelector(IAsyncResult result)
        {
            StorageDevice res = null;

            if (isAvaliableUseGamerService)
            {
                res = Guide.EndShowStorageDeviceSelector(result);
            }
            return(res);
        }
Ejemplo n.º 5
0
        //* -----------------------------------------------------------------------*
        /// <summary>
        /// 読み出しデバイス選択ダイアログを終了した時に非同期で呼び出されます。
        /// ここから自動的に読み出し処理へ入ります。
        /// </summary>
        ///
        /// <param name="result">非同期操作のステータス</param>
        private void onSelectedDevice(IAsyncResult result)
        {
            CIOInfo.instance.device = CGuideWrapper.instance == null?
                                      Guide.EndShowStorageDeviceSelector(result) :
                                          CGuideWrapper.instance.EndShowStorageDeviceSelector(result);

            CIOInfo info = CIOInfo.instance;

            load(
                info.deviceReady ?
                info.getPath(fileName) : null);
        }
Ejemplo n.º 6
0
        private StorageDevice GetStorageDevice()
        {
            storageResult = Guide.BeginShowStorageDeviceSelector(null, null);
            while (!storageResult.IsCompleted)
            {
                this.Tick();
            }
            StorageDevice storageDevice = Guide.EndShowStorageDeviceSelector(storageResult);

            storageResult = null;
            return(storageDevice);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called when a storage device selector has been dismissed.
        /// </summary>
        /// <param name="result">The result of the asynchronous operation.</param>
        void StorageDeviceDismissed(IAsyncResult result)
        {
            device = Guide.EndShowStorageDeviceSelector(result);
            UpdateStatusFromDevice();

            if (Status == StorageProviderStatus.Connected)
            {
                OpenSession(currentSessionContext);
            }
            else
            {
                HandleCancelledBehavior();
            }
        }
Ejemplo n.º 8
0
 private static void GetDevice(IAsyncResult result)
 {
     device = Guide.EndShowStorageDeviceSelector(result);
     if (device != null && device.IsConnected)
     {
         if (LoadSettings)
         {
             DoLoadSettings();
         }
         else
         {
             DoSaveSettings();
         }
     }
 }
Ejemplo n.º 9
0
        void OpenFile(string filename)
        {
            IAsyncResult result = null;
            SerializeUtils <GameVariables> gameVariables = new SerializeUtils <GameVariables>();

            if (!Guide.IsVisible)
            {
                result = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One, null, null);
            }
            if (result.IsCompleted)
            {
                StorageDevice device = Guide.EndShowStorageDeviceSelector(result);
                gameVariables.LoadData(device, filename);
                LoadVariables(gameVariables);
            }
        }
Ejemplo n.º 10
0
 //* -----------------------------------------------------------------------*
 /// <summary>
 /// 読み出しデバイス選択ダイアログを終了した時に非同期で呼び出されます。
 /// ここから自動的に読み出し処理へ入ります。
 /// </summary>
 ///
 /// <param name="result">非同期操作のステータス</param>
 private void load(IAsyncResult result)
 {
     device = Guide.EndShowStorageDeviceSelector(result);
     if (device != null && device.IsConnected)
     {
         if (container == null)
         {
             container = device.OpenContainer(CODENAME);
         }
         __load(Path.Combine(container.Path, FILE));
     }
     else
     {
         __load(null);
     }
 }
Ejemplo n.º 11
0
        private void FindStorageDevice(IAsyncResult result)
        {
            StorageDevice storageDevice = Guide.EndShowStorageDeviceSelector(result);

            if (storageDevice != null)
            {
                if (result.AsyncState == "saveRequest")
                {
                    SaveGame(storageDevice);
                }
                else if (result.AsyncState == "loadRequest")
                {
                    LoadGame(storageDevice);
                }
            }
        }
Ejemplo n.º 12
0
        // Override OnExiting function to stop all sounds and save game data
        protected override void OnExiting(Object sender, EventArgs args)
        {
            loopingMusic.Stop(AudioStopOptions.Immediate);
            loopingMusic.Dispose();

            // Save the current high score
            if ((result != null) && result.IsCompleted)
            {
                device = Guide.EndShowStorageDeviceSelector(result);
                result = null;
            }
            if ((device != null) && device.IsConnected)
            {
                SaveGameData();
            }

            base.OnExiting(sender, args);
        }
Ejemplo n.º 13
0
        public void OpenLevel(string filename)
        {
            form.IncrementProgressBar(25);
            IAsyncResult result = null;
            SerializeUtils <LevelData> levelData = new SerializeUtils <LevelData>();

            if (!Guide.IsVisible)
            {
                result = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One, null, null);
            }
            if (result.IsCompleted)
            {
                StorageDevice device = Guide.EndShowStorageDeviceSelector(result);
                levelData.LoadData(device, filename);
                form.IncrementProgressBar(25);
                LoadLevel(levelData);
            }
        }
Ejemplo n.º 14
0
        void BackgroundLoadContent()
        {
            // First thing we need to do is get a valid storage device for loading and saving
            // high scores.  Since this is a background thread, we can block on it; rendering the guide
            // for Xbox 360 will happen on the main thread.
            IAsyncResult result = Guide.BeginShowStorageDeviceSelector(null, null);

            while (!result.IsCompleted)
            {
            }
            StorageDevice device = Guide.EndShowStorageDeviceSelector(result);

            ScreenManager.Game.Services.AddService(typeof(StorageDevice), device);

            ScreenManager.Game.Content.Load <object>("alien_hit");
            ScreenManager.Game.Content.Load <object>("alien1");
            ScreenManager.Game.Content.Load <object>("background");
            ScreenManager.Game.Content.Load <object>("badguy_blue");
            ScreenManager.Game.Content.Load <object>("badguy_green");
            ScreenManager.Game.Content.Load <object>("badguy_orange");
            ScreenManager.Game.Content.Load <object>("badguy_red");
            ScreenManager.Game.Content.Load <object>("bullet");
            ScreenManager.Game.Content.Load <object>("cloud1");
            ScreenManager.Game.Content.Load <object>("cloud2");
            ScreenManager.Game.Content.Load <object>("fire");
            ScreenManager.Game.Content.Load <object>("gamefont");
            ScreenManager.Game.Content.Load <object>("ground");
            ScreenManager.Game.Content.Load <object>("hills");
            ScreenManager.Game.Content.Load <object>("laser");
            ScreenManager.Game.Content.Load <object>("menufont");
            ScreenManager.Game.Content.Load <object>("moon");
            ScreenManager.Game.Content.Load <object>("mountains_blurred");
            ScreenManager.Game.Content.Load <object>("player_hit");
            ScreenManager.Game.Content.Load <object>("scorefont");
            ScreenManager.Game.Content.Load <object>("smoke");
            ScreenManager.Game.Content.Load <object>("sun");
            ScreenManager.Game.Content.Load <object>("tank");
            ScreenManager.Game.Content.Load <object>("tank_fire");
            ScreenManager.Game.Content.Load <object>("tank_tire");
            ScreenManager.Game.Content.Load <object>("tank_top");
            ScreenManager.Game.Content.Load <object>("title");
            ScreenManager.Game.Content.Load <object>("titlefont");
        }
Ejemplo n.º 15
0
        private void FinishSavingHighScores()
        {
            storageDevice = Guide.EndShowStorageDeviceSelector(result);
            if (storageDevice.IsConnected)
            {
                //storage device is connected, open container and finish saving the high scores
                if (container == null)
                {
                    container = storageDevice.OpenContainer(containerName);
                }

                // Get the path of the save game
                string fullpath = Path.Combine(container.Path, highScoresFilename);

                // Open the file, creating it if necessary
                FileStream stream = File.Open(fullpath, FileMode.OpenOrCreate);
                try
                {
                    // Convert the object to XML data and put it in the stream
                    XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
                    serializer.Serialize(stream, entries);
                }
                finally
                {
                    // Close the file
                    stream.Close();

                    //Since we saved, we will also dispose the container
                    //so it will stick in case the console is turned off
                    //before the game exits
                    if (container != null)
                    {
                        container.Dispose();
                        container = null;
                    }
                }
            }
            else
            {
                SaveHighScores();
            }
        }
Ejemplo n.º 16
0
 private void StorageDeviceSelectorCallback(IAsyncResult result)
 {
     _storageDevice = Guide.EndShowStorageDeviceSelector(result);
     if (_storageDevice != null && _storageDevice.IsConnected)
     {
         if (DeviceSelected != null)
         {
             DeviceSelected(this, null);
         }
     }
     else
     {
         PrepareEventArgs(EventArgs);
         if (DeviceSelectorCanceled != null)
         {
             DeviceSelectorCanceled(this, EventArgs);
         }
         HandleEventArgResults();
     }
 }
Ejemplo n.º 17
0
        void SaveVariables(string filename)
        {
            {
                IAsyncResult result = null;
                SerializeUtils <GameVariables> gameVariables2 = new SerializeUtils <GameVariables>();

                gameVariables2.Data = gameVariables;
                if (!Guide.IsVisible)
                {
                    result = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One, null, null);
                }
                if (result.IsCompleted)
                {
                    StorageDevice device = Guide.EndShowStorageDeviceSelector(result);
                    if (device.IsConnected)
                    {
                        gameVariables2.SaveData(device, filename);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        private void FinishLoadingHighScores()
        {
            storageDevice = Guide.EndShowStorageDeviceSelector(result);
            if (storageDevice.IsConnected)
            {
                //storage device is connected, open container and finish saving the high scores
                if (container == null)
                {
                    container = storageDevice.OpenContainer(containerName);
                }

                // Get the path of the save game
                string fullpath = Path.Combine(container.Path, highScoresFilename);

                if (!File.Exists(fullpath))
                {
                    InitializeDefaultHighScores();
                    return;
                }

                // Open the file, creating it if necessary
                FileStream stream = File.Open(fullpath, FileMode.Open, FileAccess.Read);
                try
                {
                    // Convert the object to XML data and put it in the stream
                    XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
                    entries = (HighScoreData)serializer.Deserialize(stream);
                }
                finally
                {
                    // Close the file
                    stream.Close();
                }
            }
            else
            {
                LoadHighScores();
            }
        }
Ejemplo n.º 19
0
        private void FindNameStorageDevice(IAsyncResult result)
        {
            StorageDevice storageDevice = Guide.EndShowStorageDeviceSelector(result);

            if (storageDevice != null)
            {
                string   value        = (string)result.AsyncState;
                string[] splitStrings = value.Split(':');

                if (splitStrings[0] == "saveRequest")
                {
                    SaveNameData(splitStrings[1], storageDevice, _nameWrapper);
                }
                if (splitStrings[0] == "loadRequest")
                {
                    LoadNameData(splitStrings[1], storageDevice);
                }

                while (!result.IsCompleted)
                {
                }
            }
        }
Ejemplo n.º 20
0
        }   // end of InitStorageContainer

        /// <summary>
        /// Callback for Guide.BeginShowStorageDeviceSelector().
        /// </summary>
        /// <param name="result"></param>
        private static void SelectDoneCallback(IAsyncResult result)
        {
            requestOpen = false;

            storageDevice = Guide.EndShowStorageDeviceSelector(result);

            if (storageDevice != null)
            {
                if (!Storage.InitStorageContainer())
                {
                    // OpenContainer failed so try again.
                    if (!requestOpen
#if CLIENT
                        && !GamerServices.IsGuideVisible
#endif
                        )
                    {
                        try
                        {
                            Guide.BeginShowStorageDeviceSelector(SelectDoneCallback, null);
                            requestOpen = true;
                        }
                        catch
                        {
                            /// Probably the guide got opened but IsVisible wasn't
                            /// set yet. We'll just try again later.
                        }
                    }
                }
            }
            else
            {
                // The user chose <B> from the dialog.  Inform user that they
                // must choose a storage device.  Also allow them to quit.
                userChoseNoStorage = true;
            }
        }   // end of SelectDoneCallback()
Ejemplo n.º 21
0
        //* ────________________________________*
        //* methods ───────────────────────────────-*

#if XBOX360
        //* -----------------------------------------------------------------------*
        /// <summary>デバイスを初期化します。</summary>
        ///
        /// <param name="result">非同期操作のステータス。</param>
        public void initializeDevice(IAsyncResult result)
        {
            device = Guide.EndShowStorageDeviceSelector(result);
        }
Ejemplo n.º 22
0
 public StorageDevice EndShowStorageDeviceSelector(IAsyncResult result)
 {
     return(Guide.EndShowStorageDeviceSelector(result));
 }
Ejemplo n.º 23
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)
        {
            // Allow the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                runGame = false;
            }

            // We need to load the game data
            if (GameLoadRequested)
            {
                if ((result != null) && result.IsCompleted)
                {
                    device = Guide.EndShowStorageDeviceSelector(result);
                    result = null;
                    if ((device == null) || !device.IsConnected)
                    {
                        // Reset the request flag
                        GameLoadRequested = false;
                    }
                }
                if ((device != null) && device.IsConnected)
                {
                    // Load game data
                    GetSavedData();
                    // Reset the request flag
                    GameLoadRequested = false;
                }
            }

            // Update sounds
            audioEngine.Update();

            // Update input
            lastGamePadState     = currentGamePadState;
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);
            lastKeyboardState    = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();


            // Wait 3 seconds until we start playing
            if (gameTime.TotalGameTime.Seconds > 3 && playingGame == false)
            {
                playingGame = true;
                // Get the storage device
                result = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One,
                                                              null, null);
            }

            // After 3 seconds play the game
            if (playingGame)
            {
                // Update the players Catapult
                playerCatapult.Update(gameTime);

                if (playerCatapult.CurrentState == CatapultState.Reset)
                {
                    // reset background and log
                    screenPosition = Vector2.Zero;

                    endObjectPos.X = 1000;
                    endObjectPos.Y = 500;
                }

                // Move background
                if (playerCatapult.CurrentState == CatapultState.ProjectileFlying)
                {
                    screenPosition.X = (playerCatapult.PumpkinPosition.X -
                                        playerCatapult.PumpkinLaunchPosition) * -1.0f;
                    endObjectPos.X = (playerCatapult.PumpkinPosition.X -
                                      playerCatapult.PumpkinLaunchPosition) *
                                     -1.0f + 1000;
                }

                // Calculate the pumpkin flying distance
                if (playerCatapult.CurrentState == CatapultState.ProjectileFlying ||
                    playerCatapult.CurrentState == CatapultState.ProjectileHit)
                {
                    pumpkinDistance = playerCatapult.PumpkinPosition.X -
                                      playerCatapult.PumpkinLaunchPosition;
                    pumpkinDistance /= 15.0f;
                }

                // Is this a high score
                if (highScore < pumpkinDistance)
                {
                    highScore = (int)pumpkinDistance;
                }
            }

            // Exit game
            if (!runGame)
            {
                Exit();
            }

            base.Update(gameTime);
        }