Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // crappy blackjack v1
- // i can't get anywhere with more complicated projects
- // so i went all the way back to teenager-level shit
- // and made something as simple as possible
- // use this simple example and make it better
- // this is a simple blackjack game
- // rules:
- // https://bicyclecards.com/how-to-play/blackjack/
- // missing:
- // - card faces
- // - an actual deck
- // - ace rules
- // - dealer must stop at 17 or higher
- // - ties are no win/loss
- // - natural 21 is auto win unless dealer also has 21
- // - splitting pairs
- // - double down
- // - insurance
- // crappy blackjack v2 https://pastebin.com/edit/LJb2URb5
- using System;
- class Program
- {
- static Random random = new Random();
- static int dealer, player;
- static void Main(string[] args)
- {
- Console.WriteLine("welcome to blackjack for babies");
- int money = 100;
- while (money > 0)
- {
- // get bet before cards are dealt
- Console.WriteLine("moneys: " + money);
- int bet = 0;
- while (!(bet > 0 && bet <= money))
- {
- Console.Write("bet (1.." + money + ")? ");
- string input = Console.ReadLine();
- int.TryParse(input, out bet);
- }
- money -= bet;
- // deal cards
- dealer = deal_card() + deal_card();
- player = deal_card() + deal_card();
- show_cards();
- // player hit/stand input
- while (true)
- {
- Console.Write("another card [y/n]? ");
- ConsoleKeyInfo key = Console.ReadKey();
- Console.WriteLine();
- if (key.Key == ConsoleKey.Y)
- {
- player += deal_card();
- show_cards();
- // finish if he busts
- if (player >= 21) break;
- }
- // finish if he's done
- if (key.Key == ConsoleKey.N) break;
- }
- // let player know if he busted
- if (player > 21)
- Console.WriteLine("YOU BUSTED");
- // do dealer's turn if he didn't bust
- if (player < 21)
- {
- // deal until win or bust
- while (dealer <= player)
- {
- dealer += deal_card();
- show_cards();
- }
- // let player know if dealer busted
- if (dealer > 21)
- Console.WriteLine("DEALER BUSTED");
- }
- // dealer busted, or player won
- if (dealer > 21 || (player <= 21 && player > dealer))
- {
- Console.WriteLine("you win " + (bet * 2) + " moneys!");
- money += bet * 2;
- }
- // player busted, or dealer won
- if (player > 21 || (dealer <= 21 && player < dealer))
- {
- Console.WriteLine("dealer wins.");
- }
- // no ties because the dealer always tries to get higher than player
- if (player <= 21 && dealer <= 21 && player == dealer)
- {
- Console.WriteLine("you tied the dealer. you get your bet back.");
- money += bet;
- }
- }
- Console.WriteLine("you're all out of moneys. see ya next payday, sucker!");
- Console.ReadKey(true);
- }
- static void show_cards()
- {
- Console.WriteLine("dealer: " + dealer);
- Console.WriteLine("you: " + player);
- }
- static int deal_card()
- {
- return random.Next(1, 11);
- }
- }
Add Comment
Please, Sign In to add comment