Academic · Oct–Nov 2023
Slay the Spire but in C
Turn-based card battler for the terminal, in plain C, inspired by Slay the Spire.

TL;DR
- A Slay the Spire-style card battler in plain C: three classes with their own decks, three stages, and monsters that announce their next move.
- Managed memory by hand: monsters and stages live in linked lists, kept sorted with an insertion sort and freed as monsters die.
- Won Best Game at the Mostra TechDesign, CESAR School's showcase of student projects.
Slay the Spire but in C is a turn-based card game that runs in the terminal. I wrote it in C for the Algorithms and Data Structures course at CESAR School (opens in a new tab), as my take on Mega Crit (opens in a new tab)'s Slay the Spire. It's a student project, not affiliated with Mega Crit, and it uses none of their art: everything is text, in Portuguese.
It won Best Game at the Mostra TechDesign, the showcase where CESAR School students present their projects at the end of each semester.
How it plays
You pick a class, then fight your way through three stages of monsters by spending energy on cards.
- Three classes: Warrior, Mage and Archer, each with its own deck of six cards.
- Energy: you get 3 energy per turn and each card costs 1 to 3. Cards attack one monster, hit every monster, give you shields or heal you, and each one can be played once per turn.
- Intents: as in Slay the Spire, every monster shows what it will do next, attack for a set amount or raise its shield, and acts when you end your turn.
- Three stages, nine monsters: a dark cave, the castle dungeon and the Demon King's castle, from goblins and orcs to a dragon and the Demon King himself.
- Difficulty: easy, medium or hard sets how much HP every monster has.
- High scores: every run is saved to a file and ranked by difficulty, then stage reached, then HP left.

How it's built
The course was about data structures in C, so the interesting part was managing data and memory by hand:
- Linked lists: each stage's monsters live in a doubly linked list, and the stages themselves form a singly linked list. When a monster dies, it's unlinked and freed.
- Insertion sort: the monster list is kept sorted by HP with an insertion sort that relinks its nodes in place, so single-target cards always hit the weakest monster.
- Decks built at runtime: each class's deck is an array of pointers to cards allocated with
malloc. Playing again frees the old deck, stages and monsters before building new ones. - Modules: cards, monsters, stages, turns, the menu, the player, high scores and utilities each have their own source file and header.
- Terminal presentation: ANSI escape codes for colors and clearing the screen, an ASCII-art title, and the story intro, victory and defeat texts typed out letter by letter.
- No libraries: only the C standard library and
usleepfromunistd.h, compiled with GCC.
Media
Screenshots and art
A full turn, in Portuguese like the rest of the game.
Like this?
Let's talk
Open to conversations about developer and production roles, and collaborations. I'm in Recife, Brazil (UTC−3).