snake_game
Classic Snake game written in XCX 3.1. Terminal-based with real-time input, progressive speed scaling, and Unicode rendering.
snake_game
Classic Snake game written natively in XCX 3.0. Playable in the terminal with real-time keyboard input, progressive speed scaling, and persistent high score within a session.
Features
Requirements
>= 3.0>= 1.0Installation
text
xcx pax clone "snake_game"
Running
text
xcx pax run
Or directly:
text
xcx src/main.xcx
Controls
| Key | Action |
|---|---|
W / ↑ | Move up |
S / ↓ | Move down |
A / ← | Move left |
D / → | Move right |
Q | Quit game |
Enter | Restart |
Direction reversal (e.g. going left while moving right) is ignored — the snake continues in the current direction.
Scoring
| Event | Points |
|---|---|
| Eating food | +10 |
Speed increases by 20 ms every 50 points, down to a minimum of 60 ms per tick.
Project Structure
text
snake_game/
├── project.pax # PAX project configuration
└── src/
└── main.xcx # Full game — single file, no dependencies
How It Works
The board is a flat array:i of size BOARDW × BOARDH (20 × 15). Each cell holds one of four constants: EMPTY, SNAKE, FOOD, or WALL. The snake's body is tracked as two parallel array:i lists (snakex, snakey).
Each tick:
1. A read_input fiber is spawned and waits for a keypress
2. @wait speed_ms delays the frame
3. The fiber result is consumed via .next()
4. step() moves the snake, checks collisions, and handles food
Food is placed by collecting all EMPTY cell indices into a set:N, then using random.choice from to pick one at random.
License
MIT
Install
xcx pax add snake_game@1.0.0
Downloads
17
Stars
1