public GameMech() { GameTable = new Table(); HeadDealer = new Dealer(3); GeneratePlayers(HowManyPlayers()); GamePlayDisplay(); }
public GameMech() { bjTable = new Table(); bjDealer = new Dealer(3); bjDealer.Deck.ShuffleDeck(); SetupPlayer(); // Setup Wallet? // Nice name //StartBlackJack(); // SetupTable PlayGame(); }
public static Win CheckWinner(Player user, Dealer dealer ) { if (dealer.PlayerScore > 21 && user.PlayerScore < 22) { return Win.Player; } if (user.PlayerScore > 21 && dealer.PlayerScore < 22) { return Win.Dealer; } if(dealer.PlayerScore > user.PlayerScore) { return Win.Dealer; } return Win.None; }
public Game() { dealer = new Dealer(); dealer.shuffle(); dealer.init(); player = new Player(new Hand(new List<Card>(){dealer.hit(), dealer.hit()}), dealer); player.start(); dealer.start(); bool playerWin = false; if(player.getHand().isBursted()) playerWin = false; else if(dealer.getHand().isBursted()) playerWin = true; else if(player.getHand().getValue() > dealer.getHand().getValue()) playerWin = true; else if(player.getHand().isBlackJack() && !dealer.getHand().isBlackJack()) playerWin = true; System.Console.WriteLine(playerWin ? "Win" : "Lose"); Console.ReadLine(); }
//public Deck GetDeck() //{ // return deck; //} public void StartUp() { numHands = 1; currentHand = 1; deck = new Deck(1); //player = new Player(); playerList = new List <Player>(); playerList.Add(new Player()); dealer = new Dealer(); //intialize money, start with two cards for player and 2 cards with dealer with one face down // User can hit until satisfied or busts // Dealer then hits until satisfied or busts //create instace of deck class and call the shuffle method BlackJack.disableHitStand(); BlackJack.disableBetting(); BlackJack.initAddMoneyCmbBox(); //Intilaize money //Intialize cards in dealer's and player's hands //Deal(); }
public void Play() { _discardPile = new List<Card>(); // create a player _player = new Player(); // create a dealer _dealer = new Dealer(); // create some cards in a deck of cards _deck = new DeckOfCards(); _deck.Shuffle(); while (true) { List<Card> discards; discards = _player.ClearYourHand(); _discardPile.AddRange(discards); discards = _dealer.ClearYourHand(); _discardPile.AddRange(discards); // deal the cards Card cardToDeal; cardToDeal = GetTopCardFromDeck(); _player.PutInHand(cardToDeal); cardToDeal = GetTopCardFromDeck(); _dealer.PutInHand(cardToDeal); cardToDeal = GetTopCardFromDeck(); _player.PutInHand(cardToDeal); cardToDeal = GetTopCardFromDeck(); _dealer.PutInHand(cardToDeal); // print the state of the game for the user PrintTheGame(); // hit the player until they don't wanna be hit no more while (_player.HasNotGoneOver21() && _player.WantsAnotherCard()) { cardToDeal = GetTopCardFromDeck(); _player.PutInHand(cardToDeal); PrintTheGame(); } // stop if the player busts if (_player.HasGoneOver21()) { Console.WriteLine("You have lost, human."); Console.WriteLine("It is a sad day for your species."); } else { _dealer.ShowAllOfYourCards(); // hit the dealer until the computer is over 17 while (_dealer.HasNotGoneOver21() && _dealer.WantsAnotherCard()) { cardToDeal = GetTopCardFromDeck(); _dealer.PutInHand(cardToDeal); } PrintTheGame(); // figure out the winner if (_dealer.HasGoneOver21()) { Console.WriteLine("You win, this time, human."); } else if (_player.TotalOfHand() >= _dealer.TotalOfHand()) { Console.WriteLine("You win, this time, human."); } else { Console.WriteLine("You have lost, puny human."); Console.WriteLine("Your species will never win."); } } // see if the player wants to go another hand Console.WriteLine("Press any key but N and Enter to play another hand."); string input = Console.ReadLine().ToLower(); if (input == "n") { break; } } }
public void DrawGameCharacters(SpriteBatch spriteBatch) { Player.Draw(spriteBatch); Dealer.Draw(spriteBatch); }
public Game() { Deck = new Deck(); Player = new Player(); Dealer = new Dealer(); }
public Game() { deck = new Deck(); player = new Player(); dealer = new Dealer(); }
public void LoadContent() { player = GameManager.Instance.Player; dealer = GameManager.Instance.Dealer; }
public void Play() { deck = new CardDeck(); gamer = new Gamer(); gamer.TakeCard(); ShowHands(gamer); if (gamer.Sum == 21) { Console.WriteLine("Black Jack, You WIN!"); task = Task.Factory.StartNew(() => StatInsert("Black Jack")); //StatInsert("Black Jack"); Console.ReadKey(); } else { bool flag = false; do { if (flag) { gamer.TakeCard(); ShowHands(gamer); } if (gamer.Sum > 21) { Console.WriteLine("Bust! You lose"); task = Task.Factory.StartNew(() => StatInsert("Bust")); //StatInsert("Bust"); break; } else if (gamer.Sum == 21) { break; } Answer("More card?", out flag); } while (flag); if (gamer.Sum <= 21) { dealer = new Dealer(); dealer.DealerPlay(); if (dealer.Sum > 21) { ShowHands(dealer); Console.WriteLine("You win!"); task = Task.Factory.StartNew(() => StatInsert("Win")); //StatInsert("Win"); } else if (dealer.Sum <= 21 && dealer.Sum > gamer.Sum) { ShowHands(dealer); Console.WriteLine("Dealer wins, you lose"); task = Task.Factory.StartNew(() => StatInsert("Lose")); //StatInsert("Lose"); } else if (dealer.Sum < 21 && dealer.Sum < gamer.Sum) { ShowHands(dealer); Console.WriteLine("You Win!"); task = Task.Factory.StartNew(() => StatInsert("Win")); //StatInsert("Win"); } else { ShowHands(dealer); Console.WriteLine("Push!"); task = Task.Factory.StartNew(() => StatInsert("Push")); //StatInsert("Push"); } } } }
public bool Run() { //リスタート有無 var isRestartGame = false; InitializeGame(); FirstDraw(); //プレイヤーターン Turn = Turn.PlayerTurn; var playerAction = ConfirmPlayerAction(); while (playerAction == PlayerAction.Hit) { Player.DrawCard(Deck); ShowPointsAndHand(Player); ShowPointsAndHand(Dealer); if (!Player.Hand.IsBust) { playerAction = ConfirmPlayerAction(); } else { break; } } //プレイヤーがバーストしてなければディーラーターン if (!Player.Hand.IsBust) { Turn = Turn.DealerTurn; while (!Dealer.CanDraw) { Dealer.DrawCard(Deck); } //ディーラーがバーストしていなければ結果表示 if (!Dealer.Hand.IsBust) { ShowResult(); } else { ShowPointsAndHand(Player); ShowPointsAndHand(Dealer); ShowBustMessage(Dealer); ShowResultMessage(Result.Win); } } else { ShowBustMessage(Player); ShowResultMessage(Result.Lose); } isRestartGame = ConfirmRestartGame(); return(isRestartGame); }
public static void BJ() { int round = 0; do //一局的开始 { Casino c = new Casino(); //系统 Computer com = new Computer(); //新的电脑玩家实例 Dealer d = new Dealer(); //新的庄家实例 Human p = new Human(); //新的个人玩家实例 c.I = 0; //准备阶段 c.Shuffle(); //洗牌 Console.WriteLine("**********************************************"); Console.WriteLine("Welcome to BlackJack,Round:{0}", round); Console.WriteLine("Computer Win rate={0}%", Computer.WinRate); Console.WriteLine("Versus"); Console.WriteLine("Human Win rate={0}%", 100 * p.Win / (p.Win + p.Lose)); Console.WriteLine("**********************************************"); //玩家回合 c.I = com.PlayerRound(c.I); //c.I = p.PersonRound(c.I); Console.WriteLine(" "); Console.WriteLine("DealerHand"); Console.WriteLine("----------"); //庄家回合 if (com.Flag == 1)//电脑玩家和人类玩家同时有特殊状况?有则不进入庄家回合直接下一轮 { } else { d.Flag = d.DealerRound(c.I, com, p); //结算 if (d.Flag == 0) //庄家没爆 { if (com.Flag == 0) //电脑玩家没特殊情况就允许结算 { com.GetResult(com.Sum, d.Sum); } if (p.Flag == 0)//人类玩家没特殊情况就允许结算 { //p.GetResult(p.Sum, d.Sum); } } } //if ((round >= 100) && ((100*p.Win/(p.Win+p.Lose)) >= com.WinRate)) //{ // Console.WriteLine("红包密码666!"); //} //Console.ReadKey(); com.EditTendencyToSql(3, com.CardCombination); if (com.IfViceExp != 0) { com.EditTendencyToSql(4, com.Sum); } using (SqlConnection sqlcon = new SqlConnection("Server=.;DataBase=BlackJack;Trusted_Connection=SSPI")) { sqlcon.Open(); string cmdstring = "UPDATE BJWinRate SET WinRate = @WinRate, Time = @Time WHERE ID = 1"; SqlCommand cmd = new SqlCommand(cmdstring, sqlcon); cmd.Parameters.AddWithValue("@WinRate", Convert.ToString(Computer.WinRate)); cmd.Parameters.AddWithValue("@Time", DateTime.Now.ToString("HH:mm:ss")); cmd.ExecuteNonQuery(); } Console.WriteLine("**********************************************"); round++; Console.Clear(); } while (true); }
static void Main(string[] args) { // Text strings ... string txtPlayerBorder = "---- Player ----"; string txtDealerBorder = "---- Dealer ----"; string txtHandTotal = "Hand total is currently:"; string txtEndGame = "\nPress ENTER to end this game."; string txtPlayerCurrTotal = "Player, your total is currently: "; string txtPlayerTotal = "Player total is : "; string txtDealerTotal = "Dealer total is : "; string txtPlayerBlackJack = "Congratulations! You have a Blackjack!" + txtEndGame; string txtDealerBlackJack = "I'm sorry, the house wins with a Blackjack." + txtEndGame; string txtDealerWins = "-- I am sorry. The house wins this round --" + txtEndGame; string txtPlayerWins = "-- Congratulations! You won! --" + txtEndGame; string txtDraw = "-- The game was a draw. --" + txtEndGame; // End text strings ... Utility myUtils = new Utility(); // Instance of Deck Deck deck = new Deck(); // Instantiate the two participants Dealer dealer = new Dealer(); Player player = new Player(); bool gameOver = false; // Deal cards to players for (int i = 0; i < 2; i++) { Card playerCard = dealer.DealCard(deck); Card dealerCard = dealer.DealCard(deck); player.Hand.Add(playerCard); dealer.Hand.Add(dealerCard); } // Set up the board myUtils.ColorPrint(txtPlayerBorder, player.color); foreach (Card card in player.Hand) { Console.WriteLine("{0} of {1}", card.Rank, card.Suit); } player.HandTotal(); myUtils.ColorPrint(String.Format("{0} {1}", txtHandTotal, player.handTotal), player.color); myUtils.ColorPrint(txtDealerBorder, dealer.color); // I only want to show one card... Console.WriteLine("{0} of {1}", dealer.Hand[1].Rank, dealer.Hand[1].Suit); dealer.HandTotal(); /* * foreach (Card card in dealer.Hand) * { * Console.WriteLine("{0} of {1}", card.Rank, card.Suit); * } * * * myUtils.ColorPrint(String.Format("{0} {1}", txtHandTotal, dealer.handTotal), dealer.color); */ // Time to play -- player first if (myUtils.checkBlackJack(player.Hand)) { myUtils.ColorPrint(txtPlayerBlackJack, player.color); dealer.win = true; gameOver = true; } else { player.turn = true; } if (myUtils.checkBlackJack(dealer.Hand)) { myUtils.ColorPrint(txtDealerBlackJack, dealer.color); gameOver = true; } else { player.turn = true; } if (!gameOver && player.turn == true) { Console.WriteLine("----------------------"); Console.WriteLine("--- Player's Turn ---"); Console.WriteLine("----------------------"); Console.WriteLine("{0}{1}", txtPlayerCurrTotal, player.handTotal); } //Console.WriteLine("Player's turn status: {0}", player.turn); while (!gameOver && player.turn == true) { if (player.handTotal < 21) { Console.WriteLine("What would you like to do?\n(Type \"hit\" or \"h\" to hit, \"stay\" or \"s\" to stay.)"); string playerMove = Console.ReadLine(); playerMove.Trim().ToLower(); switch (playerMove) { case "h": case "hit": Card newCard = dealer.DealCard(deck); if (newCard.Rank == "Ace") { Console.WriteLine("You have received an Ace. Would you like it to be worth 1 or 11 ?"); newCard.Value = Convert.ToInt32(Console.ReadLine()); } player.Hand.Add(newCard); player.HandTotal(); myUtils.ColorPrint(String.Format("You chose to hit. You received a {0} of {1}. Your new total is {2}.", newCard.Rank, newCard.Suit, player.handTotal), player.color); break; case "s": case "stay": Console.WriteLine("You chose to stay. Your turn is now complete. It is now the dealer's turn."); player.turn = false; dealer.turn = true; break; default: Console.WriteLine("I don't recognize that request. Please select either 'hit' or 'stay'."); break; } } else if (player.handTotal == 21) { player.turn = false; player.win = true; } else { myUtils.ColorPrint("You have bust.", "red"); dealer.win = true; gameOver = true; Console.WriteLine(txtEndGame); } } // now the dealer if (dealer.turn == true && !gameOver) { dealer.PlayTurn(deck); } // real quick check if the dealer didn't win if (!dealer.win && !gameOver) { if (dealer.handTotal > 21) { player.win = true; } } // show the dealer's hand foreach (Card card in dealer.Hand) { Console.WriteLine("{0} of {1}", card.Rank, card.Suit); } myUtils.ColorPrint(String.Format("{0} {1}", txtHandTotal, dealer.handTotal), dealer.color); if (player.win == true && !gameOver) { myUtils.ColorPrint(txtPlayerWins, player.color); gameOver = true; } else if (dealer.win == true && !gameOver) { myUtils.ColorPrint(txtDealerWins, dealer.color); } else if (!gameOver) { // no obvious winner, we need to evaluate ... if (player.handTotal > dealer.handTotal) { Console.WriteLine("{0}{1} - {2}{3}", txtPlayerTotal, player.handTotal, txtDealerTotal, dealer.handTotal); myUtils.ColorPrint(txtPlayerWins, player.color); } else if (player.handTotal < dealer.handTotal) { Console.WriteLine("{0}{1} -- {2}{3}", txtPlayerTotal, player.handTotal, txtDealerTotal, dealer.handTotal); myUtils.ColorPrint(txtDealerWins, dealer.color); } else { Console.WriteLine(txtDraw); } } Console.ReadLine(); }
public MainNode() { Deck = new Deck(); Player = new Player(Deck); Dealer = new Dealer(Deck); //タイトル Title = new SpriteNode(); Title.Texture = Texture2D.Load("resources/title.png"); Title.Position = Engine.WindowSize / 2; Title.CenterPosition = Title.ContentSize / 2; Title.ZOrder = 5; AddChildNode(Title); //勝ち表示 Win = new SpriteNode(); Win.Texture = Texture2D.Load("resources/win.png"); Win.Position = Engine.WindowSize / 2; Win.CenterPosition = Win.ContentSize / 2; Win.ZOrder = 10; Win.IsDrawn = false; AddChildNode(Win); //負け表示 Lose = new SpriteNode(); Lose.Texture = Texture2D.Load("resources/lose.png"); Lose.Position = Engine.WindowSize / 2; Lose.CenterPosition = Lose.ContentSize / 2; Lose.ZOrder = 10; Lose.IsDrawn = false; AddChildNode(Lose); //引き分け Draw = new SpriteNode(); Draw.Texture = Texture2D.Load("resources/draw.png"); Draw.Position = Engine.WindowSize / 2; Draw.CenterPosition = Draw.ContentSize / 2; Draw.ZOrder = 10; Draw.IsDrawn = false; AddChildNode(Draw); //バスト Bust = new SpriteNode(); Bust.Texture = Texture2D.Load("resources/bust.png"); Bust.Position = Engine.WindowSize / 2; Bust.CenterPosition = Bust.ContentSize / 2; Bust.ZOrder = 10; Bust.IsDrawn = false; AddChildNode(Bust); //ブラックジャック Blackjack = new SpriteNode(); Blackjack.Texture = Texture2D.Load("resources/jack.png"); Blackjack.Position = Engine.WindowSize / 2; Blackjack.CenterPosition = Blackjack.ContentSize / 2; Blackjack.ZOrder = 10; Blackjack.IsDrawn = false; AddChildNode(Blackjack); PCardPointSum = new TextNode(); PCardPointSum.Font = Font.LoadDynamicFont("resources/mplus-1m-regular.ttf", 60); PCardPointSum.CenterPosition = PCardPointSum.ContentSize / 2; PCardPointSum.Position = new Vector2F(520, 665); PCardPointSum.ZOrder = 5; AddChildNode(PCardPointSum); DCardPointSum = new TextNode(); DCardPointSum.Font = Font.LoadDynamicFont("resources/mplus-1m-regular.ttf", 60); DCardPointSum.CenterPosition = DCardPointSum.ContentSize / 2; DCardPointSum.Position = new Vector2F(520, 83); DCardPointSum.ZOrder = 5; DCardPointSum.Text = "?"; AddChildNode(DCardPointSum); RoundText = new TextNode(); RoundText.Text = Round.ToString(); RoundText.Font = Font.LoadDynamicFont("resources/mplus-1m-regular.ttf", 70); RoundText.CenterPosition = RoundText.ContentSize / 2; RoundText.Position = new Vector2F(837, 645); RoundText.ZOrder = 2; AddChildNode(RoundText); //リザルトのマスク Mask = new SpriteNode(); Mask.Texture = Texture2D.Load("resources/mask.png"); Mask.Position = Engine.WindowSize / 2; Mask.CenterPosition = Mask.ContentSize / 2; Mask.ZOrder = 15; Mask.Color = new Color(0, 0, 0, 0); AddChildNode(Mask); //リザルトのマスク Mask = new SpriteNode(); Mask.Texture = Texture2D.Load("resources/mask.png"); Mask.Position = Engine.WindowSize / 2; Mask.CenterPosition = Mask.ContentSize / 2; Mask.ZOrder = 15; Mask.Color = new Color(0, 0, 0, 0); AddChildNode(Mask); //リザルトタイトル ResultTitle = new SpriteNode(); ResultTitle.Texture = Texture2D.Load("resources/resultTitle.png"); ResultTitle.Position = new Vector2F(Engine.WindowSize.X / 2, Engine.WindowSize.Y / 5); ResultTitle.CenterPosition = ResultTitle.ContentSize / 2; ResultTitle.ZOrder = 16; ResultTitle.IsDrawn = false; AddChildNode(ResultTitle); //リザルトのPlayer, Dealer表示 ResultHolder = new SpriteNode(); ResultHolder.Texture = Texture2D.Load("resources/score.png"); ResultHolder.Position = new Vector2F(Engine.WindowSize.X / 2, Engine.WindowSize.Y / 2 - 70); ResultHolder.CenterPosition = ResultHolder.ContentSize / 2; ResultHolder.ZOrder = 16; ResultHolder.IsDrawn = false; AddChildNode(ResultHolder); //スコアの間の棒 ResultBar = new SpriteNode(); ResultBar.Texture = Texture2D.Load("resources/resultBar.png"); ResultBar.Position = Engine.WindowSize / 2; ResultBar.CenterPosition = ResultBar.ContentSize / 2; ResultBar.ZOrder = 16; ResultBar.IsDrawn = false; AddChildNode(ResultBar); //リザルトメッセージ ResultMessage = new SpriteNode(); ResultMessage.Position = new Vector2F(Engine.WindowSize.X / 2, (Engine.WindowSize.Y / 3) * 2 + 20); ResultMessage.ZOrder = 16; AddChildNode(ResultMessage); //リザルトのスコア表示 Score = new TextNode(); Score.Font = Font.LoadDynamicFont("resources/mplus-1m-regular.ttf", 100); Score.CenterPosition = Score.ContentSize / 2; Score.Position = Engine.WindowSize / 2; Score.ZOrder = 16; Score.Text = ""; AddChildNode(Score); coroutine = PlayCoroutine(Update()); }
public void Start() { CreateDeck(); playerOne = new Player(new Point(0, 70), "red"); dealer = new Dealer(new Point(400, 70), "red"); }
/// <summary> /// Display the current gaming board/table /// </summary> /// <param name="dealer">The Dealer object</param> /// <param name="numberOfPlayers">Number of players playing</param> /// <param name="playersList">The list of players</param> /// <param name="deal">Current deal</param> public static void DisplayBoard(Dealer dealer, int numberOfPlayers, List <Player> playersList, int deal) { DisplayDealer(dealer, false); DisplayPlayers(numberOfPlayers, playersList); }
static void Main(string[] args) { bool continueProgram = true; do { Console.Clear(); Shoe decks = new Shoe(); decks.GenerateDeck(); bool dealerNeedsToDraw = true; bool askForHitAgain = true; bool playerBusted = false; bool dealerBusted = false; var deck = decks.cards; Shoe.addAsciiCards(deck); List <Card> playerHand = Player.startingDealPlayer(deck); List <Card> dealerHand = Dealer.startingDealDealer(deck); int dealerHandValue = 0; dealerHandValue = Dealer.showOneOfDealersCards(dealerHand); Console.WriteLine("\nDealer Shows " + dealerHand[0].NumericValue + "\n"); int playersHandValue = 0; playersHandValue = Player.displaysPlayersCards(playerHand, playersHandValue); Console.WriteLine("\nYou drew " + playersHandValue + "\n"); if (playersHandValue == 21) { Console.WriteLine("Black Jack!!!\nYou Win!!!\n"); } else { int timesThroughTheHitOrMissLoop = 1; do { if (playersHandValue > 21) { Console.WriteLine("Player Busted"); playerBusted = true; break; } else if (playersHandValue == 21) { break; } Deal.askForHitOrStay(ref askForHitAgain, deck, playerHand, ref playersHandValue, ref timesThroughTheHitOrMissLoop); } while (askForHitAgain); if (playersHandValue == 21) { Console.WriteLine("Black Jack!!!\nYou Win!!!\n"); } else { Console.WriteLine(); int timesThroughTheDealerLessThanLoop = 1; if (playerBusted == false) { Deal.checkForDraw(ref dealerNeedsToDraw, deck, dealerHand, ref dealerHandValue, ref timesThroughTheDealerLessThanLoop); Console.WriteLine("Dealer Has\n"); dealerHandValue = dealerHandValue - dealerHandValue; Dealer.checkForDealerBust(ref dealerBusted, dealerHand, ref dealerHandValue); } Table.CheckForWin(playerBusted, dealerBusted, dealerHandValue, playersHandValue); } } continueProgram = Table.Restart(); } while (continueProgram); }
public List <Card> getCards(Dealer dealer) { return(dealer.getHand()); }
static void Main(string[] args) { //Initialize deck CardDeck CardDecks = new CardDeck(1); CardDecks.SetResetDeck(); //Set up dealer Dealer dealer = new Dealer(); //Start the game Console.WriteLine("----------------------------------------"); Console.WriteLine("Welcome to BlackJack"); Console.WriteLine("----------------------------------------"); //Create Players int PlayerCnt = 1; Player Player2 = new Player(); Player Player3 = new Player(); Player Player4 = new Player(); Console.WriteLine("Please enter player name"); String PlayerName = Console.ReadLine(); Player Player1 = new Player(PlayerName); Console.WriteLine($"Player '{Player1.Name}' created. Would you like to add another player?"); //Case to create player 2 if (Console.ReadLine().ToLower() != "no") { Console.WriteLine("Please enter player name"); PlayerName = Console.ReadLine(); Player2 = new Player(PlayerName); Console.WriteLine($"Player '{Player2.Name}' created. Would you like to add another player?"); PlayerCnt++; //case to create player 3 if (Console.ReadLine().ToLower() != "no") { Console.WriteLine("Please enter player name"); PlayerName = Console.ReadLine(); Player3 = new Player(PlayerName); Console.WriteLine($"Player '{Player3.Name}' created. Would you like to add another player?"); PlayerCnt++; //case to create player 4 if (Console.ReadLine().ToLower() != "no") { Console.WriteLine("Please enter player name"); PlayerName = Console.ReadLine(); Player4 = new Player(PlayerName); Console.WriteLine($"Player '{Player4.Name}' created."); PlayerCnt++; } } } Console.WriteLine("Lets start!"); List <Player> Players = new List <Player>(); //Create a list of players based on players created switch (PlayerCnt) { case 1: Players.Add(Player1); break; case 2: Players.Add(Player1); Players.Add(Player2); break; case 3: Players.Add(Player1); Players.Add(Player2); Players.Add(Player3); break; case 4: Players.Add(Player1); Players.Add(Player2); Players.Add(Player3); Players.Add(Player4); break; } string ContinueGame; do { PlayBlackJack(Players, dealer, CardDecks); if (Players.Count() == 0) { Console.WriteLine($"You have (all) lost. Game Over."); break; } Console.WriteLine("Would you like to play again?"); ContinueGame = Console.ReadLine().ToLower(); } while(ContinueGame != "no"); }
}//end of method to change text colour //method to play game public static void Play() { //create dealer and players var dealer = new Dealer(new Player("Dealer"), new List <Card>()); var players = new List <Player>(); CreatePlayers(players); Console.WriteLine(); //deal 2 cards to each player foreach (Player player in players) { Console.WriteLine($"{player.Name}"); while (player.Hand.Count < 2) { var card = dealer.Deal(); player.Hand.Add(card); player.Score = Score.EvaluateHand(player.Hand); TextColour(card.House); Console.WriteLine($"The card dealt is {card.Face} of {card.House}"); Console.ForegroundColor = ConsoleColor.DarkBlue; } //Display player score Console.WriteLine($"{player.Name}'s score is {player.Score}"); //ask player to stick or twist StickOrTwist(dealer, player); #region Betting (Not Finished) //ask each player how much they want to bet //Console.WriteLine($"{player.Name}"); //Console.WriteLine("How many chips would you like to put down ?"); //string input = Console.ReadLine(); //int chips = Convert.ToInt32(input); //player.Bet = Bet.TotalBet(chips); //Display player bet //Console.WriteLine($"{player.Name}'s current bet is {player.Bet}"); //Console.WriteLine(); ////ask if they want to bet more //Console.WriteLine($"Your current bet is {player.Bet}"); //Console.WriteLine("Would you like to put down more chips? Y or N"); //string answer = Console.ReadLine(); ////more chips //if (answer is "y" || answer is "Y") //{ // Console.WriteLine("How many chips would you like to put down?"); // string input = Console.ReadLine(); // int chips = Convert.ToInt32(input); // player.Bet = Bet.TotalBet(chips); // Console.WriteLine($"{player.Name}'s current bet is {player.Bet}"); // Console.WriteLine(); //} ////no more //else if (answer is "n" || answer is "N") //{ // Console.WriteLine("Next Player!"); // Console.WriteLine(); //} #endregion } //get 2 random cards for dealer while (dealer.Hand.Count < 2) { var card = dealer.Deal(); dealer.Hand.Add(card); dealer.Player.Score = Score.EvaluateHand(dealer.Hand); TextColour(card.House); Console.WriteLine($"The card dealt is {card.Face} of {card.House}"); Console.ForegroundColor = ConsoleColor.DarkBlue; } //keep dealing if under 17 while (dealer.Player.Score < 17) { var card = dealer.Deal(); dealer.Hand.Add(card); dealer.Player.Score = Score.EvaluateHand(dealer.Hand); TextColour(card.House); Console.WriteLine($"The card dealt is {card.Face} of {card.House}"); Console.ForegroundColor = ConsoleColor.DarkBlue; } //display dealer score Console.WriteLine($"Dealer's score is {dealer.Player.Score}"); //busts or blackjacks BustsAndBlackjacks(players, dealer); //closest to 21 Winner(players, dealer); //play again? PlayAgain(); //pause console Console.ReadLine(); }//end play method
static void PlayBlackJack(List <Player> Players, Dealer dealer, CardDeck cardDecks) { //Place a bet foreach (Player player in Players) { Console.WriteLine($"How much would you like to bet {player.Name}? Your balance is: ${player.Chips}"); //Capture bet long BetAmt = Convert.ToInt64(Console.ReadLine()); player.MakeBet(BetAmt); } //Deal cards cardDecks.DealCards(Players, dealer); cardDecks.DisplayAllCards(Players, dealer); System.Threading.Thread.Sleep(2000); //Set up player action foreach (Player player in Players) { Console.WriteLine("------------------------------------------------------------------------"); cardDecks.PlayerCardAction(player, dealer); } cardDecks.DealerCardAction(dealer); List <Player> RemovePlayers = new List <Player>(); foreach (Player player in Players) { if (dealer.Score >= player.Score) { Console.WriteLine($"{player.Name}, you lost {player.BetAmt} chips."); player.Chips -= player.BetAmt; if (player.Chips == 0) { RemovePlayers.Add(player); } } else { if (player.HasBlackJack == true) { player.BetAmt *= 1.5; Console.WriteLine($"Winner Winner Chicken Dinner {player.Name}! You had blackjack and win {player.BetAmt}! That is 1.5x your bet."); player.Chips += player.BetAmt; } else { Console.WriteLine($"{player.Name}, you won {player.BetAmt} chips."); player.Chips += player.BetAmt; } } } //Remove Bankrupt players foreach (Player player in RemovePlayers) { Console.WriteLine($"{player.Name}, you are bankrupt. We have kicked you out of the casino."); System.Threading.Thread.Sleep(1000); Players.Remove(player); } foreach (Player player in Players) { player.ClearPlayerData(player); } dealer.ClearDealerData(dealer); }
public Controller() { _dealer = new Dealer("James"); _deck = new CardDeck(); _deck.Shuffle(); }
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"); }
public static void Main(string[] args) { List <Player> players = new List <Player>(); List <Card> deckOfCards = new List <Card>(); //Display welcomescreen Display.DisplayWelcomeScreen(); //Get nr of players int nrOfPlayers = Player.PickNumberOfPlayers(); // Assign name to players players = Player.NamePlayers(nrOfPlayers); bool isPlayingGame = true; while (isPlayingGame) { //Create a new deck of cards deckOfCards = Card.CreateCardDeck(); //Create a Dealer object Dealer dealer = new Dealer(); int deal = 0; //Pick cards NewDeal(players, deckOfCards, dealer, deal); //Let players do their rounds. Player.HitOrStand(deckOfCards, players, dealer); //Let dealer play the round dealer.HitOrStand(deckOfCards, players); //Check and display winners DisplayWinners(players, nrOfPlayers, dealer); //Check if player wants to Quit or Continue while (true) { Console.WriteLine("Press Y to play another round or N to exit game."); string playerChoice = Console.ReadLine(); if (playerChoice.ToLower() == "y") //Play another round. { Player.ResetPlayer(players, nrOfPlayers); //Display welcomescreen Display.DisplayWelcomeScreen(); break; } else if (playerChoice.ToLower() == "n") //Time to quit game { Console.WriteLine("Thank you for playing Black Jack!"); isPlayingGame = false; System.Threading.Thread.Sleep(500); break; } } } }
static void Main(string[] args) { //init Deck deck = new Deck(); Dealer dealer = new Dealer(); Console.WriteLine("\t\t\tWelcome To BlackJack Game!!!\n\n"); Console.Write("How much money do you want to place? $"); double money = Convert.ToDouble(Console.ReadLine()); Console.WriteLine(); Player player = new Player(money); string wantContinue; do { Console.Clear(); deck.Shuffle(); player.ClearHandCards(); dealer.ClearHandCards(); Console.WriteLine("Your current blance: ${0}", player.Blance); // if a bet is not between 2-500 or the bet is more than balance, reprompt to the player again. do { if (player.Blance < 2) { Console.WriteLine("You don't have enough money! Minimum bet is $2\n"); Console.WriteLine("Thanks for playing! Goodbye!\n"); return; } Console.Write("How much would you like to bet? ($2 - $500) $"); player.Bet = Convert.ToDouble(Console.ReadLine()); if (player.Bet < 2 || player.Bet > 500) { Console.WriteLine("The general limits are from $2 to $500.\n"); } else if ((player.Bet > player.Blance) && (2 < player.Bet && player.Bet <= 500)) { Console.WriteLine("You don't have enough $$ to bet. Please lower down your bet :)\n"); } } while(player.Bet < 2 || player.Bet > 500 || (player.Bet > player.Blance) && (2 < player.Bet && player.Bet <= 500)); Console.WriteLine("Bet: ${0}\n", player.Bet); // player and dealer draw 2 cards from deck for (int i = 0; i < 2; i++) { player.DrawCard(deck.DealCard()); dealer.DrawCard(deck.DealCard()); } player.ShowCards(); // show one card to player dealer.ShowOneCard(); string hitOrStand; do { Console.WriteLine("\nHit(h) or Stand(s)"); hitOrStand = Console.ReadLine(); Console.WriteLine(); // if player type hit, player will draw a card from the deck. if (hitOrStand.ToLower() == "h") { player.DrawCard(deck.DealCard()); if (player.Score > 21) { PrintWhoWin("L", player, dealer); break; } else { player.ShowCards(); dealer.ShowOneCard(); } } // if player type stand, dealer will draw cards until the point is 17 or more. else if (hitOrStand.ToLower() == "s") { while (dealer.Score < 17) { dealer.DrawCard(deck.DealCard()); } if (dealer.Score > 21) { PrintWhoWin("W", player, dealer); } else { // Compare with player to see who's winner if (dealer.Score > player.Score) { PrintWhoWin("L", player, dealer); } else { if (dealer.Score == player.Score) { PrintWhoWin("T", player, dealer); } else { PrintWhoWin("W", player, dealer); } } } break; } else { Console.WriteLine("Invailed input!"); } } while (hitOrStand.ToLower() != "s"); Console.WriteLine("Wanna Continue? (y/n)"); wantContinue = Console.ReadLine(); if (wantContinue.ToLower() != "n" && wantContinue.ToLower() != "y") { Console.WriteLine("Invailed input!"); return; } } while (wantContinue.ToLower() != "n"); Console.WriteLine("Thanks for playing! Goodbye!\n"); }
public static void displayDealerScore(Dealer dealer) { Console.WriteLine("Dealer Score = {0}", dealer.getDealerScore()); }
public static int GameRound(Player player, Dealer dealer, Deck deck) { if (player.PlayerHand.Count == 0 || dealer.PlayerHand.Count == 0) { deck.FreshDeal(player, dealer); //If the first two draws are Aces, it prevents busting with a 22. deck.AcesFirstTwoCards(player, dealer); } Console.WriteLine($"Dealer's Cards: [{dealer.PlayerHand[0].Name}] [Hidden]"); Console.Write("Player's Cards: "); foreach (Cards card in player.PlayerHand) { Console.Write($"[{card.Name}] "); } Console.WriteLine($"Total: {player.SumCardValues()}"); if (player.SumCardValues() == 21) { Console.WriteLine("BLACKJACK! You won!!"); player.RoundScore += 1; return(0); } if (player.SumCardValues() > 21) { Console.WriteLine($"BUST! You lost with a total of {player.SumCardValues()}.."); dealer.RoundScore += 1; return(0); } Console.Write("Stay or Hit? (Enter 'S' or 'H'): "); char input = Game.CollectValidInput("Stay or Hit"); if (input == 'S') { if (dealer.didBustToSeventeen(dealer, deck) == true) { player.RoundScore += 1; dealer.WonOrLossOutput("dealerBust", dealer); return(0); } else { string outcome = Game.CompareHands(player, dealer); dealer.WonOrLossOutput(outcome, dealer); } } if (input == 'H') { Console.Clear(); deck.PlayerDraw(player); if (player.SumCardValues() > 21 && Ace.IsAceInHand(player)) { Ace.ReplaceAceValue(player); GameRound(player, dealer, deck); } else { GameRound(player, dealer, deck); } } return(0); }
private void GenerirajSlikiIgraci() { Random r = new Random(); int boja = r.Next(1, 4); int broj = r.Next(2, 14); dealer = new Dealer(upotrebeniKarti); Karta k = new Karta(dealer, boja, broj); dealer.dodajKarta(k); String pateka = "karti/"; pateka += broj.ToString() + "-" + boja.ToString() + ".png"; upotrebeniKarti.dodajKarta(broj, boja); pictureBox8.Image = Image.FromFile(pateka); pictureBox7.Image = Properties.Resources.zadna; label7.Text = "Збир на картите: " + dealer.PresmetajZbirKarti().ToString(); if (brojigraci == 1) { Player player = new Player(upotrebeniKarti, panel1, 1, this); player.ime = iminja[0]; player.vlog = vlogo[0]; textBox2.Text = iminja[0]; textBox8.Text = vlogo[0].ToString(); textBox2.Visible = true; textBox8.Visible = true; label111.Visible = true; label112.Visible = true; label111.Text = "Збир на карти: " + player.presmetajZbir().ToString(); igraci.Add(player); pictureBox1.Image = Properties.Resources.player; panel1.Controls.Add(pictureBox1); player.postaviSlika(); } else if (brojigraci == 2) { Player player = new Player(upotrebeniKarti, panel1,1, this); player.ime = iminja[0]; player.vlog = vlogo[0]; textBox8.Text = vlogo[0].ToString(); label112.Visible = true; Player player1 = new Player(upotrebeniKarti, panel2, 2, this); player1.ime = iminja[1]; player1.vlog = vlogo[1]; textBox9.Text = vlogo[1].ToString(); label212.Visible = true; pictureBox1.Image = Properties.Resources.player; pictureBox2.Image = Properties.Resources.player; textBox8.Visible = textBox9.Visible=true; label111.Visible = true; label111.Text = "Збир на карти: " + player.presmetajZbir().ToString(); label222.Visible = true; label222.Text = "Збир на карти: " + player1.presmetajZbir().ToString(); textBox2.Visible =textBox3.Visible= true; textBox2.Text = iminja[0]; textBox3.Text = iminja[1]; panel1.Controls.Add(pictureBox1); panel2.Controls.Add(pictureBox2); player.postaviSlika(); player1.postaviSlika(); igraci.Add(player); igraci.Add(player1); } else if (brojigraci == 3) { Player player = new Player(upotrebeniKarti, panel1, 1, this); player.ime = iminja[0]; player.vlog = vlogo[0]; textBox8.Text = vlogo[0].ToString() ; label112.Visible = true; Player player2 = new Player(upotrebeniKarti, panel2, 2, this); player2.ime = iminja[1]; player2.vlog = vlogo[1]; textBox9.Text = vlogo[1].ToString(); label212.Visible = true; Player player3 = new Player(upotrebeniKarti, panel3, 3, this); player3.ime = iminja[2]; player3.vlog = vlogo[2]; textBox10.Text = vlogo[2].ToString(); label312.Visible = true; textBox8.Visible = textBox9.Visible =textBox10.Visible= true; textBox2.Visible = textBox3.Visible = textBox4.Visible=true; pictureBox1.Image = Properties.Resources.player; pictureBox2.Image = Properties.Resources.player; pictureBox3.Image = Properties.Resources.player; label111.Visible = true; label111.Text = "Збир на карти: " + player.presmetajZbir().ToString(); label222.Visible = true; label222.Text = "Збир на карти: " + player2.presmetajZbir().ToString(); label333.Visible = true; label333.Text = "Збир на карти: " + player3.presmetajZbir().ToString(); textBox2.Text = iminja[0]; textBox3.Text = iminja[1]; textBox4.Text = iminja[2]; panel1.Controls.Add(pictureBox1); panel2.Controls.Add(pictureBox2); player.postaviSlika(); player2.postaviSlika(); player3.postaviSlika(); igraci.Add(player); igraci.Add(player2); igraci.Add(player3); } else if (brojigraci == 4) { Player player = new Player(upotrebeniKarti, panel1,1, this); player.ime = iminja[0]; player.vlog = vlogo[0]; textBox8.Text = vlogo[0].ToString(); label112.Visible = true; Player player1 = new Player(upotrebeniKarti, panel2, 2, this); player1.ime = iminja[1]; player1.vlog = vlogo[1]; textBox9.Text = vlogo[1].ToString(); label212.Visible = true; Player player2 = new Player(upotrebeniKarti, panel3, 3, this); player2.ime = iminja[2]; player2.vlog = vlogo[2]; textBox10.Text = vlogo[2].ToString(); label312.Visible = true; Player player3 = new Player(upotrebeniKarti, panel4, 4, this); player3.ime = iminja[3]; player3.vlog = vlogo[3]; textBox11.Text = vlogo[3].ToString(); label412.Visible = true; textBox8.Visible = textBox9.Visible = textBox10.Visible = textBox11.Visible=true; textBox2.Visible = textBox3.Visible = textBox4.Visible =textBox5.Visible= true; panel1.Controls.Add(pictureBox1); panel2.Controls.Add(pictureBox2); pictureBox1.Image = Properties.Resources.player; pictureBox2.Image = Properties.Resources.player; pictureBox3.Image = Properties.Resources.player; pictureBox4.Image = Properties.Resources.player; label111.Visible = true; label111.Text = "Збир на карти: " + player.presmetajZbir().ToString(); label222.Visible = true; label222.Text = "Збир на карти: " + player1.presmetajZbir().ToString(); label333.Visible = true; label333.Text = "Збир на карти: " + player2.presmetajZbir().ToString(); label444.Visible = true; label444.Text = "Збир на карти: " + player3.presmetajZbir().ToString(); textBox2.Text = iminja[0]; textBox3.Text = iminja[1]; textBox4.Text = iminja[2]; textBox5.Text = iminja[3]; player.postaviSlika(); player1.postaviSlika(); player2.postaviSlika(); player3.postaviSlika(); igraci.Add(player); igraci.Add(player1); igraci.Add(player2); igraci.Add(player3); } else if (brojigraci == 5) { Player player = new Player(upotrebeniKarti, panel1, 1, this); player.ime = iminja[0]; player.vlog = vlogo[0]; textBox8.Text = vlogo[0].ToString(); label112.Visible = true; Player player1 = new Player(upotrebeniKarti, panel2, 2, this); player1.ime = iminja[1]; player1.vlog = vlogo[1]; textBox9.Text = vlogo[1].ToString(); label212.Visible = true; Player player2 = new Player(upotrebeniKarti, panel3, 3, this); player2.ime = iminja[2]; player2.vlog = vlogo[2]; textBox10.Text = vlogo[2].ToString(); label312.Visible = true; Player player3 = new Player(upotrebeniKarti, panel4, 4,this); player3.ime = iminja[3]; player3.vlog = vlogo[3]; textBox11.Text = vlogo[3].ToString(); label412.Visible = true; Player player4 = new Player(upotrebeniKarti, panel5, 5, this); player4.ime = iminja[4]; player4.vlog = vlogo[4]; textBox12.Text = vlogo[4].ToString(); label512.Visible = true; textBox8.Visible = textBox9.Visible = textBox10.Visible = textBox11.Visible =textBox12.Visible= true; textBox2.Visible = textBox3.Visible = textBox4.Visible = textBox5.Visible =textBox6.Visible= true; pictureBox1.Image = Properties.Resources.player; pictureBox2.Image = Properties.Resources.player; pictureBox3.Image = Properties.Resources.player; pictureBox4.Image = Properties.Resources.player; pictureBox5.Image = Properties.Resources.player; label111.Visible = true; label111.Text = "Збир на карти: " + player.presmetajZbir().ToString(); label222.Visible = true; label222.Text = "Збир на карти: " + player1.presmetajZbir().ToString(); label333.Visible = true; label333.Text = "Збир на карти: " + player2.presmetajZbir().ToString(); label444.Visible = true; label444.Text = "Збир на карти: " + player3.presmetajZbir().ToString(); label555.Visible = true; label555.Text = "Збир на карти: " + player4.presmetajZbir().ToString(); textBox2.Text = iminja[0]; textBox3.Text = iminja[1]; textBox4.Text = iminja[2]; textBox5.Text = iminja[3]; textBox6.Text = iminja[4]; panel1.Controls.Add(pictureBox1); panel2.Controls.Add(pictureBox2); player.postaviSlika(); player1.postaviSlika(); player2.postaviSlika(); player3.postaviSlika(); player4.postaviSlika(); igraci.Add(player); igraci.Add(player1); igraci.Add(player2); igraci.Add(player3); igraci.Add(player4); } }
private void ShowDealerCard(bool hideOneCard = true) { Dealer.ShowPlayerCards(hideOneCard); }
public void ClearDealerData(Dealer dealer) { dealer.Hand.Clear(); dealer.Score = 0; }
public Player(Hand hand, Dealer dealer) { this.hand = hand; this.dealer = dealer; }
static void Main(string[] args) { var playGame = true; do { var Deck = new Dictionary<string, int>(); Deck = Deck.CreateDeck(); var dealer = new Dealer(); var user = new Player(); var gameOver = false; var cardBeingDealt = 0; //Deal the initial 2 cards to each player for (int i = 0; i < 2; i++) { dealer.DealCards(Deck, cardBeingDealt); if (dealer.CardDealt) { cardBeingDealt++; } } for (int i = 2; i < 4; i++) { user.DealCards(Deck, cardBeingDealt); if (user.CardDealt) { cardBeingDealt++; } } do { user.ShowHand(user.PlayerHand); if (dealer.PlayerScore < 21 && user.PlayerScore < 21) { dealer.DealerChoice(Deck, cardBeingDealt); if (dealer.CardDealt) { cardBeingDealt++; } user.HitOrStay(Deck, cardBeingDealt); if (user.CardDealt) { cardBeingDealt++; } else { gameOver =true; } } else { Console.WriteLine("Your Score is {0}",user.PlayerScore); Console.WriteLine("Dealer Score is {0}", dealer.PlayerScore); CheckWinner(user, dealer); //if(user.PlayerScore > dealer.PlayerScore) //{ // Console.WriteLine("Dealer Wins"); //} // else if(user.PlayerScore > 21 || dealer.PlayerScore > 21) //{ // Console.WriteLine("Bust"); //} //else if(dealer.PlayerScore > user.PlayerScore) //{ // Console.WriteLine("You Win"); //} //Console.WriteLine("Game Over!"); gameOver = true; } } while (!gameOver); playGame = false; } while (!playGame == false); //for (int i = 0; i < 52; i++) //{ // var newCard = Dealer.DealCards(Deck, i); // Console.WriteLine(newCard); //} Console.ReadLine(); }
/// <summary> /// Give all the players and the dealer one card each. /// </summary> /// <param name="playersList">List of players in game</param> /// <param name="deckOfCards">The current list of cards</param> /// <param name="dealer">The Dealer object</param> /// <param name="deal">What deal we are on</param> private static void NewDeal(List <Player> playersList, List <Card> deckOfCards, Dealer dealer, int deal) { Display.DisplayDealer(dealer, false); Display.DisplayPlayers(playersList.Count, playersList); for (deal = 0; deal < 2; deal++) { DrawPlayersCards(playersList.Count, playersList, deckOfCards, deal); DrawDealersCard(dealer, deal, deckOfCards); Display.DisplayPlayers(playersList.Count, playersList); } }
private static void StartGame() { Console.Clear(); dealer = new Dealer(); player = new Player(); List <Card> deckOfCards = startDeck.InitialiseDeck(); if (isPlayersTurn) { Console.WriteLine("Player to go first"); } else { Console.WriteLine("Dealer to go first"); } while (!player.HasStuck || !dealer.HasStuck) { if (isPlayersTurn) { Console.WriteLine("Would you like to stick or twist? (S/T)"); player.PlayerChoice = Console.ReadLine(); if (player.PlayerChoice.ToUpper() == "T") { Console.WriteLine("Player Twists"); Card dealtCard = takeCard.GetCard(deckOfCards); Console.WriteLine("Dealt card of: " + dealtCard.Value); player.AddCardToHand(dealtCard); deckOfCards = removeCard.RemoveCardFromDeck(deckOfCards); player.TotalScore = calculateScore.CalculateTotalCardScore(player.CardsInHand()); Console.WriteLine("Current Player Score is: " + player.TotalScore); if (bust.IsBust(player.TotalScore)) { Console.WriteLine("Player, you are bust :("); Console.ReadKey(); break; } } else { Console.WriteLine("Player Sticks"); if (!dealer.HasStuck) { Console.WriteLine("Dealer's turn"); } player.HasStuck = true; isPlayersTurn = !isPlayersTurn; } } else { Random random = new Random(); var i = random.Next(0, 10); Thread.Sleep(2500); var chance = 0.9; if (dealer.TotalScore >= 18) { chance = 5; } if (i > chance) { Console.WriteLine("Dealer Twists"); Card dealtCard = takeCard.GetCard(deckOfCards); Console.WriteLine("Dealt card of: " + dealtCard.Value); dealer.AddCardToHand(dealtCard); deckOfCards = removeCard.RemoveCardFromDeck(deckOfCards); dealer.TotalScore = calculateScore.CalculateTotalCardScore(dealer.CardsInHand()); Console.WriteLine("Current Dealer Score is: " + dealer.TotalScore); if (dealer.TotalScore == 21) { Console.WriteLine("Dealer Twists"); break; } if (bust.IsBust(dealer.TotalScore)) { Console.WriteLine("Dealer, you are bust :("); Console.ReadKey(); break; } } else { Console.WriteLine("Dealer Sticks"); if (!player.HasStuck) { Console.WriteLine("Player's turn"); } dealer.HasStuck = true; isPlayersTurn = !isPlayersTurn; } } } string result = checkWinner.CheckTheWinnerBetweenPlayerAndDealer(player.TotalScore, dealer.TotalScore); Console.WriteLine("------------------------------------"); Console.WriteLine("Result"); Console.WriteLine("The result of the game is " + result); switch (result) { case "Dealer": Dealer.GamesWon++; break; case "Player": Player.GamesWon++; break; } Console.WriteLine("Games won from dealer: " + dealer.ShowGamesWon()); Console.WriteLine("Games won from player: " + player.ShowGamesWon()); Console.WriteLine("------------------------------------"); Console.WriteLine("Would you like to play again? (Y/N)"); string choice = Console.ReadLine().ToUpper(); if (choice == "Y") { StartGame(); } }
public void Execute(Dealer dealer, Player player) { }