summaryrefslogtreecommitdiff
path: root/addons/snake
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 15:58:05 -0300
committerGabriel Schneider <[email protected]>2026-11-06 17:53:43 -0300
commite9f9f65ace7650a02cee6bf2b2eb466522485834 (patch)
treecaf5b7a2344b8da002f3952e3225e0db38b492fc /addons/snake
parent75e4787be773c8cbfd2e60e59d409b9556898365 (diff)
downloadpardes-e9f9f65ace7650a02cee6bf2b2eb466522485834.tar.gz
pardes-e9f9f65ace7650a02cee6bf2b2eb466522485834.zip
kinds #36, the five kinds on ABI 3: fake.c with every function (view painting each view's size, search through found, FakeJob cancel) and PA_PICTURES, snake, life and image over the module's prefix and open(path, bytes), image without a record (a Restore reads its file), and pdf.c ported mechanically (tick into pa_tick with its [P/N] prefix, a table of the views it is told, its strip laid out for the view its last key or click came from, the text layer painted for a window of glyphs and read on the tick while some view shows text, a body read keeping nothing, search through found, the record its fit, tint and place, PA_PICTURES); the goldens moved once, said in the report: the art words from the first frame, fake's view line, a pane ticked when opened or loaded, a view told after a frame re-wrapped its tag
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'addons/snake')
-rw-r--r--addons/snake/snake.out12
-rw-r--r--addons/snake/snake.zig9
2 files changed, 12 insertions, 9 deletions
diff --git a/addons/snake/snake.out b/addons/snake/snake.out
index 79bc5f19..6869c5cc 100644
--- a/addons/snake/snake.out
+++ b/addons/snake/snake.out
@@ -283,10 +283,10 @@ dump 240 bytes
tag Snake 1
|######################
|# #
-|# oo #
|# o #
-|# * @ #
-|# #
+|# o #
+|# * o #
+|# @ #
|######################
|
|
@@ -310,15 +310,15 @@ tag Snake 1
|
|
> tick 150
-tag Snake 1
+tag Snake 1 over
|######################
|# #
|# o #
|# o #
|# * o #
-|# @ #
+|# x #
|######################
-|
+|game over: any key
|
|
|
diff --git a/addons/snake/snake.zig b/addons/snake/snake.zig
index badafc54..cdbf74d9 100644
--- a/addons/snake/snake.zig
+++ b/addons/snake/snake.zig
@@ -76,7 +76,7 @@ pub const Snake = extern struct {
s.placeFood();
}
- pub fn open(s: *Snake, _: ?[]const u8) void {
+ pub fn open(s: *Snake, _: ?[]const u8, _: ?[]const u8) void {
s.rng = addon.seed() | 1;
s.restart();
}
@@ -88,14 +88,17 @@ pub const Snake = extern struct {
return if (!flags.focused or s.dead) s.next.stop() else s.next.every(now, period);
}
- pub fn paint(s: *const Snake, w: addon.Window, out: addon.Paint) void {
+ pub fn prefix(s: *const Snake, w: *std.Io.Writer) !void {
+ try w.print("Snake {d}{s}", .{ s.score, if (s.dead) " over" else "" });
+ }
+
+ pub fn paint(s: *const Snake, w: addon.Window, _: addon.Paint) void {
const wall: addon.Style = .{ .fg = .index(8) };
for (0..H + 2) |y| for (0..W + 2) |x| if (x % (W + 1) == 0 or y % (H + 1) == 0) w.put(x, y, "#", wall);
w.put(1 + s.food.x, 1 + s.food.y, "*", .{ .fg = .index(1), .attrs = .{ .bold = true } });
for (s.segs[0..s.len], 0..) |p, i|
w.put(1 + p.x, 1 + p.y, if (i > 0) "o" else if (s.dead) "x" else "@", .{ .fg = .index(2), .attrs = .{ .bold = i == 0 } });
if (s.dead) w.put(0, H + 2, "game over: any key", .{ .fg = .index(1) }) else if (!w.focused) w.put(0, H + 2, "paused", wall);
- out.prefix("Snake {d}{s}", .{ s.score, if (s.dead) " over" else "" });
}
pub fn key(s: *Snake, k: addon.Key) bool {