Пример #1
0
 /// <summary>
 /// Deal a card pile to the players
 /// </summary>
 /// <param name="cs">card pile to be dealt</param>
 /// <param name="player1">player 1</param>
 /// <param name="player2">player 2</param>
 public void DealCards(CardPile cs, Player player1, Player player2)
 {
     while (cs.NumberOfCards != 0)
     {
         player1.AddToHand(cs.RemoveNextCard());
         player2.AddToHand(cs.RemoveNextCard());
     }
 }
Пример #2
0
        /// <summary>
        /// Shuffles cards
        /// </summary>
        /// <param name="cs">card pile to be shuffled</param>
        /// <param name="numTimes">number of times the card pile is to be shuffled</param>
        public void Shuffle(CardPile cs, int numTimes)
        {
            if (cs.NumberOfCards == 0)
            {
                Console.WriteLine("A Deck must be created before it can be shuffled");
                return;
            }

            cs.Shuffle(numTimes);
        }
Пример #3
0
 /// <summary>
 /// Creates (hydrates) a full card deck based on Card suits and rank enum
 /// </summary>
 /// <param name="cs">Object to be hydrated</param>
 public void CreateDeck(CardPile cs)
 {
     foreach (CardSuit suit in Enum.GetValues(typeof(CardSuit)))
     {
         foreach (CardRank rank in Enum.GetValues(typeof(CardRank)))
         {
             cs.AddCard(new Card(suit, rank));
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Primary loop that runs the War card game
        /// </summary>
        /// <param name="battleOutput">User interface output class</param>
        /// <returns>GamesResults object with winning and losing player</returns>
        public static GameResults RunGame(IBattleOutput battleOutput)
        {
            Game     game = new Game(battleOutput);
            CardPile deck = new CardPile();

            game.CreateDeck(deck);
            game.Shuffle(deck, _numberOfShuffles);

            Player player1 = new Player();
            Player player2 = new Player();

            game.DealCards(deck, player1, player2);

            if (player1.NumberOfCards == 0 || player2.NumberOfCards == 0)
            {
                Console.WriteLine("Error:  Something happend during the creation / shuffling / dealing of the game");
                return(null);
            }

            return(game.PlayGame(player1, player2));
        }
Пример #5
0
 /// <summary>
 /// Default constructor that instantiates a player
 /// </summary>
 public Player()
 {
     _hand       = new CardPile();
     _winPile    = new CardPile();
     _battlePile = new BattlePile();
 }