Blackjack Game

A class project that grew from a console game into a Pygame interface.

Blackjack Game Demo

Project Overview

Blackjack began as a console assignment and later became a graphical Pygame version.

It supports betting, persistent balances, dealer logic, and standard blackjack payouts in both versions.

Technical Implementation

Key Features

Modular design with separate modules for card handling, game logic, and persistence
Pygame-based GUI with interactive buttons, animations, and visual card representation
Balance persistence between games using file I/O
Full implementation of standard blackjack rules (hit, stand, blackjack payouts)
Card display with Unicode symbols and suit colors
Responsive betting system with multiple bet sizes

Implementation Details

The game is structured around three key modules:

deck.py - Handles card operations (deck creation, shuffling, dealing, and scoring)
db.py - Manages persistence through simple file I/O to save player balance
game.py - Implements the Pygame GUI version with graphics and interaction

The GUI implementation uses Pygame to create an interactive experience with buttons, card visualization, and game state management. The design implements proper object-oriented principles with separate classes for Cards, Buttons, and Game logic.

Version Evolution

Original Console Version

Text-based interface with ASCII card representations
Command-line betting and gameplay
Basic game mechanics with accurate rules
File-based balance persistence

Enhanced GUI Version

Pygame graphical interface with interactive elements
Button-based betting and gameplay controls
Visual card representations with proper suit symbols
Animation effects and improved UX

Card Visualization

One of the most interesting aspects of the project was implementing card visualization in both versions. The text-based version uses ASCII art to represent cards:

def display_card(card): card_name, card_suit, _ = card if card_suit == 'Hearts': suit = '♥' elif card_suit == 'Diamonds': suit = '♦' # ... more code ... card_display = ''' ┌─────────┐ │{}{} │ │ │ │ {} │ │ │ │ {}{}│ └─────────┘'''.format(card_name, suit, suit, card_name, suit)

The GUI version implements cards as objects with visual rendering in Pygame:

class Card: def __init__(self, card_data, x, y, face_up=True): self.rank = card_data[0] self.suit = card_data[1] self.value = card_data[2] self.x = x self.y = y self.face_up = face_up def draw(self, surface): # Draw card background card_rect = pygame.Rect(self.x, self.y, CARD_WIDTH, CARD_HEIGHT) pygame.draw.rect(surface, WHITE, card_rect, border_radius=5) # ... more rendering code ...

Technologies Used

Python Pygame Object-Oriented Design File I/O Game Logic UI Design

Explore the Code

View on GitHub