r/java•
Momifier

Black jack help.

I am creating blackjack but I don't know what to do next... here is my code. (i'm using eclipse)

package Blackjack;

public class BlackJack {

public static void main (String[]args){
	
	card(5);
		
}

private static void suit(int s){
	String suitstring = null;
	
	switch (s){
	case 1: suitstring="spade";
	break;
	case 2: suitstring="club";
	break;
	case 3: suitstring ="heart";
	break;
	case 4: suitstring="diamond";
	break;
	}


private static void card(int c){
	String cardstring = null;

	switch (c){
	case 1: cardstring="Ace";
	break;
	case 2: cardstring="Two";
	break;
	case 3: cardstring="Three";
	break;
	case 4: cardstring="Four";
	break;
	case 5: cardstring="Five";
	break;
	case 6: cardstring="Six";
	break;
	case 7: cardstring="Seven";
	break;
	case 8: cardstring="Eight";
	break;
	case 9: cardstring="Nine";
	break;
	case 10: cardstring="Ten";
	break;
	case 11: cardstring="Jack";
	break;
	case 12: cardstring="Queen";
	break;
	case 13: cardstring="king";
	break;
	
	}
	
}

}

Posted Oct 6, 2014, 4:47 PM UTC

03
desrtfx•

First: this question is better posted in r/Javahelp, but without a clear question you would not get much help there either.

Think about how Black Jack is played:

  1. There is a shoe of (x) decks of cards, each deck consisting of 52 cards.
  2. Each player gets dealt a single card
  3. Each player gets dealt another card
  4. Each player can decide to:
    • get another card
    • stay
    • split (under certain conditions)
  5. Once all players stay, the scores are compared to determine the winner.

With the rules out of the way, let's think about how to implement them:

  1. First, you should split your game in different classes:
    • a class for a single card (suit, value) - probably using enums
    • a class for a deck of cards (holding 52 cards as per standard poker rules, ability to shuffle)
    • a class for a shoe (consisting of x decks, ability to shuffle through all x decks, can deal single cards that are removed from the shoe and passed as return value from dealing)
    • a player class that can hold up to 2 hands (because of splitting) - conatins methods to check and return the score
    • a game class that ties all the above together - here would be the main method that runs the game loop.
  2. Now think about a way how to join all of the above with the rules that are defined.

You will need some arrays, loops, conditionals.

3
slartybartfast_•

I would use enums as this would avoid nulls and and unneeded switch statements.

2
NotCohen•

now you need to use some logical operations.

if card() == 10 and card() == 11 then:
print "black jack".
else:
"bust!"

Ans so on for draw and splits etc.

1
[deleted]•

[deleted]

1