Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package blackjack;
- import java.util.*;
- /**
- *
- * @author szetow
- */
- public class Game {
- public static int betAmt;
- public static int Amt = 300;
- public static int playerPoints;
- public static int playerPoints2;
- public static int dealerPoints;
- public static char ans = 'a';
- public static boolean play = true;
- private static int[] playerHand = new int[5];
- private static int[] playerHand2 = new int[5];
- private static int[] dealerHand = new int[5];
- public void clearPoints() {
- playerPoints = 0;
- playerPoints2 = 0;
- dealerPoints = 0;
- }
- public static void calcPoints(int hand[], int points,String who) {
- points = 0;
- for(int i = 0;i < 5; i++) {
- if(hand[i] == 1 && points < 11)
- {
- points += 11;
- } // ace and less than 11
- else if(hand[i] == 1 && points >= 11)
- {
- points += 1;
- } // ace and more than 11
- if(hand[i] >10) {
- points += 10;
- } // 11,12,13
- else if(hand[i] <= 10 && hand[i] != 1)
- {
- // System.out.println("less than 2)");
- points += hand[i];
- } //less and equal to 10 but NOT 1
- }
- System.out.println(points);
- if(who.equals("PlayerHand")) {
- playerPoints= points;
- System.out.println(playerPoints);
- }
- if(who.equals("DealerHand")) {
- dealerPoints= points;
- }
- }
- public static void calcResults() {
- if(dealerPoints > playerPoints) {
- System.out.println("Dealer beat you!");
- Amt-=betAmt;
- }
- if(playerPoints > dealerPoints) {
- System.out.println("You won!");
- Amt+=betAmt;
- }
- if(playerPoints == dealerPoints) {
- System.out.println("Draw");
- }
- if(Amt < 0) {
- System.out.println("You lost all your money. Game Over");
- System.exit(0);
- }
- }
- public static void checkBust() {
- /*Check Bust*/
- if(playerPoints >= 22) {
- System.out.println("You busted, go fuckyourself.");
- System.exit(0);
- }
- if(dealerPoints >= 22) {
- System.out.println("Dealer busted, go fuck himself.");
- System.exit(0);
- }
- }
- public static void main(String[] args) {
- /*DEALS DECK*/
- Scanner keyboard = new Scanner(System.in);
- Scanner reader = new Scanner(System.in);
- Pile newGame = new Pile() ;
- newGame.makeDeck();
- while(play) {
- System.out.println("You have "+ Amt);
- System.out.println("How much do you wanna bet?");
- betAmt = reader.nextInt();
- while(betAmt > 0 && betAmt < Amt) {
- System.out.println("Your Bet must be more than 0 and less than your total Amount");
- betAmt = reader.nextInt();
- }
- newGame.shuffle();
- System.out.println("You have :");
- newGame.remove(1,playerHand);
- newGame.getNextCard();
- newGame.remove(1,playerHand);
- newGame.getNextCard();
- System.out.print("Your total points is ") ;
- calcPoints(playerHand,playerPoints,"PlayerHand");
- while(ans!='s') {
- System.out.println("k, what u wanna do? h = hit, s = stand");
- ans = keyboard.nextLine().charAt(0);
- switch(ans) {
- case 'h' :
- newGame.remove(1,playerHand);
- newGame.getNextCard();
- System.out.print("Your total points is ") ;
- calcPoints(playerHand,playerPoints,"PlayerHand");
- checkBust();
- if(playerPoints == 21) {
- ans = 's';//continues
- }
- }
- }
- /*calculate dealer*/
- //draws card
- System.out.println("Dealer has");
- newGame.remove(1,dealerHand);
- newGame.getNextCard();
- //System.out.println("HIDDEN");
- newGame.remove(1,dealerHand);
- newGame.getNextCard();
- System.out.println("Dealer has a total of ");
- calcPoints(dealerHand,dealerPoints,"DealerHand");
- //hits
- while(dealerPoints <= 16) {
- newGame.remove(1,dealerHand);
- newGame.getNextCard();
- System.out.println("He draws again! Total is");
- calcPoints(dealerHand,dealerPoints,"DealerHand");
- checkBust();
- }
- calcResults();
- //playerHand.displayAt(20);
- System.out.println("Do you wanna continue playing? (Y/N)");
- ans = keyboard.nextLine().charAt(0);
- if(ans == 'n') {
- play = false;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment