public string DescribeBooks() { /* Return a long string that describes everyone's books by looking at the Books * dictionary: "Joe has a book of sixes. (line break) Ed has a book of Aces." */ string description = ""; foreach (Value value in books.Keys) { description += books[value].Name + " has a book of " + Card.Plural(value) + Environment.NewLine; } return(description); }
public string DescribeBooks() { // Return a long string that describes everyone's books by looking at the Books // dictionary: "Joe has a book of sixes. (line break) Ed has a book of Aces." string whoHasWhichBooks = ""; foreach (Values value in books.Keys) { whoHasWhichBooks += books[value].Name + " has a book of " + Card.Plural(value) + Environment.NewLine; } return(whoHasWhichBooks); }
public Deck DoYouHaveAny(Values value) { // This is where an opponent asks if I have any cards of a certain value // Use Deck.PullOutValues() to pull out the values. Add a line to the TextBox // that says, "Joe has 3 sixes"—use the new Card.Plural() static method Deck resultingDeck = cards.PullOutValues(value); string valueString; if (resultingDeck.Count != 1) { valueString = Card.Plural(value); } else { valueString = value.ToString(); } textBoxOnForm.Text += $"{Name} has {resultingDeck.Count} {valueString}{Environment.NewLine}"; return(resultingDeck); }
public bool PullOutBooks(Player player) { // Pull out a player's books. Return true if the player ran out of cards, otherwise // return false. Each book is added to the Books dictionary. A player runs out of // cards when he’'s used all of his cards to make books—and he wins the game IEnumerable <Values> pulledBook = player.PullOutBooks(); // is a foreach loop for a Dictionary of one a target for improvement? would have to extract the value otherwise foreach (Values value in pulledBook) { books.Add(value, player); textBoxOnForm.Text += $"{player.Name} scored a book of {Card.Plural(value)}.{Environment.NewLine}"; } if (player.CardCount == 0) { return(true); } return(false); }
public void AskForACard(List <Player> players, int myIndex, Deck stock, Values value) { // Ask the other players for a value. First add a line to the TextBox: "Joe asks // if anyone has a Queen". Then go through the list of players that was passed in // as a parameter and ask each player if he has any of the value (using his // DoYouHaveAny() method). He'll pass you a deck of cards—add them to my deck. // Keep track of how many cards were added. If there weren't any, you'll need // to deal yourself a card from the stock (which was also passed as a parameter), // and you'll have to add a line to the TextBox: "Joe had to draw from the stock" Deck resultingDeck; int numCards = 0; string pluralName = Card.Plural(value); bool goFish = true; textBoxOnForm.Text += $"{Name} asks if anyone has a {value}.{Environment.NewLine}"; for (int i = 0; i < players.Count; i++) { if (players[i].Name != Name) { resultingDeck = players[i].DoYouHaveAny(value); numCards = resultingDeck.Count; if (numCards > 0) { goFish = false; for (int j = 0; j < resultingDeck.Count; j++) { cards.Add(resultingDeck.Deal()); } } } } if (goFish) { cards.Add(stock.Deal()); textBoxOnForm.Text += $"{Name} had to Go Fish.{Environment.NewLine}"; } }
public Deck DoYouHaveAny(Values value) { textBoxOnForm.Text += name + " has " + cards.PullOutValues(value).Count.ToString() + Card.Plural(value); return(cards.PullOutValues(value)); }