Exemple #1
0
        //Activates an event.
        //Activates when an upside down card is clicked
        public async void OnCardClick(object sender, RoutedEventArgs e)
        {
            if (IsLocked)
            {
                return;
            }
            Card card = GridData.AllCards.First(a => a.Element == e.Source as Button);

            if (card.IsRevealed)
            {
                return;
            }
            card.Reveal();

            // First card
            if (RevealedCard == null)
            {
                RevealedCard = card;
            }

            // No match
            else if (card.Type != RevealedCard.Type)
            {
                IsLocked = true;
                await Task.Delay(1000);

                card.Hide();
                RevealedCard.Hide();
                GridData.SetCardsEnabled(false);
                RevealedCard       = null;
                CurrentPlayerIndex = CurrentPlayerIndex == 0 ? 1 : 0;
                GridData.SetCardsEnabled(true);
                IsLocked = false;
                //Turns bool Displayplayer ON/OFF. This updates the player turn in the top left of the screen.
                DisplayPlayer = !DisplayPlayer;
                if (DisplayPlayer)
                {
                    Labelnameplayer.Content = Players[0].Name + " is aan zet";
                }
                else
                {
                    Labelnameplayer.Content = Players[1].Name + " is aan zet";
                }
            }

            // Match
            else
            {
                IsLocked = true;
                CurrentPlayer.ApplyScore(card.Type);
                await Task.Delay(500);

                card.Matched();
                RevealedCard.Matched();
                UpdatePlayerScore(CurrentPlayer);
                RevealedCard = null;
                IsLocked     = false;
                //Updates the player turn in the top left of the screen again.
                //This time it shows that they get an extra turn.
                if (DisplayPlayer)
                {
                    Labelnameplayer.Content = Players[0].Name + " heeft een extra zet";
                }
                else
                {
                    Labelnameplayer.Content = Players[1].Name + " heeft een extra zet";
                }
            }
        }