コード例 #1
0
ファイル: Program.cs プロジェクト: RGale25/Blackjack
        private void showTable(bool endOfRound)
        {
            if (endOfRound)
            {
                string cards = "";
                foreach (Card card in dealer.getHand())
                {
                    cards = cards + " " + card.getType() + " " + card.getSuit() + "(" + card.getValue() + ")";
                }

                Console.WriteLine("Dealers's Cards :  {0}  ({1})", cards, dealer.getScore());
            }
            else
            {
                Console.WriteLine("Dealer's Cards : {0} {1}, X", dealer.getHand()[0].getType(), dealer.getHand()[0].getSuit());
            }

            Console.WriteLine();
            foreach (Player player in players)
            {
                string cards = "";
                foreach (Card card in player.getHand())
                {
                    cards = cards + " " + card.getType() + " " + card.getSuit() + "(" + card.getValue() + ")";
                }

                Console.WriteLine("{0}'s Cards :  {1}  ({2})", player.getName(), cards, player.getScore());
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: RGale25/Blackjack
 public void addCardToHand(Card card)
 {
     this.score = getScore();
     Console.WriteLine(score + card.getValue());
     if (this.score + card.getValue() > 21 && card.getType() == "ace") //if top card from deck is ace and makes score > 21 then change cards value to 1
     {
         card.setValue(1);
     }
     else if (this.score + card.getValue() > 21) //if top card makes score > 21 and is not an ace then chack hand for an ace to swap
     {
         bool aceSwapped = false;
         int  i          = 0;
         while (!aceSwapped && i < hand.Count)
         {
             if (hand[i].getValue() == 11)
             {
                 hand[i].setValue(1);
                 aceSwapped = true;
             }
             i++;
         }
     }
     this.hand.Add(card);
     this.score = this.getScore();
 }