X hits on this document

243 views

0 shares

0 downloads

0 comments

97 / 102

{

   // Save to Isolated Storage file

   using (IsolatedStorageFile isolatedStorageFile

       = IsolatedStorageFile.GetUserStoreForApplication())

   {

       // If user choose to save, create a new file

       using (IsolatedStorageFileStream fileStream

           = isolatedStorageFile.CreateFile(fileName))

       {

using (StreamWriter streamWriter = new StreamWriter(fileStream))

           {

               // Write date to the file

               streamWriter.WriteLine(gameplayScreen.player.Score);

streamWriter.WriteLine(gameplayScreen.computer.Score);

               streamWriter.WriteLine(gameplayScreen.isHumanTurn);

               streamWriter.Close();

           }

       }

   }

}

/// <summary>

/// Saves the gamepleay screen data to State Object

/// </summary>

/// <param name="gameplayScreen"></param>

private static void SaveToStateObject(GameplayScreen gameplayScreen)

{

   // Save date to the State object

   PhoneApplicationService.Current.State.Add("HumanScore", gameplayScreen.player.Score);

   PhoneApplicationService.Current.State.Add("PhoneScore", gameplayScreen.computer.Score);

   PhoneApplicationService.Current.State.Add("isHumanTurn", gameplayScreen.isHumanTurn);

}

#endregion

Note that when the application state is reloaded from the Isolated storage, the player is asked if continue the saved game or start the new one.

195.

Open file GameplayScreen.cs located in “Screens” folder.

196.

Locate function LoadContent and replace it with the following code:

C#

public override void LoadContent()

{

   // Load textures

Page | 97

Document info
Document views243
Page views243
Page last viewedTue Dec 06 12:07:08 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments