Giter Club home page Giter Club logo

blackjack's Introduction

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

blackjack's People

Contributors

tcyang-md avatar

Watchers

 avatar

Forkers

enis8400

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.