A console-based Tetris game built with C# .NET 8 using Test-Driven Development (TDD).
- Classic Tetris gameplay with all 7 standard pieces (I, O, T, S, Z, J, L)
- Simple character-based UI using
[ ]blocks - 4-state rotation system for all pieces
- Line clearing with gravity (pieces drop down)
- Score tracking (100 points per line, with bonus for multiple lines)
- Fixed fall speed gameplay
- Clean architecture with separated game logic and console UI
TetrisGame/
├── src/
│ ├── TetrisGame.Core/ # Game logic (domain layer)
│ │ ├── Position.cs # Position record for coordinates
│ │ ├── TetrominoType.cs # Enum for 7 piece types
│ │ ├── Tetromino.cs # Tetromino class with rotation
│ │ └── GameBoard.cs # 20x10 game board with collision detection
│ └── TetrisGame.Console/ # Console UI layer
│ ├── ConsoleRenderer.cs # Display rendering
│ ├── GameEngine.cs # Main game loop and logic
│ └── Program.cs # Entry point
└── tests/
└── TetrisGame.Core.Tests/ # Unit tests for core logic
├── PositionTests.cs
├── TetrominoTests.cs
├── GameBoardTests.cs
└── LineClearingTests.cs
-
Navigate to the project directory:
cd C:\dev\AgentsGame
-
Run the game:
dotnet run --project src\TetrisGame.Console
- ← → : Move piece left/right
- ↓ : Soft drop (move down faster)
- SPACE : Rotate piece clockwise
- ESC : Quit game
Run all unit tests:
dotnet testRun tests with detailed output:
dotnet test --verbosity normal- The game board is 20 rows tall by 10 columns wide
- Pieces fall at a fixed speed
- When a horizontal line is completely filled, it is cleared
- Score 100 points per line cleared
- Multiple lines cleared at once give bonus points (e.g., 2 lines = 400 points)
- Game ends when a new piece cannot be placed at the top
The core game logic has comprehensive test coverage including:
- Position Tests: Coordinate movement and equality
- Tetromino Tests: All 7 piece types and their rotations
- GameBoard Tests: Grid management, piece placement, collision detection
- Line Clearing Tests: Complete line detection, removal, and gravity
All 26 unit tests pass successfully.
This project was built using Test-Driven Development (TDD):
- Write failing tests first (Red)
- Implement minimum code to make tests pass (Green)
- Refactor while keeping tests green (Refactor)
The clean separation between core game logic (TetrisGame.Core) and console UI (TetrisGame.Console) makes the code:
- Easy to test
- Easy to maintain
- Portable to other UI frameworks if needed
- Framework: .NET 8
- Language: C# 12 with modern features (records, pattern matching, etc.)
- Testing: xUnit
- Architecture: Clean architecture with domain-driven design principles
Potential improvements for the future:
- Variable fall speed based on level
- Preview of next piece
- Hold piece functionality
- High score persistence
- Sound effects
- Color-coded pieces
- T-spin detection
- Hard drop feature