feat(snake): implement snake game with pure game logic, renderer, and IPC-based main loop

This commit is contained in:
2026-10-18 04:00:09 +02:00
parent a7913ddeef
commit 0389c85108
8 changed files with 458 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
use crate::game::Snake;
use crate::renderer::{render, RenderCommand};
#[test]
fn render_produces_commands() {
let snake = Snake::new();
let mut commands = [RenderCommand { x: 0, y: 0, w: 0, h: 0, color: 0 }; 64];
let count = render(&snake, &mut commands);
// background + border + food + 3 body segments = 6
assert!(count >= 6);
}
#[test]
fn first_command_is_background() {
let snake = Snake::new();
let mut commands = [RenderCommand { x: 0, y: 0, w: 0, h: 0, color: 0 }; 64];
render(&snake, &mut commands);
assert_eq!(commands[0].x, 0);
assert_eq!(commands[0].y, 0);
assert!(commands[0].w > 0);
assert!(commands[0].h > 0);
}
#[test]
fn food_is_rendered() {
let snake = Snake::new();
let mut commands = [RenderCommand { x: 0, y: 0, w: 0, h: 0, color: 0 }; 64];
let count = render(&snake, &mut commands);
// Food is command index 2 (after bg and border)
assert!(count > 2);
assert_eq!(commands[2].color, 0xFF0040);
}