X hits on this document

211 views

0 shares

0 downloads

0 comments

90 / 102

Due to security considerations, Windows Phone isolates applications from each other and does not provide means like shared file system to persist data from applications.  This is why we need a special means, the Isolated storage, to persist the state of our game.

Task 1 – Utilize Tombstoning and Isolated storage to store the game state

Though Tombstoning and Isolated storage have similar capabilities, they both can store the game state, we use them in different scenarios.

We use Tombstoning to store the state of the game when we launch another application, e.g. via the "Start" button or using the above-mentioned Choosers and Launchers.

We use Isolated storage to store the state of the game when are going to exit the game, but want to continue next time from the same place. We exit the game, e.g. via "Back" button when we go before the first page of the game or when we explicitly call the "Exit" method of the Game class.

Fortunately, Windows Phone itself recognizes those scenarios and raises appropriate events, which we may handle in our game.

In this task, we extend the CatapultGame class with event handlers that save and restore the application state using Tombstoning and Isolated storage capabilities and assign those handlers to the correspondent events raised by the Windows Phone:

188.

Open the CatapultGame.cs file.

189.

Replace the "Using Statements" region with the following code:

C#

#region Using Statements

using System;

using System.Collections.Generic;

using System.Linq;

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Audio;

using Microsoft.Xna.Framework.Content;

using Microsoft.Xna.Framework.GamerServices;

using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework.Input;

using Microsoft.Xna.Framework.Input.Touch;

using Microsoft.Xna.Framework.Media;

using CatapultGame;

using GameStateManagement;

using Microsoft.Phone.Shell;

using System.IO.IsolatedStorage;

using System.Xml.Serialization;

using System.IO;

#endregion

Page | 90

Document info
Document views211
Page views211
Page last viewedFri Dec 02 18:22:49 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments