Skip to content

Classic game of Blackjack made in Java using JOptionPane as GUI and ArrayLists to simulate deck of cards

Notifications You must be signed in to change notification settings

tcyang-md/Blackjack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Blackjack 🃏

I created Blackjack in Java using JOptionPane as my GUI and an ArrayList of card objects to simulate a deck of cards. The program follows the traditional rules of Blackjack where the dealer must draw to 16 and stand on all 17s.

Instructions

$ java card and the game should appear as a JOptionPane pop up and you will be able to play. Have fun!

Breakdown

import java.util.ArrayList;
import java.util.Random;
import javax.swing.JOptionPane;

public class Card {
  
  // constructors for the card object called by buildDeck
  public Card()
  public Card(String num, String suit)
  
  // checks if one card is exactly the same as another card (suit and value)
  @Override
  public boolean equals(Object newCard)
  
  // creates a unique deck of cards and shuffles them using a Fisher-Yates shuffling algorithm where a loop iterates 
  // through every index in the ArrayList of the deck, swapping the current card with another random card.
  public static void buildDeck(ArrayList<Card> deck)
  
  // deals 4 cards, 2 to player, 2 to dealer
  public static void initialDeal(ArrayList<Card> deck, ArrayList<Card> playerHand, ArrayList<Card> dealerHand)
  
  // helper methods
  public static void dealOne(ArrayList<Card> deck, ArrayList<Card> hand)
  public static int getHandValue(ArrayList<Card> hand)
  public static boolean checkBust(ArrayList<Card> hand)
  public static boolean dealerTurn(ArrayList<Card> deck, ArrayList<Card> hand)
  public static int whoWins(ArrayList<Card> playerHand, ArrayList<Card> dealerHand)
  public static String displayCard(ArrayList<Card> hand)
  public static String displayHand(ArrayList<Card> hand)
  public static void clearHands(ArrayList<Card> playerHand, ArrayList<Card> dealerHand)
  
  // using JOptionPane, display game with hit and stay options
  public static void main(String[] args)
}

Demo Example

first display playerbust playerbeatsdealer dealerbeatsplayer dealerbust

About

Classic game of Blackjack made in Java using JOptionPane as GUI and ArrayLists to simulate deck of cards

Topics

Resources

Stars

Watchers

Forks

Languages