示例#1
0
        static void Main(string[] args)
        {
            Deck_of_cards desk = new Deck_of_cards();

            desk.update();
            Player player            = new Player();
            Player dealer            = new Player();
            bool   checker_of_points = true;


            while (true)
            {
                player.clean_points();
                dealer.clean_points();
                desk.number_of_cards_checker();
                players_turn(ref checker_of_points, player, desk);
                dealers_turn(ref checker_of_points, dealer, desk);
                compare_points(checker_of_points, player, dealer);

                Console.WriteLine("\nPrint c - continue, f - finish: ");
                if (Console.ReadLine() != "c")
                {
                    break;
                }
                Console.WriteLine("\n");
            }

            //desk.print();
        }
示例#2
0
        static void players_turn(ref bool checker_of_points, Player player, Deck_of_cards desk)
        {
            checker_of_points = true;


            while (true)
            {
                Console.WriteLine("Print h - hit, s - stand: ");
                if (Console.ReadLine() == "h")
                {
                    if (player.take_card(desk, true))
                    {
                        player.print_points();
                        Console.WriteLine("\nYou lost\n");
                        checker_of_points = false;
                        break;
                    }
                    player.print_points();
                }
                else
                {
                    break;
                }
            }
        }
示例#3
0
 static void dealers_turn(ref bool checker_of_points, Player dealer, Deck_of_cards desk)
 {
     if (checker_of_points)
     {
         Console.WriteLine("\nDealer playes\n");
         while (dealer.get_points() < 17)
         {
             if (dealer.take_card(desk, false))
             {
                 dealer.print_points();
                 Console.WriteLine("\ndealer lost\n");
                 checker_of_points = false;
                 break;
             }
             dealer.print_points();
         }
     }
 }
示例#4
0
        public bool take_card(Deck_of_cards desk, bool identify)
        {
            Random random_card = new Random();
            int    new_card    = random_card.Next(desk.get_number_of_cards());
            int    add_points  = desk.get_card(new_card);


            if (add_points == 11)
            {
                if (identify)
                {
                    Console.WriteLine("Choose 1 or 11 points: ");
                    if (Console.ReadLine() == "1")
                    {
                        add_points = 1;
                    }
                }
                else
                {
                    auto_11_choser = true;
                    if ((points + add_points) > 21)
                    {
                        add_points = 1;
                    }
                }
            }

            Console.WriteLine("Added points: " + add_points);
            points += add_points;

            if (auto_11_choser && points > 21)
            {
                points -= 10;
                Console.WriteLine("11 back to 1");
                auto_11_choser = false;
            }

            if (points > 21)
            {
                return(true);
            }
            return(false);
        }