aboutsummaryrefslogtreecommitdiffstats
path: root/test/rl.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-03-20 21:58:37 -0500
committerJesse Luehrs <doy@tozt.net>2013-03-20 21:58:37 -0500
commit8192a07c2696b7313dd509a7e474ff7fc79d9bdb (patch)
tree0c6eaa1b69b2e0348f3485ae08e2e3b9bbf1aad1 /test/rl.rs
parentd00c8ec76c498196be8bfe2d58f27697bda9de69 (diff)
downloadrust-term-8192a07c2696b7313dd509a7e474ff7fc79d9bdb.tar.gz
rust-term-8192a07c2696b7313dd509a7e474ff7fc79d9bdb.zip
implement a bit more in the test
Diffstat (limited to 'test/rl.rs')
-rw-r--r--test/rl.rs52
1 files changed, 44 insertions, 8 deletions
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();
}
}
}