当前位置: 首页>>代码示例>>C#>>正文


C# Deck.TakeTopCard方法代码示例

本文整理汇总了C#中Deck.TakeTopCard方法的典型用法代码示例。如果您正苦于以下问题:C# Deck.TakeTopCard方法的具体用法?C# Deck.TakeTopCard怎么用?C# Deck.TakeTopCard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Deck的用法示例。


在下文中一共展示了Deck.TakeTopCard方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        /// <summary> 
        /// A single hand of Blackjack
        /// </summary> 
        /// <param name="args">command-line args</param> 
        static void Main(string[] args)
        {
            //Declare variables for and create a deck of cards and blackjack hands for the dealer and the player

            Deck deck = new Deck();
            BlackjackHand dealerHand = new BlackjackHand("Dealer");
            BlackjackHand playerHand = new BlackjackHand("Player");

            //Print a “welcome” message to the user telling them that the program will play a single hand of Blackjack

            Console.WriteLine("You will play a single hand of Blackjack.");

            // Shuffle the deck of cards

            deck.Shuffle();

            //Deal 2 cards to the player and dealer
            dealerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());

            //Show all the player’s cards

            playerHand.ShowAllCards();

            //Show the dealer’s first card

            dealerHand.ShowFirstCard();

            //Print both the player’s hand and the dealer’s hand

            playerHand.Print();
            dealerHand.Print();

            //Let the player hit if they want to

            playerHand.HitOrNot(deck);

            //Show all the dealer’s cards

            dealerHand.ShowAllCards();

            //Print both the player’s hand and the dealer’s hand

            playerHand.Print();
            dealerHand.Print();

            //Print the scores for both hands

            Console.WriteLine("Player's score: " + playerHand.Score + ".");
            Console.WriteLine("Dealer's score: " + dealerHand.Score + ".");
        }
开发者ID:JoaoGFarias,项目名称:MOOCs-Assigments,代码行数:55,代码来源:Program.cs

示例2: Main

        /// <summary>
        /// Let you play a hand of Blackjack
        /// </summary>
        /// <param name="args">command-line args</param>
        static void Main(string[] args)
        {
            //create deck and two hands
            Deck deck = new Deck();
            BlackjackHand dealerHand = new BlackjackHand("Dealer");
            BlackjackHand playerHand = new BlackjackHand("Player");

            //print welcome message
            Console.WriteLine("Welcome friend!");
            Console.WriteLine("You are now going to play a single hand of Blackjack\n");

            //shuffle the deck
            deck.Shuffle();

            //deal two cards for player
            playerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());

            //deal two cards for dealer
            dealerHand.AddCard(deck.TakeTopCard());
            dealerHand.AddCard(deck.TakeTopCard());

            //make all player's cards face up
            playerHand.ShowAllCards();

            //make first dealer's card face up
            dealerHand.ShowFirstCard();

            //print both hands
            playerHand.Print();
            dealerHand.Print();

            //ask player if he wants to "hit"
            playerHand.HitOrNot(deck);

            //make all dealer's card face up
            dealerHand.ShowAllCards();

            //print both hands
            playerHand.Print();
            dealerHand.Print();

            //print scores
            Console.WriteLine("Player score: {0}", playerHand.Score);
            Console.WriteLine("Dealer score: {0}", dealerHand.Score);
        }
开发者ID:Elinos,项目名称:Beginning-Game-Programming-With-CSharp,代码行数:50,代码来源:Program.cs

示例3: Taking_a_card_from_the_deck_reduces_the_count_by_one

 public void Taking_a_card_from_the_deck_reduces_the_count_by_one()
 {
     IDeck deck = new Deck();
     deck.InitialiseDeck();
     deck.TakeTopCard();
     Assert.AreEqual(51, deck.Count);
 }
开发者ID:Roonerelli,项目名称:Shithead,代码行数:7,代码来源:Class1.cs


注:本文中的Deck.TakeTopCard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。