Пример #1
0
        private async void FlipCard(CardViewModel card)
        {
            card.Visibility = true;

            int nrflipped = Cards.Count(c => c.Visibility && !c.Hidden);

            if (nrflipped == 2)
            {
                var visibleCards    = Cards.Where(c => c.Visibility && !c.Hidden).ToList();
                int nrDistinctCards = visibleCards.Select(c => c.ImageUp).Distinct().Count();
                await Task.Delay(200);

                if (nrDistinctCards == 1)
                {
                    foreach (var c in visibleCards)
                    {
                        c.Hidden = true;
                    }
                    Score += 10;
                }
                else
                {
                    foreach (var c in visibleCards)
                    {
                        c.Visibility = false;
                    }
                }
            }

            int nrhidden = Cards.Count(c => c.Hidden);

            if (nrhidden == GridSize * GridSize && CurrentTime > 0)
            {
                DispatcherTimer.Stop();
                MessageBox.Show("You Won!", "Message", MessageBoxButton.OK,
                                MessageBoxImage.Exclamation);

                GameRecord gameRecord = new GameRecord
                {
                    Date   = DateTime.Now,
                    Game   = "PairGame",
                    Player = App.CurrentApp.MainViewModel.LoginViewModel.Player,
                    Score  = Score
                };
                _gameRecordManager.Add(gameRecord);
                App.CurrentApp.MainViewModel.Refresh();
                CurrentTime   = 0;
                Score         = 0;
                IsEnabledSave = false;
            }
            //else
            //if (nrhidden != GridSize * GridSize && CurrentTime == 0)
            //{
            //    DispatcherTimer.Stop();
            //    MessageBox.Show("You Lost!", "Loser", MessageBoxButton.OK,
            //                           MessageBoxImage.Exclamation);
            //    CurrentTime = 0;
            //    Score = 0;
            //    IsEnabledSave = false;
            //}
        }