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(); }
public int deal() { Card a = cardDeck[0]; discard.Add(a); cardDeck.RemoveAt(0); a.print(); return(a.getValue()); }
public String Play() { var deck = new Deck(); deck.createDeck(); Console.WriteLine("Shuffling the deck..."); deck.shuffleDeck(); int iterator = 0; while (user_score < 21 && dealer_score < 21) { if (iterator == 0) { Card card = deck.drawCard(); Console.WriteLine("You drew a " + card.getCard()); user_score += card.getValue(); Console.WriteLine("Your Score: " + user_score); Card dealer_card = deck.drawCard(); Console.WriteLine("The dealer drew a " + dealer_card.getCard()); dealer_score += dealer_card.getValue(); Console.WriteLine("Dealer Score: " + dealer_score); } else { Console.WriteLine("Hit or Stand?"); String hitOrStand = Console.ReadLine().ToLower(); if (hitOrStand == "hit") { Card card = deck.drawCard(); Console.WriteLine("You drew a " + card.getCard()); user_score += card.getValue(); Console.WriteLine("Your Score: " + user_score); } Card dealer_card = deck.drawCard(); Console.WriteLine("The dealer drew a " + dealer_card.getCard()); dealer_score += dealer_card.getValue(); Console.WriteLine("Dealer Score: " + dealer_score); } iterator++; } return(determineWinner()); }
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()); } }