/// <summary> /// Method shows PlayersForm for editing players /// </summary> private void ChangePlayers() { // if the current game is not finished yet if (!game.CheckGameFinished()) { MessageBox.Show("Please wait until the end of current game!"); return; } PlayersForm form = new PlayersForm(); form.GameStats = statistics; form.ShowDialog(); statistics = form.GameStats; if (form.ChangedPlayer) { // set the list of active players for a new game game.SetPlayerList(form.GetActivePlayers()); // start new game NewGame(); } }
/// <summary> /// Method emulates the first moves of a dealer - if some player's got a blackjack on 2 cards, the dealer acts specially /// </summary> private void DealerFirstHit(int nPlayer) { // if the player hasn't got blackjack then do nothing if (game.CheckBlackJack(game.GetPlayer(nPlayer))) { game.SetPlayerState(nPlayer, PlayerState.BLACKJACK); // check the first dealer's card: if it has rank of 10 or 11 if (game.GetPlayer(nPlayer).PlayerHand.GetCardsNumber() == 2) { if (game.GetDealer().CountScore() >= 10) { // the dealer asks player if he/she wants to take the winning right away System.Windows.Forms.DialogResult res = System.Windows.Forms.MessageBox.Show( game.GetPlayer(nPlayer).Name + ", would you like to take your win 1-to-1 or keep playing " + "(in that case if the dealer doesn't have blackjack you'll win 3-to-2!)?", "Dealer's got 10, J, Q, K or A!", System.Windows.Forms.MessageBoxButtons.YesNo); // if player clicks Yes then he/she wins immediately if (res == System.Windows.Forms.DialogResult.Yes) { game.GetPlayer(nPlayer).PlayResult = PlayerResult.WIN; game.TotalLose += game.GetPlayer(nPlayer).Stake; } // otherwise dealer will wait until the end of a shuffle and we increment nDealerWaits else if (res == System.Windows.Forms.DialogResult.No) { nDealerWaits++; } // check if it was the last player and others are waiting if (!DealerShouldWait(nDealerWaits)) { DealerHit(); } // if game is finished if (game.CheckGameFinished()) { GameOver(); } cardtable.Invalidate(); } else { // if a player's got blackjack on 2 cards and the first dealer's card has rank less than 10 // the dealer loses immediately to this player (and if there's only one player we finish the game here) if (game.GetPlayersCount() == 1) { game.GameResults(nPlayer); GameOver(); } } } } }