Advertisement
Guest User

Blackjack Thingy

a guest
Jul 30th, 2018
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.55 KB | None | 0 0
  1. package net.truttle.javagony.blackjack;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     /**
  7.     TRUTTLE1 PRESENTS:
  8.     Blackjack without any if, while, for, or switch commands!
  9.     AKA Blackjack in Javagony!
  10.     https://esolangs.org/wiki/Javagony
  11.     */
  12.     private static int[] playerCards = new int[5];
  13.     private static int[] dealerCards = new int[5];
  14.     private static int currentCard;
  15.     public static void main(String[] args)
  16.     {
  17.         playerCards[0] = (int)(Math.random()*11)+1;
  18.         playerCards[1] = (int)(Math.random()*10)+1;
  19.        
  20.         dealerCards[0] = (int)(Math.random()*11)+1;
  21.         dealerCards[1] = (int)(Math.random()*10)+1;
  22.         System.out.println("PLAYER'S CARDS: ");
  23.         displayPlayerCards(0);
  24.         System.out.println("");
  25.         System.out.println("PLAYER CARD SUM :: " + sumPlayerCards());
  26.         System.out.println("");
  27.         System.out.println("DEALER'S CARDS: ");
  28.         displayDealerCards(1);
  29.         currentCard = 2;
  30.         System.out.println("");
  31.         System.out.println("");
  32.         playersTurn();
  33.     }
  34.    
  35.     private static void displayPlayerCards(int card)
  36.     {
  37.         try
  38.         {
  39.             int z = 1/playerCards[card];
  40.             System.out.print(playerCards[card] + " :: ");
  41.             card++;
  42.             displayPlayerCards(card);
  43.         }
  44.         catch(Exception e)
  45.         {
  46.             return;
  47.         }
  48.     }
  49.  
  50.     private static void displayDealerCards(int card)
  51.     {
  52.         try
  53.         {
  54.             int z = 1/dealerCards[card];
  55.             System.out.print(dealerCards[card] + " :: ");
  56.             card++;
  57.             displayDealerCards(card);
  58.         }
  59.         catch(Exception e)
  60.         {
  61.             return;
  62.         }
  63.     }
  64.  
  65.     private static void playersTurn()
  66.     {
  67.         System.out.println("[H] - Hit :: [Anything Else] - Stay");
  68.         System.out.println("!!![H] must be a capital H!!!");
  69.         Scanner sc = new Scanner(System.in);
  70.         String x = sc.next();
  71.         int h = (int)x.charAt(0);
  72.         h -= 72;
  73.         try
  74.         {
  75.             int z = 1/h;
  76.             currentCard = 2;
  77.             dealersTurn();
  78.             return;
  79.         }
  80.         catch(Exception e)
  81.         {
  82.             playerCards[currentCard] = (int)(Math.random()*11)+1;
  83.             currentCard++;
  84.             System.out.println("PLAYER'S CARDS: ");
  85.             displayPlayerCards(0);
  86.             System.out.println("");
  87.  
  88.             try
  89.             {
  90.                 int bust = 1/checkForBust();
  91.                 try
  92.                 {
  93.                     int win = 1/(21-sumPlayerCards());
  94.                     try
  95.                     {
  96.                         int v = 1/(currentCard-5);
  97.                         playersTurn();
  98.                     }
  99.                     catch(Exception f)
  100.                     {
  101.                         System.out.println("You win! You drew 5 cards and didn't bust! :)");
  102.                         return;
  103.                     }
  104.                 }
  105.                 catch(Exception f)
  106.                 {
  107.                     System.out.println("You win! You have 21 points! :)");
  108.                     return;
  109.                 }
  110.             }
  111.             catch(Exception f)
  112.             {
  113.                 System.out.println("You busted! You lose! :(");
  114.                 return;
  115.             }
  116.  
  117.         }
  118.     }
  119.  
  120.     private static int checkForBust()
  121.     {
  122.         System.out.println("PLAYER CARD SUM :: " + sumPlayerCards());
  123.         try
  124.         {
  125.             int x = Math.addExact(sumPlayerCards(),Integer.MAX_VALUE-21);
  126.             return 1;
  127.         }
  128.         catch(Exception e) {return 0;}
  129.        
  130.     }
  131.     private static int sumPlayerCards()
  132.     {
  133.         return playerCards[0] + playerCards[1] + playerCards[2] + playerCards[3] + playerCards[4];
  134.     }
  135.    
  136.  
  137.     private static void dealersTurn()
  138.     {
  139.         int dealerAction = sumDealerCards()-17;
  140.         dealerAction*=-1;
  141.         try
  142.         {
  143.             int x = Math.addExact(dealerAction,Integer.MAX_VALUE);
  144.             System.out.println("DEALER :: Stay!");
  145.             showFinalResults();
  146.         }
  147.         catch(Exception e)
  148.         {
  149.             System.out.println("DEALER :: Hit!");
  150.             dealerCards[currentCard] = (int)(Math.random()*11)+1;
  151.             currentCard++;
  152.             System.out.println("");
  153.  
  154.             try
  155.             {
  156.                 int bust = 1/checkForBustDealer();
  157.                 try
  158.                 {
  159.                     int win = 1/(21-sumDealerCards());
  160.                     try
  161.                     {
  162.                         int v = 1/(currentCard-5);
  163.                         dealersTurn();
  164.                     }
  165.                     catch(Exception f)
  166.                     {
  167.                         System.out.println("You lose! The dealer drew 5 cards and didn't bust! :(");
  168.  
  169.                         System.out.println("");
  170.                         System.out.println("The dealer got: " + sumDealerCards());
  171.                         System.out.println("DEALER'S CARDS: ");
  172.                         displayDealerCards(0);
  173.                         System.out.println("");
  174.                         return;
  175.                     }
  176.                 }
  177.                 catch(Exception f)
  178.                 {
  179.                     System.out.println("You lose! The dealer got 21 points! :(");
  180.                     System.out.println("");
  181.                     System.out.println("The dealer got: " + sumDealerCards());
  182.                     System.out.println("DEALER'S CARDS: ");
  183.                     displayDealerCards(0);
  184.                     return;
  185.                 }
  186.             }
  187.             catch(Exception f)
  188.             {
  189.                 System.out.println("The dealer busted! You win! :)");
  190.  
  191.                 System.out.println("");
  192.                 System.out.println("The dealer got: " + sumDealerCards());
  193.                 System.out.println("DEALER'S CARDS: ");
  194.                 displayDealerCards(0);
  195.                 System.out.println("");
  196.                 return;
  197.             }
  198.         }
  199.     }
  200.     private static int checkForBustDealer()
  201.     {
  202.         try
  203.         {
  204.             int x = Math.addExact(sumDealerCards(),Integer.MAX_VALUE-21);
  205.             return 1;
  206.         }
  207.         catch(Exception e) {return 0;}
  208.        
  209.     }
  210.     private static int sumDealerCards()
  211.     {
  212.         return dealerCards[0] + dealerCards[1] + dealerCards[2] + dealerCards[3] + dealerCards[4];
  213.     }
  214.    
  215.     private static void showFinalResults()
  216.     {
  217.         System.out.println("");
  218.         System.out.println("FINAL RESULTS:");
  219.         System.out.println("The player got: " + sumPlayerCards());
  220.         System.out.println("PLAYER'S CARDS: ");
  221.         displayPlayerCards(0);
  222.         System.out.println("");
  223.         System.out.println("");
  224.         System.out.println("The dealer got: " + sumDealerCards());
  225.         System.out.println("DEALER'S CARDS: ");
  226.         displayDealerCards(0);
  227.         System.out.println("");
  228.        
  229.         int w = sumPlayerCards()-sumDealerCards();
  230.         try
  231.         {
  232.             int t = 1/w;
  233.             try
  234.             {
  235.                 int v = Math.addExact(w, Integer.MAX_VALUE);
  236.                 System.out.println("You lose! :(");
  237.             }
  238.             catch(Exception e)
  239.             {
  240.                 System.out.println("You win! :)");
  241.             }
  242.         }
  243.         catch(Exception e)
  244.         {
  245.             System.out.println("It was a tie!");
  246.         }
  247.     }
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement