protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            MatchingGameViewModel game;

            string isolatedStorageFileName = this.LoadState<string>(IsolatedStorageFileNameKey);
            if (!string.IsNullOrEmpty(isolatedStorageFileName))
            {
                MainViewModel.Instance.IsolatedStorageFileName = isolatedStorageFileName;
                MainViewModel.Instance.GameMode = this.LoadState<GameModes>(GameModeKey);

                int[] cardsOrder = this.LoadState<int[]>(CardsOrderKey);
                bool[] cardsUseDuplicate = this.LoadState<bool[]>(CardsUseDuplicateKey);
                bool[] cardsIsMatched = this.LoadState<bool[]>(CardsIsMatchedKey);
                bool[] cardsIsSelected = this.LoadState<bool[]>(CardsIsSelectedKey);

                // load stream from isolated storage
                MainViewModel.Instance.LoadDeckFromIsolatedStorage();

                bool isMatchingGame = MainViewModel.Instance.GameMode == GameModes.MatchingGame;
                game = new MatchingGameViewModel(MainViewModel.Instance.Decks.SelectedDeck, isMatchingGame, cardsOrder, cardsUseDuplicate, cardsIsMatched, cardsIsSelected);
            }
            else
            {
                bool isMatchingGame = MainViewModel.Instance.GameMode == GameModes.MatchingGame;
                game = new MatchingGameViewModel(MainViewModel.Instance.Decks.SelectedDeck, isMatchingGame);
            }

            MainViewModel.Instance.CurrentView = game;
            DataContext = MainViewModel.Instance.CurrentView;
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            MatchingGameViewModel game;

            string isolatedStorageFileName = this.LoadState <string>(IsolatedStorageFileNameKey);

            if (!string.IsNullOrEmpty(isolatedStorageFileName))
            {
                MainViewModel.Instance.IsolatedStorageFileName = isolatedStorageFileName;
                MainViewModel.Instance.GameMode = this.LoadState <GameModes>(GameModeKey);

                int[]  cardsOrder        = this.LoadState <int[]>(CardsOrderKey);
                bool[] cardsUseDuplicate = this.LoadState <bool[]>(CardsUseDuplicateKey);
                bool[] cardsIsMatched    = this.LoadState <bool[]>(CardsIsMatchedKey);
                bool[] cardsIsSelected   = this.LoadState <bool[]>(CardsIsSelectedKey);

                // load stream from isolated storage
                MainViewModel.Instance.LoadDeckFromIsolatedStorage();

                bool isMatchingGame = MainViewModel.Instance.GameMode == GameModes.MatchingGame;
                game = new MatchingGameViewModel(MainViewModel.Instance.Decks.SelectedDeck, isMatchingGame, cardsOrder, cardsUseDuplicate, cardsIsMatched, cardsIsSelected);
            }
            else
            {
                bool isMatchingGame = MainViewModel.Instance.GameMode == GameModes.MatchingGame;
                game = new MatchingGameViewModel(MainViewModel.Instance.Decks.SelectedDeck, isMatchingGame);
            }

            MainViewModel.Instance.CurrentView = game;
            DataContext = MainViewModel.Instance.CurrentView;
        }
        void MatchingGame_Loaded(object sender, RoutedEventArgs e)
        {
            MatchingGameViewModel game = this.DataContext as MatchingGameViewModel;

            game.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(game_PropertyChanged);

            if (game.SelectedDeck.Count <= 8)
            {
                GameViewbox.MaxHeight = 500.0;
            }
        }
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.Uri.ToString() == "app://external/")
            {
                this.SaveState(IsolatedStorageFileNameKey, MainViewModel.Instance.IsolatedStorageFileName);
                this.SaveState(GameModeKey, MainViewModel.Instance.GameMode);

                // save game specific state
                MatchingGameViewModel matchingGame = MainViewModel.Instance.CurrentView as MatchingGameViewModel;

                int[]  cardsOrder;
                bool[] cardsUseDuplicate;
                bool[] cardsIsMatched;
                bool[] cardsIsSelected;
                matchingGame.GetGameState(out cardsOrder, out cardsUseDuplicate, out cardsIsMatched, out cardsIsSelected);

                this.SaveState(CardsOrderKey, cardsOrder);
                this.SaveState(CardsUseDuplicateKey, cardsUseDuplicate);
                this.SaveState(CardsIsMatchedKey, cardsIsMatched);
                this.SaveState(CardsIsSelectedKey, cardsIsSelected);
            }
        }
        private void AppbarButtonReset_Click(object sender, EventArgs e)
        {
            MatchingGameViewModel matchingGame = this.DataContext as MatchingGameViewModel;

            matchingGame.ResetCards.Execute(null);
        }
Example #6
0
        public CardDeck()
        {
            _cardPairs = new ObservableCollection<CardPair>();

            #if !SILVERLIGHT
            CreateNewCardPair = new DelegateCommand(() =>
            {
                CardPair cp = new CardPair() { IsInEdit = true , Card1 = new Card() , Card2 = new Card() ,ParentDeck = this ,IsSelected = true};
                cp.Initialize();
                _cardPairs.Add(cp);
                SelectedCardPair = cp;
                IsDirty = true;
            });

            EditDeck = new DelegateCommand(() =>
            {
                MainViewModel.Instance.CurrentView = this;
                Taskbar.AddEntryToJumpList(ZipPath, Title);
            });

            CancelCommand = new DelegateCommand(CancelEdit);

            DeleteDeck = new DelegateCommand(DeleteTheDeck);

            SaveDeck = new DelegateCommand(() =>
            {
                SaveTheDeck();
            });

            ShareDeck = new DelegateCommand(() =>
            {
                if (ShareClicked != null)
                {
                    ShareClicked(this, EventArgs.Empty);
                }
            });
            #endif
            ShowHelp = new DelegateCommand(() =>
            {
                MessageBox.Show((string)Application.Current.Resources["Resource_MessageBox_ShowHelp"]);
            });

            LearningGame = new DelegateCommand(() =>
            {
            #if !WINDOWS_PHONE
                LearningGameViewModel game = new LearningGameViewModel(this);
                MainViewModel.Instance.CurrentView = game;
            #else
                MainViewModel.Instance.GameMode = GameModes.LearningGame;
            #endif

            #if !SILVERLIGHT
                Taskbar.AddEntryToJumpList(ZipPath, Title);
            #endif
                this.IsSelected = false;
            }, () => { return Count > 0; });

            MatchingGame = new DelegateCommand(() =>
            {
            #if !WINDOWS_PHONE
                MatchingGameViewModel game = new MatchingGameViewModel(this, true);
                MainViewModel.Instance.CurrentView = game;
            #else
                MainViewModel.Instance.GameMode = GameModes.MatchingGame;
            #endif
            #if !SILVERLIGHT
                Taskbar.AddEntryToJumpList(ZipPath, Title);
            #endif
                this.IsSelected = false;
            }, () => { return Count >= 6; });

            MemoryGame = new DelegateCommand(() =>
            {
            #if !WINDOWS_PHONE
                MatchingGameViewModel game = new MatchingGameViewModel(this ,false);
                MainViewModel.Instance.CurrentView = game;
            #else
                MainViewModel.Instance.GameMode = GameModes.MemoryGame;
            #endif

            #if !SILVERLIGHT
                Taskbar.AddEntryToJumpList(ZipPath, Title);
            #endif
                this.IsSelected = false;
            }, () => { return Count >= 6; });
        }