RainbowRoad1/Cgame logo

RainbowRoad1/Cgame

Free

一些用C编写的小游戏, 14行贪吃蛇 22行2048 22行俄罗斯方块 25行扫雷...以及各种小玩意

FreeFree tier
Type
Open Source

About RainbowRoad1/Cgame

Cgame is an open-source collection of classic games written in the C programming language, created by GitHub user RainbowRoad1. The project emphasizes achieving maximum functionality with minimal code, featuring implementations such as a 14-line snake game, 22-line Tetris, 22-line 2048, and 24-line minesweeper. All games use no third-party libraries and are intended to run on Windows, though code can be adapted for other platforms. The repository offers multiple versions per game—tiny (minimal code with formatting), chaos (extreme compression to 80 characters per line), color (with console colors), and others—making it a versatile resource for learning C programming, code golf, and game development. The project is licensed under MIT and is accompanied by tutorial videos on Bilibili.

Key Features

Minimal code implementations of classic games (snake, Tetris, 2048, minesweeper, maze, five-in-a-row, window games)
Multiple version variants per game: tiny (formatted minimal code), chaos (extreme line compression), color (console colors), and more
No third-party libraries required; pure C standard library
MIT licensed – free to use, modify, and distribute
Supported by Bilibili tutorial videos for several games
Includes both keyboard and mouse versions (e.g., minesweeper mouse version)
Code formatted with clang-format for readability

Pros & Cons

Pros
  • Extremely short game code (e.g., 5-line snake chaos version) demonstrates impressive compression
  • High playability despite minimal lines; games are fully functional
  • Educational resource: shows clever C tricks and optimizations
  • Multiple versions allow learners to compare different approaches (compact vs. readable)
  • Open source under MIT license with no third-party dependencies
Cons
  • Windows-only for direct execution (though code can be adapted)
  • Some code uses C99 features, which may not compile on older compilers without -std=c99 flag
  • Reported compilation warnings (e.g., _sleep() in Visual Studio) requiring manual workarounds
  • Repository organization described by author as 'messy' with multiple versions and outdated files
  • Author states they no longer wish to maintain the project; updates are unlikely

Best For

Learning and teaching C programming through game developmentExploring code golf and minimalistic coding techniquesCreating educational projects or demonstrationsPorting simple console games to other platformsBuilding a foundation for more complex game projects

FAQ

What games are included in Cgame?
The collection includes snake (GluttonousSnake), Tetris, 2048, minesweeper (MineSweeper), maze (Maze), five-in-a-row (Five-in-a-row), and window games (WindowGame).
What are the differences between the 'tiny', 'chaos', and 'color' versions?
The 'tiny' version is formatted minimal code with reasonable readability. The 'chaos' version compresses each line to at most 80 characters for extreme brevity. The 'color' version adds console colors to improve visual appeal.
Can I run these games on Linux or macOS?
The code is primarily designed for Windows (using Windows-specific functions like _sleep). However, the author notes it can be ported to other platforms as reference code. For example, a 31-line Linux version of minesweeper is included.
Is Cgame free to use?
Yes, the project is licensed under the MIT License, allowing free use, modification, and commercial use as long as the original author is credited.
Where can I find tutorials for these games?
The author has published video tutorials on Bilibili. Specific video links are provided in the repository's README for each game.