A collection of comprehensive refactoring tutorials that teach software engineering principles through practical, hands-on game development. Each project takes a working but poorly-structured game and systematically transforms it into a production-ready, object-oriented application.
Refactor Classes is an educational programming curriculum that teaches software engineering through progressive refactoring. Instead of building projects from scratch, you'll learn by improving existing code—just like real-world software development.
- Real-world skill: Most professional programming is maintaining and improving existing code
- Learn by comparison: See "before" and "after" side-by-side
- Incremental learning: Each step builds on the previous one
- Working code always: The game remains playable after every refactoring step
- Practical application: Learn concepts in context, not in isolation
10 steps | Beginner to Advanced | Python + Pygame
Transform a beginner's chess game into a production-ready application with AI.
What You'll Learn:
- Eliminating anti-patterns (
exec(), global state, magic numbers) - Object-oriented programming (classes, inheritance, polymorphism)
- Design patterns (Command, Observer, Factory, Strategy)
- AI algorithms (Minimax with alpha-beta pruning)
- Software architecture (Model-View separation, dependency injection)
Technologies: Python 3.10+, Pygame, Turtle Graphics
11 steps | Beginner to Advanced | Python + Pygame + NumPy
Transform a monolithic Tetris game into a clean, production-ready application.
What You'll Learn:
- Code cleanup and configuration management
- Removing global state and dependency injection
- Game loop architecture (Input → Update → Draw)
- Object-oriented design (GameState, Piece, Board classes)
- Renderer abstraction and separation of concerns
- Input handling and timing systems (DAS/ARR, delta time)
- Advanced game features (ghost piece, hold system, T-spins, combos)
- Production polish (menus, sound, particles, AI, high scores)
Technologies: Python 3.10+, Pygame, NumPy
- Learn what "good code" looks like and why it matters
- See the difference between working code and professional code
- Build confidence by improving real projects
- Master object-oriented programming and design patterns
- Learn architectural thinking and separation of concerns
- Practice refactoring techniques used in industry
- See textbook concepts applied to real projects
- Bridge the gap between theory and practice
- Build portfolio-worthy projects
- Fill gaps in software engineering fundamentals
- Learn industry best practices
- Develop professional coding habits
- Python 3.10 or higher
- Basic Python knowledge (variables, functions, loops, conditionals)
- Willingness to learn and experiment
-
Clone or download this repository
git clone <repository-url> cd "Refactor Classes"
-
Choose a project (Chess or Tetris)
cd Chess # or cd Tetris
-
Set up virtual environment
python3 -m venv chess_env # or tetris_env source chess_env/bin/activate # On Windows: chess_env\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Run any step
./play.sh 1 # Run step 1 ./play.sh 10 # Run step 10 (final version)
-
Start with Chess if you:
- Are newer to programming
- Want to learn design patterns
- Are interested in AI algorithms
-
Start with Tetris if you:
- Have some OOP experience
- Want to learn game architecture
- Are interested in game feel and polish
-
Do both! The projects complement each other:
- Chess focuses on AI and complex game logic
- Tetris focuses on architecture and production polish
- Read the README for your chosen project
- Run Step 0 to see the original code
- Read the documentation for Step 1 in
refactor_steps_docs/ - Try refactoring yourself before looking at the solution
- Compare your solution with the provided step file
- Run and test the refactored code
- Repeat for each step
Refactor Classes/
├── README.md # This file
├── Chess/ # Chess refactoring tutorial
│ ├── README.md # Chess-specific documentation
│ ├── requirements.txt # Python dependencies
│ ├── play.sh # Launcher script
│ ├── code/ # All 10 step files
│ ├── refactor_steps_docs/ # Step-by-step guides
│ ├── fixes_docs/ # Bug fixes and technical notes
│ └── tests/ # Test suite
└── Tetris/ # Tetris refactoring tutorial
├── README.md # Tetris-specific documentation
├── requirements.txt # Python dependencies
├── play.sh # Launcher script
├── code/ # All 11 step files
└── refactor_steps_docs/ # Step-by-step guides
- Python 3.10+: Modern Python with type hints
- Pygame: 2D game development library
- NumPy: Numerical computing (Tetris only)
- Turtle Graphics: Simple graphics (Chess early steps)
By completing these tutorials, you will master:
- ✅ Code quality and readability
- ✅ DRY (Don't Repeat Yourself)
- ✅ SOLID principles
- ✅ Separation of concerns
- ✅ Dependency injection
- ✅ Classes and objects
- ✅ Inheritance and polymorphism
- ✅ Encapsulation and abstraction
- ✅ Composition over inheritance
- ✅ Factory pattern
- ✅ Strategy pattern
- ✅ Command pattern
- ✅ Observer pattern
- ✅ State machine pattern
- ✅ Game loop architecture
- ✅ Input handling
- ✅ Collision detection
- ✅ Rendering systems
- ✅ AI implementation
- ✅ Sound and visual effects
This is an educational project. Feel free to use, modify, and learn from the code.
This is a teaching resource. If you find bugs or have suggestions for improvements, please feel free to contribute!
Created as a comprehensive resource for learning software engineering through practical refactoring exercises.
This project wqas insprieed by the 'commonLuke' YouTuibe channel and his attempts at learning to code in Python (https://www.youtube.com/@commonLuke). Both the original Chess and Tetris game code are his. All refactors are my own.
Happy Refactoring! 🚀