public void AddCardToHand(PlayingCard cardDealt) { if (this.cards.Count >= HandSize) { throw new ArgumentException("Too many cards"); } this.cards.Add(cardDealt); }
public void AddCardToHand(PlayingCard cardDealt) { if (this.playingCardCount >= HandSize) { throw new ArgumentException("Too many cards"); } this.cards[this.playingCardCount] = cardDealt; this.playingCardCount++; }
public Pack() { cardPack = new PlayingCard[NumSuits, CardsPerSuit]; for (Suit suit = Suit.Clubs; suit <= Suit.Spades; suit++) { for (Value value = Value.Two; value <= Value.Ace; value++) { cardPack[(int)suit, (int)value] = new PlayingCard(suit, value); } } }
//private int playingCardCount = 0; public void AddCardToHand(PlayingCard cardDealt) { //if (this.playingCardCount >= HandSize) if (this.cards.Count >= HandSize) { throw new ArgumentException("Too many cards"); } //this.cards[this.playingCardCount] = cardDealt; //this.playingCardCount++; this.cards.Add(cardDealt); }
public PlayingCard Deal() { if (cards.Count == 0) { throw new InvalidOperationException("can't deal from empty pack"); } PlayingCard dealt = (PlayingCard)cards[0]; cards.RemoveAt(0); return(dealt); }
public void AddCardToHand(PlayingCard cardDealt) /*The purpose of this method is to add the playing card specifi ed as the parameter to the hand. */ { if (this.playingCardCount >= HandSize) /*Used by your code to keep track of how many cards the hand currently contains as it is being populated.*/ { throw new ArgumentException("Too many cards"); /*This code fi rst checks to ensure that the hand is not already full. If the hand is full, it throws an * ArgumentException exception (this should never occur, but it is good practice to be safe). Otherwise, the * card is added to the cards array at the index specifi ed by the playingCardCount variable, and this variable * is then incremented. */ } this.cards[this.playingCardCount] = cardDealt; this.playingCardCount++; }
public PlayingCard DealCardFromPack() { Suit suit = (Suit)randomCardSelector.Next(NumSuits); while (this.IsSuitEmpty(suit)) { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); while (this.IsCardAlreadyDealt)(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } PlayingCard card = this.cardPack[(int)suit, (int)value]; this.cardPack[(int)suit, (int)value] = null; return card; }
public PlayingCard DealCardFromPack() { Suit suit = (Suit)randomCardSelector.Next(NumSuits); // creates suit variable of enum type Suit. Casts Suit while (IsSuitEmpty(suit)) // checks if suit is empty yet. { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); while (IsCardAlreadyDealt(suit, value)) // this and next line, if card is already dealt, gives another random card. { value = (Value)randomCardSelector.Next(CardsPerSuit); } PlayingCard card = cardPack[(int)suit, (int)value]; // creates or "pulls" a new card from the deck. cardPack[(int)suit, (int)value] = null; // removes the card from the deck. return(card); }
public PlayingCard DealCardFromPack() { Suit suit = (Suit)randomCardSelector.Next(NumSuits); while (this.IsSuitEmpty(suit)) { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); while (this.IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } List <PlayingCard> cardsInSuit = this.cardPack[suit]; PlayingCard card = cardsInSuit.Find(c => c.CardValue == value); cardsInSuit.Remove(card); return(card); }
public PlayingCard DealCardFromPack() { Suit suit = (Suit)randomCardSelector.Next(NumSuits); while (this.IsSuitEmpty(suit)) { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); while (this.IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } SortedList cardsInSuit = (SortedList)cardPack[suit]; PlayingCard card = (PlayingCard)cardsInSuit[value]; cardsInSuit.Remove(value); return(card); }
public PlayingCard DealCardFromPack() { // TODO: pick a random card, remove it from the pack, and return it Suit suit = (Suit)randomCardSelector.Next(NumSuits); while (this.IsSuitEmpty(suit)) { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); while (this.IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } PlayingCard card = this.cardPack[(int)suit, (int)value]; this.cardPack[(int)suit, (int)value] = null; return(card); }
public PlayingCard DealCardFromPack() //Instance method { Suit suit = (Suit)randomCardSelector.Next(NumSuits); // while (this.IsSuitEmpty(suit)) //this while loop selects a new suit when we run out of one type of loop { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); //symbolic instance "CardsPerSuit" while (this.IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } PlayingCard card = this.cardPack[(int)suit, (int)value]; //This is one way we deal a card. this.cardPack[(int)suit, (int)value] = null; //How you mark a card that has been dealt. Null is inserted into the cards spot. return(card); }
public PlayingCard DealCardFromPack() { Suit suit = (Suit)randomCardSelector.Next(NumSuits); while (IsSuitEmpty(suit)) { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); while (IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } Dictionary <Value, PlayingCard> cardsInSuit = _cardPack[suit]; PlayingCard card = cardsInSuit[value]; cardsInSuit.Remove(value); return(card); }
public PlayingCard DealCardFromPack() { Suit suit; do { suit = (Suit)_random.Next(NumSuit); } while (IsSuitEmpty(suit)); Value value; do { value = (Value)_random.Next(CardsPerSuit); } while (IsCardAlreadyDealt(suit, value)); PlayingCard card = _cardPack[(int)suit, (int)value]; _cardPack[(int)suit, (int)value] = null; return(card); }
public PlayingCard DealCardFromPack() { // pick a suit at random. Take a random int from 0 to max - 1 and cast to an enum Suit suit; Value value; do { suit = (Suit)randomCardSelector.Next(NumSuits); }while (this.IsSuitEmpty(suit)); do { value = (Value)randomCardSelector.Next(CardsPerSuit); }while (this.IsCardAlreadyDealt(suit, value)); PlayingCard card = this.cardPack[(int)suit, (int)value]; this.cardPack[(int)suit, (int)value] = null; return(card); }
public PlayingCard DealCardFromPack() { Suit suit; do { suit = (Suit)_random.Next(NumSuit); } while (IsSuitEmpty(suit)); Value value; do { value = (Value)_random.Next(CardsPerSuit); } while (IsCardAlreadyDealt(suit, value)); List <PlayingCard> cardsInSuit = _cardPack[suit]; PlayingCard card = cardsInSuit.Find(c => c.CardValue == value); cardsInSuit.Remove(card); return(card); }
public PlayingCard DealCardFromPack() { //// to do - pick a random card, remove it from the pack, and return it //throw new NotImplementedException("DealCardFromPack - TBD"); Suit suit = (Suit)randomCardSelector.Next(NumSuits); while (this.IsSuitEmpty(suit)) { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); while (this.IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } PlayingCard card = this.cardPack[(int)suit, (int)value]; this.cardPack[(int)suit, (int)value] = null; return(card); }
public PlayingCard DealCardFromPack() /*Picks a random card from the pack, remove the card from the pack to prevent it from being selected * again, and then pass it back as the return value from the method. This statement uses the Next method * of the randomCardSelector random number generator object to return a random number corresponding to a suit. * The parameter to the Next method specifi es the exclusive upper bound of the range to use; the value * selected is between 0 and this value minus 1. Note that the value returned is an int, so it has to be * cast before you can assign it a Suit variable. There is always the possibility that no cards of the selected * suit are left. You need to handle this situation and pick another suit if necessary.*/ { Suit suit = (Suit)randomCardSelector.Next(NumSuits); while (this.IsSuitEmpty(suit)) /*This loop calls the IsSuitEmpty method to determine whether any cards of the specifi ed suit are * left in the pack (you will implement the logic for this method shortly). If not, it picks another suit at * random (it might actually pick the same suit again) and checks again. The loop repeats the process until it * finds a suit with at least one card left. */ { suit = (Suit)randomCardSelector.Next(NumSuits); } /*You have now selected at random a suit with at least one card left. The next task is to pick a card * at random in this suit. You can use the random number generator to select a card value, but as before, there * is no guarantee that the card with the chosen value has not already been dealt. However, you can use the same * idiom as before: call the IsCardAlreadyDealt method (which you will examine and complete later) to determine * whether the card has already been dealt, and if so, pick another card at random and try again, repeating * the process until a card is found. */ Value value = (Value)randomCardSelector.Next(CardsPerSuit); while (this.IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } PlayingCard card = this.cardPack[(int)suit, (int)value]; /*You have now selected a random playing card that has not been dealt previously. This will return this card * and set the corresponding element in the cardPack array to null: */ this.cardPack[(int)suit, (int)value] = null; return(card); }
private void dealClick(object sender, RoutedEventArgs e) { try { pack = new Pack(); for (int handNum = 0; handNum < NumHands; handNum++) { for (int numCards = 0; numCards < Hand.HandSize; numCards++) { PlayingCard cardDealt = pack.DealCardFromPack(); hands[handNum].AddCardToHand(cardDealt); } north.Text = hands[0].ToString(); south.Text = hands[1].ToString(); east.Text = hands[2].ToString(); west.Text = hands[3].ToString(); } } catch (Exception ex) { MessageDialog msg = new MessageDialog(ex.Message, "Error"); msg.ShowAsync(); } }
public PlayingCard DealCardFromPack() { Suit suit = (Suit)randomCardSelector.Next(NumSuits); // If suit is empty, pick another suit. while (IsSuitEmpty(suit)) { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); // If card already dealt, pick another card. while (IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } PlayingCard card = cardPack[(int)suit, (int)value]; // When we deal a card, set the place to null. cardPack[(int)suit, (int)value] = null; return(card); }
public PlayingCard DealCardFromPack() { Suit suit = (Suit)randomCardSelector.Next(NumSuits); //if suit is empty pick another suit (meaning of line 25 & 26) while (IsSuitEmpty(suit)) { suit = (Suit)randomCardSelector.Next(NumSuits); } Value value = (Value)randomCardSelector.Next(CardsPerSuit); //if card already dealt pick another card while (IsCardAlreadyDealt(suit, value)) { value = (Value)randomCardSelector.Next(CardsPerSuit); } PlayingCard card = this.cardPack[(int)suit, (int)value]; //when we deal a card, set the place to null cardPack[(int)suit, (int)value] = null; return(card); }
public void Accept(PlayingCard card) { cards.Add(card); }
public void AddCardToHand(PlayingCard cardDealt) { // to do - add the specified card to the hand }
public void Accept(PlayingCard dealt) { cards.Add(dealt); }
public void AddCardToHand(PlayingCard cardDealt) { // TODO: add the specified card to the hand }