Ejemplo n.º 1
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="grid">Het grid waar de kaarten in komen</param>
        /// <param name="cols"> hoeveel kolommen het grid krijgt</param>
        /// <param name="rows"> hoeveel rijen het grid krijgt</param>
        public SinglePlayerGame(Grid grid, int cols, int rows, bool diff)
        {
            theme = app.currentTheme;

            _diff = diff;

            if (theme != string.Empty)
            {
                _grid = grid;
                _cols = cols;
                _rows = rows;

                SetGameGrid(_cols, _rows);
                GetImagesList();
                AddImages();
                SetBackground();
                Scores.SetScore((string)player1score.ToString(), 1);
            }
            else
            {
                ((WindowViewModel)((MainWindow)Application.Current.MainWindow).DataContext).CurrentPage = ApplicatiePage.Newgame;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// houdt de klik actie bij van de user wanneer die op een plaatje klikt.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CardClick(object sender, MouseButtonEventArgs e)
        {
            if (allowclick == true)
            {
                Sound1.Open((new Uri("Assets/Themes/Warcraft/Audio/click.wav", UriKind.Relative)));
                Sound1.Play();

                Image       card  = (Image)sender;
                ImageSource front = (ImageSource)card.Tag;
                card.Source = front;
                List <ImageSource> images = GetImagesList();

                if (firstGuess == null)
                {
                    firstGuess = card;
                    Console.WriteLine("First guess is set");
                    firstGuess.MouseDown -= new MouseButtonEventHandler(CardClick);
                    return;
                }
                if (card.Source.ToString() == firstGuess.Source.ToString() && card != firstGuess)
                {
                    //GOED GEKLIKT
                    Sound2.Volume = 0.3;
                    Sound2.Open((new Uri("Assets/Themes/Warcraft/Audio/matched.wav", UriKind.Relative)));
                    Sound2.Play();
                    correctcount         += 2;
                    firstGuess.Opacity    = 0.5;
                    card.Opacity          = 0.5;
                    firstGuess.MouseDown -= new MouseButtonEventHandler(CardClick);
                    card.MouseDown       -= new MouseButtonEventHandler(CardClick);
                    player1score++;
                    score1.Content = player1score;
                    Scores.SetScore((string)score1.Content.ToString(), 1);
                    allowclick = true;
                }
                else
                {
                    allowclick = false;
                    await Task.Delay(1000);

                    firstGuess.Source     = new BitmapImage(new Uri("Assets/Themes/Warcraft/Back/question.png", UriKind.Relative));
                    card.Source           = new BitmapImage(new Uri("Assets/Themes/Warcraft/Back/question.png", UriKind.Relative));
                    firstGuess.MouseDown += new MouseButtonEventHandler(CardClick);
                    allowclick            = true;
                }

                if (correctcount == images.Count)
                {
                    Timer.StopTimer();
                    MessageBox.Show("Gewonnen!");

                    dialogResult = MessageBox.Show("Wil je het spel herstarten met dezelfde instellingen?", "Vraagje", MessageBoxButton.YesNo);

                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        ResetGameGrid();
                        SetGameGrid(_cols, _rows);
                        GetImagesList();
                        AddImages();
                    }
                    else if (dialogResult == MessageBoxResult.No)
                    {
                        Grid parentGrid = (Grid)VisualTreeHelper.GetParent(_grid);
                        parentGrid.Visibility = Visibility.Collapsed;
                        Sound3.Stop();
                        ResetGameGrid();
                        ((WindowViewModel)((MainWindow)Application.Current.MainWindow).DataContext).CurrentPage = ApplicatiePage.Hoofdmenu;
                    }
                }
                firstGuess = null;
            }
        }