예제 #1
0
        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());
            }
        }