示例#1
0
 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");
             }
         }
     }
 }
示例#2
0
        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);
        }
示例#3
0
        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");
        }
示例#4
0
 public Player()
 {
     Hand = CardDeck.TakeCard() + CardDeck.TakeCard();
 }
示例#5
0
        public void Reset()
        {
            CardDeck temp = new CardDeck();

            Deck = temp.Deck;
        }
示例#6
0
 public Controller()
 {
     _dealer = new Dealer("James");
     _deck   = new CardDeck();
     _deck.Shuffle();
 }