public GameViewModel(CardDeck SelectedDeck) { _selectedDeck = SelectedDeck; Quit = new DelegateCommand(() => { #if !SILVERLIGHT Application.Current.Shutdown(); #endif }); Cancel = new DelegateCommand(() => { #if !WINDOWS_PHONE MainViewModel.Instance.CurrentView = MainViewModel.Instance.Decks; #else Microsoft.Phone.Controls.PhoneApplicationFrame frame = Application.Current.RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame; frame.GoBack(); #endif #if !SILVERLIGHT Taskbar.UpdateTaskBarStatus(0, SelectedDeck.Count / 2); #endif }); HelpCommand = new DelegateCommand(() => { #if !SILVERLIGHT MessageBox.Show((string)Application.Current.FindResource("Resource_MessageBox_ShowHelp")); #endif }); }
private void OnGameFinished() { IsFinished = true; RaisePropertyChanged(@string.of(() => IsFinished)); IsFinished = false; #if !SILVERLIGHT Taskbar.UpdateTaskBarStatus(1, 1); #endif }
private void ShuffleCards() { SetRowsAndColumns(); #if !SILVERLIGHT Taskbar.UpdateTaskBarStatus(0, SelectedDeck.Count / 2); #endif List <CardPair> cardpairs = Randomize <CardPair>(SelectedDeck.Collection.ToList()).Take(_countTotal / 2).ToList(); foreach (CardPair card in CardPairs) { card.SelectionChanged -= new EventHandler(card_SelectionChanged); } CardPairs.Clear(); Matches = 0; SlowCollectionAdd(cardpairs); }
private void DeleteTheDeck() { TaskDialog dlg = new TaskDialog() { Caption = (string)Application.Current.FindResource("Resource_MessageBox_DeleteDeckCaption") + " " + Title, Text = (string)Application.Current.FindResource("Resource_MessageBox_DeleteDeckText"), Icon = TaskDialogStandardIcon.Warning, Cancelable = true, StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No }; if (dlg.Show() == TaskDialogResult.Yes) { this.IsSelected = false; string deckGuid = this.DeckGUID; DispatcherTimer _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(MainViewModel.DeleteDelay); //Just waiting to Sync any animation in the View _timer.Tick += new EventHandler(delegate(object s, EventArgs ev) { if (MainViewModel.Instance.Decks.Collection.Contains(this)) { MainViewModel.Instance.Decks.Collection.Remove(this); } _timer.Stop(); }); _timer.Start(); Count = _cardPairs.Count; Directory.Delete(Path.GetDirectoryName(RootPath), true); Directory.Delete(Path.GetDirectoryName(ZipPath), true); Taskbar.RemoveEntryFromJumpList(ZipPath); } }
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); }); }
/// <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; }