/// <summary> /// This method sorts the clone of the deck based on the Face value rather than the integer value of the cards. /// This means that the decks clones order (which always starts as something like 1..2...5...14..33..51) will altered to /// Go from least valuable card (2) to most valuable card (A). This is usefull as if one wants to perform multiple /// operations based on variable sorted hands it odoesn't make sense to have to sort each hand individually. /// In short, this is a method for effiency of operation. /// </summary> /// <returns>Returns an integer valued list</returns> public static List <int> createSortedCloneOfDeck(List <string> deckContent) { var clone = new List <int>(); //populate new list with the converted string cards foreach (var stringCard in deckContent) { clone.Add(CardUtilities.convertFromStringCard(stringCard)); } clone.Sort(CardUtilities.NumberCardComparer); return(clone); }
private void initialiseHandLabels() { handLabels = new List <Label>() { lbl_Hand1, lbl_Hand2, lbl_Hand3, lbl_Hand4, lbl_Hand5 }; foreach (Label lbl in handLabels) { lbl.MouseUp += new MouseButtonEventHandler((object sender, MouseButtonEventArgs e) => { if (e.ChangedButton == MouseButton.Left || e.ChangedButton == MouseButton.Right) { int x = CardUtilities.convertFromStringCard(((Label)sender).Content.ToString()); if (handCards.Contains(x)) { Label deckLabel = getLabel(((Label)sender).Content.ToString()); if (deckLabel == null) { return; } // if (deckLabel.Content.ToString()[1] == '♥' || deckLabel.Content.ToString()[1] == '♦') // deckLabel.Foreground = new SolidColorBrush(Colors.Red); // else // deckLabel.Foreground = new SolidColorBrush(Colors.Black); handCards.Remove(x); handCards.Add(-1); //deckContent.Add(((Label)sender).Content.ToString()); updateHandDisplay(); setForHandState(false); } return; } }); } }
/// <summary> /// Adds a new card to the hand, sorts the hand, and updates the display to reflects the hands new state /// </summary> /// <param name="card"></param> private void passCardToHand(string card) { if (handCards == null) { handCards = new List <int> { -1, -1, -1, -1, -1 } } ; //fill it will illegal card values for (int i = 0; i < handCards.Count; i++) { if (handCards[i] == -1) { handCards[i] = CardUtilities.convertFromStringCard(card); break; } } handCards.Sort(CardUtilities.NumberCardComparer); updateHandDisplay(); }
private void cardLabelClicked(object sender, MouseButtonEventArgs e) { //This code will be executed when the new label is clicked - we want it to remove a card from the deck upon left cliking, right click will replace removed ones if (e.ChangedButton == MouseButton.Left) { //check if there are any still to be removed if (deckContent.Contains(((Label)sender).Content.ToString())) { deckContent.Remove(((Label)sender).Content.ToString()); //and remove one if there is passCardToHand(((Label)sender).Content.ToString()); } //check if there none left and grey out if there are if (!deckContent.Contains(((Label)sender).Content.ToString())) { ((Label)sender).Foreground = new SolidColorBrush(Colors.Gray); } if (handCards[4] != -1) { lbl_HandType.Content = CardUtilities.getHandValueName(CardUtilities.getSortedHandValue(handCards)); setForHandState(true); } else { setForHandState(false); } return; } //Put the card back in the deck if it was missing if (e.ChangedButton == MouseButton.Right) { //change the colour back to normal if (((Label)sender).Content.ToString()[1] == '♥' || ((Label)sender).Content.ToString()[1] == '♦') { ((Label)sender).Foreground = new SolidColorBrush(Colors.Red); } else { ((Label)sender).Foreground = new SolidColorBrush(Colors.Black); } //Check if the hand is holding a given card, and remove it from the hand if it is int x = CardUtilities.convertFromStringCard(((Label)sender).Content.ToString()); if (handCards.Contains(x)) { handCards.Remove(x); handCards.Add(-1); deckContent.Add(((Label)sender).Content.ToString()); updateHandDisplay(); } //if the card is missing from the deck replace it if (!deckContent.Contains(((Label)sender).Content.ToString())) { deckContent.Add(((Label)sender).Content.ToString()); } btn_Calculate.IsEnabled = false; btn_SpecificMask.IsEnabled = false; lbl_HandType.Content = ""; } }