コード例 #1
0
 /// <summary>
 /// Called to manage players draw.
 /// </summary>
 private void handleDraws()
 {
     // update the player cards
     WaitSynchronizePlayers();
     // go over all of the playing players
     foreach (Player curPlayer in PlayingPlayers)
     {
         // Get the player index which identifies the player in the game
         int playerIndex = GetPlayerGameIndex(curPlayer);
         // Create a new drawing action for the player
         PlayerDrawingAction action = new PlayerDrawingAction();
         // Call derived class with betting action and wait for a response
         WaitPlayerDrawingAction(curPlayer, action);
         // check that there are any cards to draw.
         if (action.DrawnCards.Count > 0)
         {
             // Get the first 3 distinct cards
             var drawnCards = action.DrawnCards.Distinct().Take(3);
             // Draw the cards on behalf of the player
             game.Draw(playerIndex, drawnCards.ToArray());
             // update the player container:
             // first remove the old cards,
             foreach (Card oldCard in drawnCards)
             {
                 curPlayer.Cards.Remove(oldCard);
             }
             // then add the new cards
             foreach (Card newCard in game.GetPlayerCards(playerIndex))
             {
                 if (!curPlayer.Cards.Contains(newCard))
                 {
                     curPlayer.Cards.Add(newCard);
                 }
             }
             // Notify the derived classes with the player and the new cards.
             NotifyPlayerNewCards(curPlayer);
         }
     }
     // Notify derived class that there are no more draws.
     NotifyDrawComplete();
 }
コード例 #2
0
 /// <summary>
 /// A method which is used to get the player drawing action. Derived classes must override this method to perform the action.
 /// </summary>
 /// <param name="player">The player which may draw new cards</param>
 /// <param name="action">The drawing action which must be updated with the player drawing selection</param>
 protected abstract void WaitPlayerDrawingAction(Player player, PlayerDrawingAction action);