Blackjack Game

A Python-based card game with both text-based and GUI interfaces

Blackjack Game Demo

Project Overview

Blackjack is an interactive card game implemented in Python that simulates the classic casino table game. The project began as a console-based application for a programming class and later evolved into a graphical version with Pygame.

Players can place bets, receive cards, and play against the dealer following standard blackjack rules. The game tracks your balance across sessions, provides realistic card visuals, and implements proper game logic including special rules like blackjack payouts.

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)
Sophisticated card display with Unicode symbols and proper suit coloring
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