C#,Gaming,Architecture

Building a Desktop Tetris Game with C# and WPF

Implemented a complete desktop Tetris experience in C# and WPF, combining object-oriented block modeling, collision-aware movement, line clearing, scoring, progressive speed, hold and preview systems, and a responsive keyboard-driven interface.

C#.NET 8WPFGame DevelopmentState Management
WPFFramework
7Tetromino Types
10 × 22Board Size
.NET 8Target

The Problem

A falling-block game must coordinate a timed game loop, keyboard input, collision detection, rotation, scoring, rendering, and game-over rules without allowing the interface and domain logic to become inseparable.

Each tetromino also requires multiple rotation states and a consistent way to translate local tile positions into board coordinates. Invalid movement must be reversed safely while completed rows are removed and the remaining grid collapses correctly.

Quick Summary

TL;DR

  • Problem: Real-time input, timed movement, collision rules, and rendering had to remain synchronized
  • Solution: Separated blocks, the game grid, queue, game state, and WPF presentation into focused classes
  • Impact: Delivered a playable desktop game with hold, preview, ghost-block, scoring, and progressive difficulty

Technical Leadership

  • Modeled all seven tetrominoes through a shared abstract Block type with specialized rotation data.
  • Kept authoritative gameplay rules inside GameState instead of embedding them in WPF event handlers.
  • Created a grid abstraction responsible for boundaries, occupied cells, completed rows, and row movement.
  • Coordinated an asynchronous game loop with immediate keyboard input and deterministic redraws.
  • Studied and adapted a guided reference implementation while maintaining a readable project structure and documenting the source material.

What I Did

The design separates what the game means from how WPF displays it.

GameState owns the active block, queue, held block, score, collision rules, placement, and game-over evaluation. MainWindow translates that state into images and connects player input to explicit game actions.

  • Represented rotations as arrays of tile coordinates for each tetromino.
  • Implemented reversible movement and rotation when a proposed position does not fit the grid.
  • Added hard drop, ghost-block projection, held-block swapping, and next-block preview.
  • Cleared complete rows from the bottom upward and shifted remaining rows into the emptied space.
  • Increased game speed as the score rises while enforcing a minimum delay.
  • Added replay behavior that creates a clean GameState after game over.

Testing and Validation

  • Exercised movement and rotation at the left, right, and bottom boundaries.
  • Verified blocks cannot overlap occupied grid cells.
  • Confirmed full rows clear and higher rows move down correctly.
  • Validated hold restrictions, hard-drop distance, score updates, and game-over behavior.
  • Checked the redraw cycle after timed and keyboard-driven state changes.

Outcome

  • Delivered a complete keyboard-controlled Tetris experience for Windows.
  • Demonstrated practical use of inheritance, encapsulation, collections, and two-dimensional arrays.
  • Kept gameplay rules independently understandable from WPF rendering code.
  • Implemented several polished gameplay features beyond basic falling-block movement.