static void Main(string[] args) { //intro Console.WriteLine("Welcome to Blackjack where the goal is to get as close to 21 as possible."); Console.WriteLine("This game is meant to help teach basic stradegy"); Console.WriteLine("If a bad/ weird move is made it will tell you the recommended play"); Console.WriteLine("Good Luck and Have fun learning how to play Blackjack"); Console.WriteLine(); string response; //stops game if false Player player = new Player(); //create player Console.WriteLine("You will start off with {0} chips", player.ChipTotal); //player is sitting at table until he wants to end the session do { //create dealer and hand response = ""; player.Bet(); Hand H1 = new Hand(); player.AddHand(H1); Dealer dealer = new Dealer(); //dealer BlackJack if (dealer.BlackKJackCheck()) { player.Lose(); player.RemoveHands();// adjust player back to no hands and ends the round if (MoneyCheck(player.ChipTotal)) { break; } response = EndGameCheck(); continue; } for (int i = 0; i < player.handCount; i++) //iterate throught player hands { if (i > 0) { Console.WriteLine("Your second hand has {0}", player.hands[i].GetPlayerHandSum()); } //Player BlackJack if (player.hands[i].BlackJackCheck()) { player.BlackJack(i + 1); if (player.handCount == 1 || (player.handCount == 2 && i == 1 && player.hands[0].BlackJackCheck() && player.hands[1].BlackJackCheck())) { Console.WriteLine("You have {0} chips left", player.ChipTotal); response = EndGameCheck(); continue; } else { continue; } } string handNum = ""; if (player.handCount > 1) { if (i == 0) { handNum = "First hand ... "; } else if (i == 1) { handNum = "Second hand ... "; } } if (player.handCount > 1) { Console.WriteLine("{0}You can hit, double, split, stay", handNum); } else { Console.WriteLine("You can hit, double, split, stay, surrender"); } string action = Console.ReadLine(); Stradegy(player.hands[i].GetPlayerHandSum(), dealer.card2, action, player.hands[i].SoftCheck(), player.hands[i].CheckSplit()); player.hands[i].Action(action); if (action == "surrender") { player.Surrender(); Console.WriteLine("You have {0} chips left", player.ChipTotal); response = EndGameCheck(); continue; } //split hand if (action == "split") { Hand H2 = player.hands[i].Split(player.hands[i].CheckSplit()); player.AddHand(H2); i--; continue; } //double bet if (action == "double") { player.DoubleBet(i + 1); } //if player bust exit / continue if (player.handCount > 1 && player.hands[i].GetPlayerHandSum() == 0) { if (i == 0) { continue; } else if (i == 1) { break; } } else if (player.hands[i].GetPlayerHandSum() == 0) { player.Lose(); Console.WriteLine("You have {0} chips left", player.ChipTotal); response = EndGameCheck(); continue; } } // check to see if dealer needs to play if (response == "") { Console.WriteLine(); Console.WriteLine("The dealer was hiding a {0}", dealer.card1); Console.WriteLine("The dealer has {0}", dealer.GetDealerHandSum()); dealer.Hit(); Console.WriteLine(); // compare dealer and player hands for (int i = 0; i < player.handCount; i++) { if (dealer.GetDealerHandSum() > player.hands[i].GetPlayerHandSum()) { player.Lose(i + 1); } else if (dealer.GetDealerHandSum() < player.hands[i].GetPlayerHandSum()) { player.Win(i + 1); } else { player.Draw(i + 1); } } // player chips if (MoneyCheck(player.ChipTotal)) { break; } response = EndGameCheck(); } player.RemoveHands();// adjust player back to no hands and ends the round }while (response == "yes"); }
static void Main(string[] args) { Utility.SetupWindow("♣♥ BlackJack ♦♠", 70, 30, false); while (Gameover() == false) { //New Game \ Reset deck.CreateDeck(); hand.ResetHand(); dealer.ResetHand(); //Beginning hand hand.addCardtoHand(deck.DrawCard()); hand.addCardtoHand(deck.DrawCard()); Cards card = deck.DrawCard(); card.Faceup = false; dealer.addCardtoHand(card); //Needs to be faced down dealer.addCardtoHand(deck.DrawCard()); Console.Clear(); Render(); //Bets int amt; do { Console.Write("Bet ammount?"); amt = Utility.ReadInt(); Console.Clear(); Render(); } while (Utility.IsReadGood() && player.getMoney() < amt || amt <= 0); player.Bet(amt); Console.Clear(); Render(); //Draws while (hand.Hit() == true) { Console.Clear(); hand.addCardtoHand(deck.DrawCard()); Render(); if (hand.handValue() > 21) { break; } } Console.Clear(); Render(); //Final hand if (hand.handValue() > 21) { Console.Write("Bust!"); } Console.WriteLine("Your total is " + hand.handValue()); Console.WriteLine("----------------------------------------------------------------------"); while (dealer.dealerHit()) { if (hand.handValue() > 21) { break; } dealer.addCardtoHand(deck.DrawCard()); Render(); } //Determine winner & money distribution if (hand.handValue() < dealer.getHandValue() && dealer.getHandValue() <= 21 || hand.handValue() > 21) { dealer.setMoney(dealer.getMoney() + amt); Console.SetCursorPosition(0, 5); Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("You Lost $" + amt); Console.ResetColor(); Console.SetCursorPosition(35, 3); Console.Write("Dealer had: " + dealer.getHandValue()); } else if (hand.handValue() > dealer.getHandValue() && hand.handValue() <= 21 || dealer.getHandValue() > 21) { dealer.setMoney(dealer.getMoney() - amt); player.setMoney(player.getMoney() + amt + amt); Console.SetCursorPosition(0, 5); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("You won $" + amt); Console.ResetColor(); Console.SetCursorPosition(35, 3); Console.Write("Dealer had: " + dealer.getHandValue()); } else { Console.SetCursorPosition(35, 3); Console.Write("Dealer had: " + dealer.getHandValue()); Console.SetCursorPosition(0, 5); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("A tie occured, money returned"); Console.ResetColor(); player.setMoney(player.getMoney() + amt); } if (dealer.getHandValue() > 21) { Console.SetCursorPosition(35, 3); Console.Write("The Dealer busted"); } card.Faceup = true; Render(); Console.SetCursorPosition(0, 6); /* Optional question * Console.ForegroundColor = ConsoleColor.DarkGray; * Console.Write("Press ENTER to play the next round..."); * Console.ResetColor(); */ Console.Read(); //End screen if (player.getMoney() == 0) { Console.ForegroundColor = ConsoleColor.Red; Utility.WriteCentered("You lost to the dealer. You are now homeless"); break; } if (dealer.getMoney() <= 0) { Console.ForegroundColor = ConsoleColor.Cyan; Utility.WriteCentered("You win! Now the Cassino kicks you out for \"cheating\"!"); break; } Console.Clear(); Render(); } Console.ResetColor(); Console.SetCursorPosition(0, Console.WindowHeight - 1); Console.Write("Press ENTER to exit..."); Console.Read(); Console.ReadLine(); }