From 8192a07c2696b7313dd509a7e474ff7fc79d9bdb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 20 Mar 2013 21:58:37 -0500 Subject: implement a bit more in the test --- test/rl.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'test/rl.rs') diff --git a/test/rl.rs b/test/rl.rs index 2ea664f..c6c3b1b 100644 --- a/test/rl.rs +++ b/test/rl.rs @@ -1,18 +1,54 @@ extern mod term; use core::io::ReaderUtil; -fn main () { +fn term_app (body: &fn ()) { term::info::init(); - let (rows, cols) = term::ios::size(); do term::ios::preserve { - term::ios::cbreak(); do term::info::with_alternate_screen { - term::info::clear(); - for uint::range(0, rows) |i| { - term::info::move(0, i); - io::print(str::repeat(".", cols)); + body() + } + } +} + +fn draw_map (rows: uint, cols: uint) { + for uint::range(0, rows) |i| { + term::info::move(0, i); + io::print(str::repeat(".", cols)); + } +} + +fn draw_character (x: uint, y: uint) { + term::info::move(x, y); + io::print("@"); + term::info::move(x, y); +} + +fn draw_ground (x: uint, y: uint) { + term::info::move(x, y); + io::print("."); +} + +fn main () { + let (rows, cols) = term::ios::size(); + + do term_app { + term::ios::cbreak(); + term::ios::echo(false); + term::info::clear(); + + draw_map(rows, cols); + + let mut (x, y) = (0u, 0u); + loop { + draw_character(x, y); + match io::stdin().read_char() { + 'q' => { break } + 'h' if x > 0 => { draw_ground(x, y); x -= 1 } + 'j' if y < rows - 1 => { draw_ground(x, y); y += 1 } + 'k' if y > 0 => { draw_ground(x, y); y -= 1 } + 'l' if x < cols - 1 => { draw_ground(x, y); x += 1 } + _ => { } } - io::stdin().read_char(); } } } -- cgit v1.2.3-54-g00ecf