Guest User

Untitled

a guest
Jun 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package blackjack;
  6. import java.util.*;
  7.  
  8. /**
  9. *
  10. * @author szetow
  11. */
  12. public class Game {
  13. public static int betAmt;
  14. public static int Amt = 300;
  15. public static int playerPoints;
  16. public static int playerPoints2;
  17. public static int dealerPoints;
  18. public static char ans = 'a';
  19. public static boolean play = true;
  20. private static int[] playerHand = new int[5];
  21. private static int[] playerHand2 = new int[5];
  22. private static int[] dealerHand = new int[5];
  23.  
  24. public void clearPoints() {
  25. playerPoints = 0;
  26. playerPoints2 = 0;
  27. dealerPoints = 0;
  28. }
  29.  
  30. public static void calcPoints(int hand[], int points,String who) {
  31. points = 0;
  32. for(int i = 0;i < 5; i++) {
  33. if(hand[i] == 1 && points < 11)
  34. {
  35. points += 11;
  36. } // ace and less than 11
  37. else if(hand[i] == 1 && points >= 11)
  38. {
  39. points += 1;
  40. } // ace and more than 11
  41. if(hand[i] >10) {
  42. points += 10;
  43. } // 11,12,13
  44. else if(hand[i] <= 10 && hand[i] != 1)
  45. {
  46. // System.out.println("less than 2)");
  47. points += hand[i];
  48. } //less and equal to 10 but NOT 1
  49. }
  50. System.out.println(points);
  51. if(who.equals("PlayerHand")) {
  52. playerPoints= points;
  53. System.out.println(playerPoints);
  54. }
  55. if(who.equals("DealerHand")) {
  56. dealerPoints= points;
  57. }
  58. }
  59. public static void calcResults() {
  60. if(dealerPoints > playerPoints) {
  61. System.out.println("Dealer beat you!");
  62. Amt-=betAmt;
  63. }
  64. if(playerPoints > dealerPoints) {
  65. System.out.println("You won!");
  66. Amt+=betAmt;
  67. }
  68. if(playerPoints == dealerPoints) {
  69. System.out.println("Draw");
  70. }
  71. if(Amt < 0) {
  72. System.out.println("You lost all your money. Game Over");
  73. System.exit(0);
  74. }
  75. }
  76. public static void checkBust() {
  77. /*Check Bust*/
  78. if(playerPoints >= 22) {
  79. System.out.println("You busted, go fuckyourself.");
  80. System.exit(0);
  81. }
  82. if(dealerPoints >= 22) {
  83. System.out.println("Dealer busted, go fuck himself.");
  84. System.exit(0);
  85. }
  86. }
  87.  
  88. public static void main(String[] args) {
  89. /*DEALS DECK*/
  90. Scanner keyboard = new Scanner(System.in);
  91. Scanner reader = new Scanner(System.in);
  92. Pile newGame = new Pile() ;
  93.  
  94.  
  95. newGame.makeDeck();
  96. while(play) {
  97. System.out.println("You have "+ Amt);
  98. System.out.println("How much do you wanna bet?");
  99. betAmt = reader.nextInt();
  100. while(betAmt > 0 && betAmt < Amt) {
  101. System.out.println("Your Bet must be more than 0 and less than your total Amount");
  102. betAmt = reader.nextInt();
  103. }
  104.  
  105. newGame.shuffle();
  106. System.out.println("You have :");
  107. newGame.remove(1,playerHand);
  108. newGame.getNextCard();
  109. newGame.remove(1,playerHand);
  110. newGame.getNextCard();
  111. System.out.print("Your total points is ") ;
  112. calcPoints(playerHand,playerPoints,"PlayerHand");
  113. while(ans!='s') {
  114. System.out.println("k, what u wanna do? h = hit, s = stand");
  115. ans = keyboard.nextLine().charAt(0);
  116. switch(ans) {
  117. case 'h' :
  118. newGame.remove(1,playerHand);
  119. newGame.getNextCard();
  120. System.out.print("Your total points is ") ;
  121. calcPoints(playerHand,playerPoints,"PlayerHand");
  122.  
  123. checkBust();
  124. if(playerPoints == 21) {
  125. ans = 's';//continues
  126. }
  127. }
  128. }
  129. /*calculate dealer*/
  130. //draws card
  131. System.out.println("Dealer has");
  132. newGame.remove(1,dealerHand);
  133. newGame.getNextCard();
  134. //System.out.println("HIDDEN");
  135. newGame.remove(1,dealerHand);
  136. newGame.getNextCard();
  137. System.out.println("Dealer has a total of ");
  138. calcPoints(dealerHand,dealerPoints,"DealerHand");
  139. //hits
  140. while(dealerPoints <= 16) {
  141. newGame.remove(1,dealerHand);
  142. newGame.getNextCard();
  143. System.out.println("He draws again! Total is");
  144. calcPoints(dealerHand,dealerPoints,"DealerHand");
  145. checkBust();
  146. }
  147. calcResults();
  148. //playerHand.displayAt(20);
  149. System.out.println("Do you wanna continue playing? (Y/N)");
  150. ans = keyboard.nextLine().charAt(0);
  151. if(ans == 'n') {
  152. play = false;
  153. }
  154. }
  155. }
  156. }
Add Comment
Please, Sign In to add comment