public GameViewModel(int totalQuestions, IImageProvider imageProvider, IStorageProvider storageProvider) { _imageProvider = imageProvider; _storageProvider = storageProvider; // register all the events CommandEvents.ContinueButtonPressed += new EventHandler(ContinueButtonPressed); CommandEvents.AnswerButtonPressed += new EventHandler(AnswerButtonPressed); CommandEvents.HighScoreContinueButtonPressed += new EventHandler(HighScoreContinueButtonPressed); DisplayHighScore += new EventHandler(DisplayScore); // check to see whether any game state is already loaded if (_storageProvider.GameStateExists()) { _game = _storageProvider.LoadGameState(); // check if the player was in the middle of a question if (_game.CurrentQuestion.Answered) { DisplayQuestion(); ContinueButtonPressed(this, new EventArgs()); } else { DisplayQuestion(); } } else { _game = new Game(totalQuestions); ContinueButtonPressed(this, new EventArgs()); } }
public void DeleteGameState() { dummyGameState = null; }
public void SaveGameState(Game currentGame) { dummyGameState = currentGame; }
public void SaveGameState(Game currentGame) { // first reset any existing data DeleteGameState(); // open the file IsolatedStorageFileStream isfStream = isf.OpenFile(gameStateFileName, System.IO.FileMode.CreateNew); // serialize the HighScoreTable XmlSerializer serializer = new XmlSerializer(typeof(Game)); serializer.Serialize(isfStream, currentGame); isfStream.Close(); }