Example #1
0
        private void checkCards(){

            if (firstCard != null && secondCard != null)
            {
                bool result = firstCard.myPhoto.id == secondCard.myPhoto.id;

                if (result)
                {
                    winMoves++;

                    Stream stream = TitleContainer.OpenStream("sounds/yes/"+RandomNumber(1,10)+".wav");
                    SoundEffect effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    effect.Play();

                    wonCards.Add(firstCard);
                    wonCards.Add(secondCard);
                    firstCard.canBeChanged = false;
                    secondCard.canBeChanged = false;

                    if (winMoves == 10)
                    {
                        gameTimer.Stop();
                       
                        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
                        App app = (App)Application.Current;

                        EyeemHighscore newHighscore = new EyeemHighscore();
                        newHighscore.albumName = app.selectedAlbum.name;
                        newHighscore.moves = moves;
                        
                        if (gametimeSeconds >= 10)
                        {
                            newHighscore.seconds = "" + gametimeSeconds;
                        }
                        else
                        {
                            newHighscore.seconds = "0" + gametimeSeconds;
                        }

                        if (gametimeMinutes >= 10)
                        {
                            newHighscore.minutes = "" + gametimeMinutes;
                        }
                        else
                        {
                            newHighscore.minutes = "0" + gametimeMinutes;
                        }
                        
                        app.highscoreList.Add(newHighscore);
                        
                        List<EyeemHighscore> SortedList = app.highscoreList.OrderBy(o => o.moves).ToList();
                        app.highscoreList = SortedList;

                        if (app.highscoreList.Capacity > 10)
                        {
                            app.highscoreList = app.highscoreList.GetRange(0, 9);
                        }

                        settings["highscore"] = app.highscoreList;
                        settings.Save();

                        var messagePrompt = new MessagePrompt
                        {
                            Title = "Congratulations",
                            Body = new TextBlock { Text = "You won! " },
                            IsAppBarVisible = true,
                            IsCancelVisible = false
                        };
                        messagePrompt.Completed += new EventHandler<PopUpEventArgs<string, PopUpResult>>(messagePrompt_Completed);
                        messagePrompt.Show();
                    }
                    else
                    {
                        gameTimer.Stop();

                        Popup showPhotoPopup;
                        showPhotoPopup = new Popup();
                        showPhotoPopup.Child = new PhotoPopup(firstCard.myPhoto);
                        showPhotoPopup.IsOpen = true;
                        showPhotoPopup.VerticalOffset = 10;
                        showPhotoPopup.HorizontalOffset = 0;
                        showPhotoPopup.Closed += (s1, e1) =>
                        {
                            gameTimer.Start();
                        };

                        /*var photoBox = new MessagePrompt
                        {
                            Title = "Great Move!",
                            Body = new Image { Stretch = Stretch.Uniform, Source = new BitmapImage(new Uri(firstCard.myPhoto.photoUrl)) },
                            IsAppBarVisible = true
                        };
                        photoBox.Completed += new EventHandler<PopUpEventArgs<string, PopUpResult>>(photoBox_Completed);
                        photoBox.Show();*/

                        firstCard = null;
                        secondCard = null;
                    }
                }
                else
                {
                    Stream stream = TitleContainer.OpenStream("sounds/no/"+RandomNumber(1,10)+".wav");
                    SoundEffect effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    effect.Play();

                    firstCard.FrontImage.Visibility = Visibility.Visible;
                    secondCard.FrontImage.Visibility = Visibility.Visible;
                    firstCard = null;
                    secondCard = null;
                }
            }
            
        }
Example #2
0
        private int compareMoves(EyeemHighscore first, EyeemHighscore second)
        {
            if (first == null)
            {
                return -1;
            }

            if (first.moves > second.moves)
                return 1;
            else
                return -1;
        }