private void ShuffleButton_Click(object sender, RoutedEventArgs e) { // Cards need to be shuffled randomly Random random = new Random(); for (int i = 0; i < 1000; i++) { // Pick two random cards int randomcard1 = random.Next(52); int randomcard2 = random.Next(52); // shuffle them string temp = cards[randomcard1]; cards[randomcard1] = cards[randomcard2]; cards[randomcard2] = temp; } // Print out cards into the the text block to the side ShuffledCards.Document.Blocks.Clear(); for (int i = 0; i < cards.Length; i++) { ShuffledCards.AppendText(cards[i] + "\r"); } // 5 cards need to be displayed on screen Card1Image.Source = new BitmapImage(new Uri("Cards/" + cards[0] + ".gif", UriKind.Relative)); Card2Image.Source = new BitmapImage(new Uri("Cards/" + cards[1] + ".gif", UriKind.Relative)); Card3Image.Source = new BitmapImage(new Uri("Cards/" + cards[2] + ".gif", UriKind.Relative)); Card4Image.Source = new BitmapImage(new Uri("Cards/" + cards[3] + ".gif", UriKind.Relative)); Card5Image.Source = new BitmapImage(new Uri("Cards/" + cards[4] + ".gif", UriKind.Relative)); }
/// <summary> /// Deals the default deck of cards into number of players /// </summary> /// <param name="NumberOfPlayers"></param> /// <returns>a dictionary with player and the cards it holds</returns> public override Dictionary <int, List <Card> > DealCards(int NumberOfPlayers) { Dictionary <int, List <Card> > DealtCards = new Dictionary <int, List <Card> >(); for (int i = 0; i < ShuffledCards.Count(); i++) { int PlayerNumber = i % NumberOfPlayers; if (!DealtCards.ContainsKey(PlayerNumber)) { DealtCards.Add((PlayerNumber), new List <Card>()); } DealtCards[PlayerNumber].Add(ShuffledCards[i]); } return(DealtCards); }