๐ Terminal Snake Game in Go
A high-performance, terminal-based Snake game implementation written in Go, showcasing advanced concurrency patterns, data structures, and clean architecture principles.
Project Overview
This Terminal Snake Game is a sophisticated implementation written in Go that demonstrates mastery of concurrent programming, efficient data structures, and clean architecture principles. The game features real-time terminal manipulation, non-blocking input handling, and smooth gameplay mechanics.
Built with performance and maintainability in mind, the project showcases advanced Go concepts including goroutines for concurrent input processing, channels for safe communication, and efficient data structures like linked lists for optimal snake body management.
The game supports multiple difficulty levels with configurable board sizes and speeds, responsive controls, and cross-platform compatibility across macOS, Linux, and Windows terminals.
Key Features
Performance & Concurrency
- Goroutines & Channels: Non-blocking input handling with safe concurrent communication
- Efficient Data Structures: Linked list implementation for O(1) head/tail operations
- Real-time Processing: Game loop with precise timing and input processing
- Memory Optimization: ~2MB baseline memory footprint with minimal allocations
Gameplay & UI
- Multiple Difficulty Levels: Three board sizes (Small, Medium, Large) and configurable speeds
- Responsive Controls: Vim-style (hjkl) and WASD movement with direction locking
- Terminal Programming: Raw terminal manipulation and ANSI escape sequences
- Cross-platform: Works seamlessly on macOS, Linux, and Windows
Technical Implementation
Architecture & Design Patterns
1. Concurrent Input Processing
ย ย defer wg.Done()
ย ย input.ListenForInput(inputChannel, s, stopChannel)
}()
2. Efficient Snake Body Management
3. Channel-based Communication
Project Structure
Performance Metrics
Gameplay Mechanics
Controls
Game Rules
- Snake grows when consuming fruit (F)
- Game ends on wall or self-collision
- Score increases with each fruit consumed
- Fruit spawns randomly in unoccupied positions
- Direction locking prevents reverse movement
- Configurable board sizes and speeds
Installation & Usage
Quick Start
Build & Deploy
Learning Outcomes
This project demonstrates mastery of several advanced Go concepts and software engineering principles:
Go Fundamentals
- Goroutines & concurrency patterns
- Channel communication
- Error handling patterns
- Memory management
- Interface design
Software Engineering
- Clean architecture principles
- Modular design patterns
- Resource management
- Cross-platform compatibility
- Performance optimization
Game Screenshots
[m] - Medium (40x20) ๐ป
[l] - Large (80x40) ๐ฅ๏ธ
[m] - Medium (100ms) ๐ถ
[l] - Fast (50ms) ๐
โ Move Down: S or J
โ Move Left: A or H
โ Move Right: D or L
๐ช Quit Game: Q or ESC