Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package BlackDjeck;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import java.util.Scanner;
- public class BlackDjack {
- public static String cards(int rowIndex) {
- String[] rows = { "Two", "Three", "Four", "Five", "Six", "Seven",
- "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace" };
- String[] suit = { "Hearts", "Diamonds", "Clubs", "Spades" };
- Random randomS = new Random();
- int suitIndex = randomS.nextInt(4);
- String card = new String(rows[rowIndex] + " " + suit[suitIndex]);
- return card;
- };
- public static int cardValues(int cardIndex) {
- int cardValue;
- switch (cardIndex) {
- case 0:
- cardValue = 2;
- break;
- case 1:
- cardValue = 3;
- break;
- case 2:
- cardValue = 4;
- break;
- case 3:
- cardValue = 5;
- break;
- case 4:
- cardValue = 6;
- break;
- case 5:
- cardValue = 7;
- break;
- case 6:
- cardValue = 8;
- break;
- case 7:
- cardValue = 9;
- break;
- case 8:
- case 9:
- case 10:
- case 11:
- cardValue = 10;
- break;
- default:
- cardValue = 11;
- break;
- }
- return cardValue;
- };
- public static Integer sum(ArrayList<Integer> list) {
- Integer sum = 0;
- for (Integer i : list) {
- sum = sum + i;
- }
- if (sum > 21) {
- for (Integer i : list) {
- if (i == 11) {
- sum -= 10;
- }
- }
- }
- return sum;
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- ArrayList<String> dealerHand = new ArrayList<String>();
- ArrayList<Integer> dealerValue = new ArrayList<Integer>();
- ArrayList<String> playerHand = new ArrayList<String>();
- ArrayList<Integer> playerValue = new ArrayList<Integer>();
- for (int i = 0; i < 2; i++) {
- Random randomR = new Random();
- int dealerR = randomR.nextInt(13);
- dealerHand.add(cards(dealerR));
- dealerValue.add(cardValues(dealerR));
- }
- for (int i = 0; i < 2; i++) {
- Random randomR = new Random();
- int playerR = randomR.nextInt(13);
- playerHand.add(cards(playerR));
- playerValue.add(cardValues(playerR));
- }
- boolean noWinner = true;
- boolean playerWin = false; // When turn true Player win double the bet
- // money.(for Bet system from Lubo )
- boolean safeMoney = false; // Check first card of dealer is Ace and
- // player said that want safe money.(for Bet
- // system from Lubo )
- boolean draw = false; // When game finish draw -> boolean draw = true;
- // than money give back to player. No one
- // win(for Bet system from Lubo )
- boolean playerPass = false;
- int hand = 1;
- System.out.println("HAND " + hand); // Display hand and cards for test
- // must replace with print to console
- // from Sasho
- System.out.println(" Dealer HAND " + hand);// Display hand and cards
- // for test must replace
- // with print to console from Sasho
- System.out.println(dealerHand.get(0));// Display hand and cards for test
- // must replace with print to console
- // from Sasho
- System.out.println("HAND " + hand);// Display hand and cards for test
- // must replace with print to console from
- // Sasho
- System.out.println(" Player HAND " + hand);// Display hand and cards
- // for test must replace
- // with print to console from Sasho
- System.out.println(playerHand.get(0));// Display hand and cards for test
- // must replace with print to console
- // from Sasho
- if (dealerValue.get(0) == 11) {
- System.out
- .println("Do you whant safe hand (take half bet money back)");
- char[] a = input.nextLine().toCharArray();// Here you must set input
- // from Sasho.My input
- // is for test.
- if (a[0] == 'c') {
- safeMoney = true;
- }
- }
- while (noWinner) {
- hand++;
- if (hand > 2) {
- if (sum(dealerValue) <= 16) {
- System.out.println("Dealer got a new card");
- Random randomR = new Random();
- int dealerR = randomR.nextInt(13);
- dealerHand.add(cards(dealerR));
- dealerValue.add(cardValues(dealerR));
- // Print Dealer Hand
- //
- dealerHandPrint(dealerHand, dealerValue, hand);
- // Print Player Hand
- //
- playerHandPrint(playerHand, playerValue, hand);
- }
- if (sum(dealerValue) > 21) {
- playerWin = true;
- System.out.println("Delar Lose");
- break;
- }
- }
- if (hand > 2 && playerPass == true) {
- while (sum(dealerValue) <= 16) {
- hand++;
- System.out.println("Dealer got a new card");
- Random randomR = new Random();
- int dealerR = randomR.nextInt(13);
- dealerHand.add(cards(dealerR));
- dealerValue.add(cardValues(dealerR));
- // Print Dealer Hand
- //
- dealerHandPrint(dealerHand, dealerValue, hand);
- // Print Player Hand
- //
- playerHandPrint(playerHand, playerValue, hand);
- }
- if (sum(dealerValue) > 21) {
- System.out.println("Player WIN!!!!!!!!!!!!!!!!!");
- playerWin = true;
- break;
- }
- if (sum(playerValue) > sum(dealerValue)) {
- System.out.println("Player WIN!!!!!!!!!!!!!!!!!");
- playerWin = true;
- break;
- } else if (sum(playerValue) == sum(dealerValue)) {
- System.out.println("No Winers!!!!!!!!!!!!!!!!!!");
- draw = true;
- break;
- }
- else {
- System.out.println("Player LOSE!!!!!!!!!!!!!!!!");
- break;
- }
- }
- // Print Dealer Hand
- //
- System.out.println("HAND " + hand);// Display hand and cards for
- // test must replace with
- // print to console from Sasho
- dealerHandPrint(dealerHand, dealerValue, hand);
- // Print Player Hand
- //
- playerHandPrint(playerHand, playerValue, hand);
- if (sum(dealerValue) == 21) {
- System.out.println("Delar WIN!!!!!!!!!!!!!!!!!!!!");
- break;
- }
- if (sum(playerValue) == 21) {
- System.out.println("Player WIN!!!!!!!!!!!!!!!!!!1");
- playerWin = true;
- break;
- }
- if (sum(playerValue) > 21) {
- System.out.println("!!!! Player LOSE!!!!!!");
- break;
- }
- System.out.println("Do you whant card");
- char[] str = input.nextLine().toCharArray();
- if (str[0] == 'c') {
- System.out.println("you got a card");
- Random randomR = new Random();
- int playerR = randomR.nextInt(13);
- playerHand.add(cards(playerR));
- playerValue.add(cardValues(playerR));
- } else {
- playerPass = true;
- }
- }
- ;
- }
- private static void playerHandPrint(ArrayList<String> playerHand,
- ArrayList<Integer> playerValue, int hand) {
- System.out.println(" Player HAND " + hand);// Display hand and cards
- // for test must replace
- // with print to console from Sasho
- System.out.println(sum(playerValue));// Display hand and cards for test
- // must replace with print to console
- // from Sasho
- for (String item : playerHand) {// Display hand and cards for test must
- // replace with print to console from Sasho
- System.out.println(item);// Display hand and cards for test must
- // replace with print to console from Sasho
- }
- }
- private static void dealerHandPrint(ArrayList<String> dealerHand,
- ArrayList<Integer> dealerValue, int hand) {
- System.out.println(" Dealer HAND " + hand);// Display hand and cards
- // for test must replace
- // with print to console from Sasho
- System.out.println(sum(dealerValue));// Display hand and cards for test
- // must replace with print to console
- // from Sasho
- for (String item : dealerHand) {// Display hand and cards for test must
- // replace with print to console from Sasho
- System.out.println(item);// Display hand and cards for test must
- // replace with print to console from Sasho
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement