π Hey DEV Community!
I recently built CodleC β a Wordle-inspired game in pure C that runs in your terminal with ANSI colors, hints, and JSON persistence. Hereβs how I did it!
What is CodleC?
A 5-letter word-guessing game where:
π© Green = Correct letter & position.
π¨ Yellow = Correct letter, wrong position.
β¬ Gray = Letter not in the word.
Features:
β
3 difficulty levels (Easy: 7 guesses, Hard: 5).
β
Limited hints (4 per game, 30s cooldown).
β
Virtual keyboard (shows letter status).
β
Saves results in results.json.
Key Technical Challenges
1. Terminal Colors (ANSI Escape Codes)
Used ANSI codes for cross-platform colors:
#define GREEN "\033[42m\033[30m"
printf("%s V %s Correct!", GREEN, RESET);
Windows fix:
#include <windows.h>
SetConsoleOutputCP(CP_UTF8); // Enable UTF-8
2. Real-Time Input (No "Enter" Needed)
Windows: _getch() (from conio.h).
Linux/macOS: termios raw mode.
char get_char() {
#ifdef _WIN32
return _getch();
#else
// Disable input buffering
struct termios old, new;
tcgetattr(0, &old);
new = old;
new.c_lflag &= ~(ICANON | ECHO);
tcsetattr(0, TCSANOW, &new);
char c = getchar();
tcsetattr(0, TCSANOW, &old);
return c;
#endif
}
3. Hint System with Cooldown
time_t last_hint_time;
if (time(NULL) - last_hint_time >= 30) {
reveal_random_letter();
} else {
printf("Wait %d sec!", 30 - (time(NULL) - last_hint_time));
}
Cool Features
- JSON Persistence
{"word": "CRANE", "guesses": 3, "difficulty": "HARD"}
- Dynamic Keyboard https://via.placeholder.com/400x100?text=Virtual+Keyboard+Demo
Try It Yourself!
π GitHub: https://github.com/DamiaoArth/CodleC
Includes:
Full source code (main.c).
Pre-built binaries (Windows/Linux).
Portuguese word lists (easy to swap).
π¬ Discussion
Ever built a terminal game? Share your experiences below!
Ideas to improve CodleC? (Thinking of adding a global leaderboard!)
References:
ANSI Escape Codes
Wordle (NYT)
Letreco
TERMOOO
c #gamedev #terminal #wordle #opensource
PS: Can you beat my high score of 3 guesses on Hard mode?
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more