コード例 #1
0
        public MatchingGameViewModel(CardDeck selectedDeck, bool isMatchingGame, int[] cardsOrder, bool[] cardsUseDuplicate, bool[] cardsIsMatched, bool[] cardsIsSelected)
            : this(selectedDeck, isMatchingGame, false)
        {
            // add card pair according to original cards order
            for (int i = 0; i < cardsOrder.Length; ++i)
            {
                CardPair cardPair = selectedDeck.Collection[cardsOrder[i]];
                if (cardsUseDuplicate[i])
                {
                    cardPair = cardPair.Duplicate();
                }

                cardPair.IsMatchingGame = isMatchingGame;
                cardPair.IsMatched      = cardsIsMatched[i];
                cardPair.IsLoaded       = true;
                //cardPair.IsSelected = cardsIsSelected[i];
                cardPair.SelectionChanged += new EventHandler(card_SelectionChanged);

                CardPairs.Add(cardPair);
            }

            SetRowsAndColumns();

            Matches = cardsIsMatched.Count(isMatched => isMatched) / 2;
        }
コード例 #2
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; });
        }
コード例 #3
0
        private void SlowCollectionAdd(List <CardPair> cardpairs)
        {
            List <CardPair> temp = new List <CardPair>();


            foreach (CardPair cpair in cardpairs)
            {
                cpair.IsSelected = false;

                CardPair dup = cpair.Duplicate();

                if (IsMatchingGame)
                {
                    dup.IsMatchingGame   = true;
                    cpair.IsMatchingGame = true;
                }
                else
                {
                    dup.IsMatchingGame   = false;
                    cpair.IsMatchingGame = false;
                }

                cpair.IsLoaded  = false;
                dup.IsLoaded    = false;
                cpair.IsMatched = false;
                dup.IsMatched   = false;

                temp.Add(cpair);
                temp.Add(dup);
            }

            cardpairs = Randomize <CardPair>(temp);
            List <int> indexCollection = new List <int>(); int i = 0;

            foreach (CardPair cp in cardpairs)
            {
                CardPairs.Add(cp);
                cp.SelectionChanged += new EventHandler(card_SelectionChanged);
                indexCollection.Add(i++);
            }

            //Randomize the IndexCollection
            indexCollection = Randomize <int>(indexCollection);

            DispatcherTimer _timer = new DispatcherTimer();

            _timer.Interval = TimeSpan.FromMilliseconds(MainViewModel.CardLoadingDelay); //Just waiting to Sync any animation in the View

            _timer.Tick += new EventHandler(delegate(object s, EventArgs ev)
            {
                int index = indexCollection.Count - 1;

                if (index == -1)
                {
                    _timer.Stop();
                }
                else
                {
                    CardPairs[indexCollection[index]].IsLoaded = true;
                    indexCollection.RemoveAt(index);
                }
            });

            _timer.Start();
        }
コード例 #4
0
        void card_SelectionChanged(object sender, EventArgs e)
        {
            CardPair pair = sender as CardPair;

            if (pair == match)
            {
                pair.IsSelected = false;
                match           = null;
            }

            if (pair.IsSelected)
            {
                if (match != null)
                {
                    //Check for proper Match
                    if (pair.Card1 == match.Card2) //Match success
                    {
                        DispatcherTimer _timer = new DispatcherTimer();
                        double          delay  = IsMatchingGame ? MainViewModel.CardMatchedDelay_MatchingGame : MainViewModel.CardMatchedDelay_MemoryGame;
                        _timer.Interval = TimeSpan.FromMilliseconds(delay); //Just waiting to Sync any animation in the View

                        List <CardPair> pairs = new List <CardPair>()
                        {
                            match, pair
                        };
                        _timer.Tick += new EventHandler(delegate(object s, EventArgs ev)
                        {
                            pairs[0].IsMatched = true;
                            pairs[1].IsMatched = true;
                            Matches++;
                            _timer.Stop();
                        });

                        _timer.Start();
                    }
                    else //Not matched
                    {
                        //This Timer is to Show the wrong cards little more time in the view
                        DispatcherTimer _timer = new DispatcherTimer();

                        double delay = IsMatchingGame ? MainViewModel.CardMatchFailedDelay_MatchingGame : MainViewModel.CardMatchFailedDelay_MemoryGame;

                        _timer.Interval = TimeSpan.FromMilliseconds(delay); //Just waiting to Sync any animation in the View

                        List <CardPair> pairs = new List <CardPair>()
                        {
                            match, pair
                        };
                        _timer.Tick += new EventHandler(delegate(object s, EventArgs ev)
                        {
                            pairs[0].IsSelected = false;
                            pairs[1].IsSelected = false;

                            _timer.Stop();
                        });

                        _timer.Start();
                    }

                    match = null;
                }
                else //First card opened
                {
                    match = pair;
                }
            }
        }
コード例 #5
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); });
        }