/// <summary> /// Makes one player play a round /// </summary> /// <param name="player">The player asking for a card</param> /// <param name="playerToAsk">The player being asked for a card</param> /// <param name="valueToAskFor">The value to ask the player for</param> /// <param name="stock">The stock to draw cards from</param> /// <returns>A message that describes what just happened</returns> public string PlayRound(Player player, Player playerToAsk, Values valueToAskFor, Deck stock) { var valuePlural = (valueToAskFor == Values.Six) ? "Sixes" : $"{valueToAskFor}s"; var message = $"{player.Name} asked {playerToAsk.Name}" + $" for {valuePlural}{Environment.NewLine}"; var cards = playerToAsk.DoYouHaveAny(valueToAskFor, stock); if (cards.Count() > 0) { player.AddCardsAndPullOutBooks(cards); message += $"{playerToAsk.Name} has {cards.Count()}" + $" {valueToAskFor} card{Player.S(cards.Count())}"; } else if (stock.Count == 0) { message += $"The stock is out of cards"; } else { player.DrawCard(stock); message += $"{player.Name} drew a card"; } if (player.Hand.Count() == 0) { player.GetNextHand(stock); message += $"{Environment.NewLine}{player.Name} ran out of cards," + $" drew {player.Hand.Count()} from the stock"; } return(message); }
/// <summary> /// Constructor creates the players and deals their first hands /// </summary> /// <param name="humanPlayerName">Name of the human player</param> /// <param name="opponentNames">Names of the computer players</param> /// <param name="stock">Shuffled stock of cards to deal from</param> public GameState(string humanPlayerName, IEnumerable <string> opponentNames, Deck stock) { this.Stock = stock; HumanPlayer = new Player(humanPlayerName); HumanPlayer.GetNextHand(Stock); var opponents = new List <Player>(); foreach (string name in opponentNames) { var player = new Player(name); player.GetNextHand(stock); opponents.Add(player); } Opponents = opponents; Players = new List <Player>() { HumanPlayer }.Concat(Opponents); }