private void GiveUp(object sender, RoutedEventArgs e) { setTurn(getTurn()); winner winnerWindow = new winner(_navigator, getTurn()); winnerWindow.ShowDialog(); }
/// <summary> /// Een event handler die af gaat als iemand op een kaart klikt, daar na slaan we de eerste op, /// en gaan we kijken of de tweede keuze overeen komt met de eerste. /// Zowel, worden er punten toegevoegt aan de speler die aan de beurd is. /// Zo niet, dan draaien we de kaarten weer om en is de volgende aan de beurt. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void CardClick(object sender, MouseButtonEventArgs e) { //need to refactor this CardClick part! Image card = (Image)sender; Card front = (Card)card.Tag; if (!front.isSelected()) { front.select(); card.Source = front.flipCard(); cardsTurned++; } if (cardsTurned == 1) { oldcard = card; turnedCard = front; } if (cardsTurned == 2) { string player = sidebar.getTurn(); if (front.getNumber() == turnedCard.getNumber() && front.isSelected() && turnedCard.isSelected()) { sidebar.AddPoint(player); countedCards += 2; if (countedCards == (rows * columns)) { _highscore = new Highscore(); _highscore.addScore(new PlayerScore(player, sidebar.getPlayerScore(player))); winner winnerWindow = new winner(_navigator, player); winnerWindow.ShowDialog(); } } else { await Task.Run(() => { Thread.Sleep(500); }); turnedCard.deselect(); front.deselect(); oldcard.Source = turnedCard.flipCard(); card.Source = front.flipCard(); } sidebar.setTurn(player); cardsTurned = 0; } }