public void AskForACard(List<Player> players, int myIndex, Deck stock, Value 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), // add you'll have to add a line to the TextBox: "Joe had to draw from the stock" int TotalCount = 0; //int PlayerIndex = 0; this.textBoxOnForm.Text += this.Name + " asks if anyone has a " + value.ToString() + "\r\n"; foreach (Player PlayerToAsk in players) { if (myIndex != players.IndexOf(PlayerToAsk)) { Deck getCards = PlayerToAsk.DoYouHaveAny(value); if (getCards.Count > 0) { TotalCount += getCards.Count; for (int i = getCards.Count; i > 0; i--) cards.Add(getCards.Deal(i - 1)); } } } if (TotalCount == 0) { if(stock.Count > 0) cards.Add(stock.Deal()); this.textBoxOnForm.Text += this.Name + " had to draw from the stock" + "\r\n"; } }
public Player(string name, Random random, TextBox textBoxOnForm) { //The constructor for the Player class ininitializes four private fields, and then //adds a line to the TextBox control on the form that says, "Joe has just // joined the game" -but use the name in the private field, and don't forget to // add a line break at the end of every line you add to the TextBox. this.name = name; this.random = random; this.textBoxOnForm = textBoxOnForm; this.cards = new Deck(new List<Card>()); this.textBoxOnForm.Text += this.name + " has just joined the game\r\n"; }
public Game(string playerName, IEnumerable<string> opponentNames, TextBox textBoxOnForm) { Random random = new Random(); this.textBoxOnForm = textBoxOnForm; players = new List<Player>(); players.Add(new Player(playerName, random, textBoxOnForm)); foreach (string opponent in opponentNames) { players.Add(new Player(opponent, random, textBoxOnForm)); } books = new Dictionary<Value, Player>(); stock = new Deck(); Deal(); players[0].SortHand(); }
public Deck PullOutValues(Value value) { Deck deckToReturn = new Deck(new Card[] { }); for (int i = cards.Count - 1; i >= 0; i--) if (cards[i].Value == value) deckToReturn.Add(Deal(i)); return deckToReturn; }
public void AskForACard(List<Player> players, int myIndex, Deck stock) { //Here's an overloaded version of AskForACard() -choose a random value //from the deck using GetRandomValue() and ask for it using AskForACard() AskForACard(players, myIndex, stock, GetRandomValue()); }
public void AskForACard(List <Player> players, int myIndex, Deck stock) { //Here's an overloaded version of AskForACard() -choose a random value //from the deck using GetRandomValue() and ask for it using AskForACard() AskForACard(players, myIndex, stock, GetRandomValue()); }