properly clamp the timeout in conway
This commit is contained in:
parent
24a230a027
commit
1d9cb6a1f9
1 changed files with 4 additions and 1 deletions
|
|
@ -145,6 +145,9 @@ pub fn play(width: u64, height: u64, writer: *std.Io.Writer) !void {
|
||||||
try con.writer.print("\x1B[{}A", .{height + 1});
|
try con.writer.print("\x1B[{}A", .{height + 1});
|
||||||
try con.print();
|
try con.print();
|
||||||
|
|
||||||
|
// keep the timeouts reasonable
|
||||||
|
timeout = std.math.clamp(timeout, 1, 10000);
|
||||||
|
|
||||||
// keep the cursor in the game window to prevent the terminal from doing
|
// keep the cursor in the game window to prevent the terminal from doing
|
||||||
// anything we can't/don't account for
|
// anything we can't/don't account for
|
||||||
cursor_x = std.math.clamp(cursor_x, 1, con.width);
|
cursor_x = std.math.clamp(cursor_x, 1, con.width);
|
||||||
|
|
@ -174,7 +177,7 @@ pub fn play(width: u64, height: u64, writer: *std.Io.Writer) !void {
|
||||||
for (buf) |c| switch (c) {
|
for (buf) |c| switch (c) {
|
||||||
// we don't wanna worry about case when using +
|
// we don't wanna worry about case when using +
|
||||||
'+', '=' => timeout += 50,
|
'+', '=' => timeout += 50,
|
||||||
'-' => timeout = std.math.clamp(timeout - 50, 1, 1000),
|
'-' => timeout -= 50,
|
||||||
'n' => break :run, // next generation
|
'n' => break :run, // next generation
|
||||||
'q' => {
|
'q' => {
|
||||||
running = false;
|
running = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue