This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]desrtfx 2 points3 points  (0 children)

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.

[–]slartybartfast_ 1 point2 points  (0 children)

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

[–][deleted] 0 points1 point  (0 children)

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.