SteelGolem

crappy blackjack v1

May 16th, 2021 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.65 KB | None | 0 0
  1. // crappy blackjack v1
  2.  
  3. // i can't get anywhere with more complicated projects
  4. // so i went all the way back to teenager-level shit
  5. // and made something as simple as possible
  6.  
  7. // use this simple example and make it better
  8.  
  9. // this is a simple blackjack game
  10.  
  11. // rules:
  12. // https://bicyclecards.com/how-to-play/blackjack/
  13.  
  14. // missing:
  15. // - card faces
  16. // - an actual deck
  17. // - ace rules
  18. // - dealer must stop at 17 or higher
  19. // - ties are no win/loss
  20. // - natural 21 is auto win unless dealer also has 21
  21. // - splitting pairs
  22. // - double down
  23. // - insurance
  24.  
  25. // crappy blackjack v2 https://pastebin.com/edit/LJb2URb5
  26.  
  27. using System;
  28.  
  29. class Program
  30. {
  31.     static Random random = new Random();
  32.  
  33.     static int dealer, player;
  34.  
  35.     static void Main(string[] args)
  36.     {
  37.         Console.WriteLine("welcome to blackjack for babies");
  38.         int money = 100;
  39.         while (money > 0)
  40.         {
  41.             // get bet before cards are dealt
  42.             Console.WriteLine("moneys: " + money);
  43.             int bet = 0;
  44.             while (!(bet > 0 && bet <= money))
  45.             {
  46.                 Console.Write("bet (1.." + money + ")? ");
  47.                 string input = Console.ReadLine();
  48.                 int.TryParse(input, out bet);
  49.             }
  50.             money -= bet;
  51.             // deal cards
  52.             dealer = deal_card() + deal_card();
  53.             player = deal_card() + deal_card();
  54.             show_cards();
  55.             // player hit/stand input
  56.             while (true)
  57.             {
  58.                 Console.Write("another card [y/n]? ");
  59.                 ConsoleKeyInfo key = Console.ReadKey();
  60.                 Console.WriteLine();
  61.                 if (key.Key == ConsoleKey.Y)
  62.                 {
  63.                     player += deal_card();
  64.                     show_cards();
  65.                     // finish if he busts
  66.                     if (player >= 21) break;
  67.                 }
  68.                 // finish if he's done
  69.                 if (key.Key == ConsoleKey.N) break;
  70.             }
  71.             // let player know if he busted
  72.             if (player > 21)
  73.                 Console.WriteLine("YOU BUSTED");
  74.             // do dealer's turn if he didn't bust
  75.             if (player < 21)
  76.             {
  77.                 // deal until win or bust
  78.                 while (dealer <= player)
  79.                 {
  80.                     dealer += deal_card();
  81.                     show_cards();
  82.                 }
  83.                 // let player know if dealer busted
  84.                 if (dealer > 21)
  85.                     Console.WriteLine("DEALER BUSTED");
  86.             }
  87.             // dealer busted, or player won
  88.             if (dealer > 21 || (player <= 21 && player > dealer))
  89.             {
  90.                 Console.WriteLine("you win " + (bet * 2) + " moneys!");
  91.                 money += bet * 2;
  92.             }
  93.             // player busted, or dealer won
  94.             if (player > 21 || (dealer <= 21 && player < dealer))
  95.             {
  96.                 Console.WriteLine("dealer wins.");
  97.             }
  98.             // no ties because the dealer always tries to get higher than player
  99.             if (player <= 21 && dealer <= 21 && player == dealer)
  100.             {
  101.                 Console.WriteLine("you tied the dealer. you get your bet back.");
  102.                 money += bet;
  103.             }
  104.         }
  105.         Console.WriteLine("you're all out of moneys. see ya next payday, sucker!");
  106.         Console.ReadKey(true);
  107.     }
  108.  
  109.     static void show_cards()
  110.     {
  111.         Console.WriteLine("dealer: " + dealer);
  112.         Console.WriteLine("you: " + player);
  113.     }
  114.  
  115.     static int deal_card()
  116.     {
  117.         return random.Next(1, 11);
  118.     }
  119. }
  120.  
Add Comment
Please, Sign In to add comment