示例#1
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); });
        }
示例#2
0
        /// <summary>
        /// Saving to Disk , this fucntion needs to be Async and have a Status Datatrigger for View animation.
        /// </summary>
        private void SaveTheDeck()
        {
            IsBusy = true;

            try
            {
                GenerateRootPath();

                CreatedTime = DateTime.Now;
                CreatedBy   = Environment.UserName;

                List <CardPair> _pairs = Collection.ToList();

                foreach (CardPair pair in _pairs)
                {
                    if (pair.IsDeleted)
                    {
                        Collection.Remove(pair);
                        continue;
                    }
                }

                foreach (CardPair pair in Collection)
                {
                    CopyResources(pair.Card1);
                    CopyResources(pair.Card2);
                }

                string path = RootPath + "\\deck.xml";


                File.Delete(path);

                FileStream fs = File.Create(path);

                XmlSerializer SerializerObj = new XmlSerializer(typeof(CardDeck));
                SerializerObj.Serialize(fs, this);

                fs.Close();

                if (!MainViewModel.Instance.Decks.Collection.Contains(this))
                {
                    MainViewModel.Instance.Decks.Collection.Add(this);
                }

                Taskbar.AddEntryToJumpList(ZipPath, Title);

                DeckPackagingHelper.PackageDeck(RootPath, Title);
            }
            catch (Exception e)
            {
                Utils.LogException(MethodBase.GetCurrentMethod(), e);

                //There are some problem Saving the Deck..
                IsBusy = false;
            }

            IsBusy  = false;
            IsDirty = false;

            Count = _cardPairs.Count;
        }