/// <summary> /// Method represents a 'round' of competing <c>Card</c> objects. /// It checks current status of player's cards and game status. /// If game is still in play, <c>player.TurnCard</c> is added to <c>TurnCards</c> (List of all players' submitted <c>Card</c> objects for round) /// // and entered into <c>playerCardDict</c>. /// <c>maxCard</c> variable is assigned to the highest card value among <c>TurnCards</c>. /// If <c>maxCard</c> equals null, the card values are tied and the players 'Declare War' /// Otherwise <c>player</c> associated with <c>maxCard</c> in <c>playerCardDict</c> adds <c>TurnCards</c> to their <c>CardsForShuffle</c> pile, /// current round's <c>TurnCards</c> is cleared and returns false. /// </summary> /// <returns>Boolean value whether to 'declare war'</returns> public bool Turn() { CheckPlayersDecks(1); var playerCardDict = new ConcurrentDictionary <Card, Player>(); List <Card> thisTurnCards = new List <Card>(); foreach (var player in Players) { var card = player.ShowCard(); player.TurnCard = card; TurnCards.Add(card); thisTurnCards.Add(card); playerCardDict.TryAdd(card, player); } if (IsDeclareWar(thisTurnCards)) { return(true); } var maxCard = MaxCard(thisTurnCards); var turnWinner = playerCardDict[maxCard]; turnWinner.AddCards(TurnCards); TurnCards.Clear(); return(false); }
/// <summary> /// It checks current status of player's cards and game status. /// If game is still in play, for now, a single additional <c>card</c> is added to <c>TurnCards</c> for 'war' and <c>Turn()</c> method is called again /// </summary> /// <returns>Boolean by way of <c>Turn()</c> method</returns> public bool DeclareWar() { CheckPlayersDecks(3); for (int i = 0; i < 3; i++) { foreach (var player in Players) { var card = player.ShowCard(); TurnCards.Add(card); } } return(Turn()); }