blob: 7edc65486cfa847e3f19af058947333990042d4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
extern crate rand;
extern crate pancurses;
#[macro_use]
extern crate text_io;
mod character;
mod computer;
mod world;
use character::Player;
use computer::Enemy;
use pancurses::{Window, initscr, endwin};
use rand::Rng;
use std::io;
use std::convert::TryFrom;
use world::{World, GameWorld, BlockType};
fn draw_block(window: &Window, block: &BlockType) {
let repr = match block {
BlockType::Floor => ".",
BlockType::Wall => "0",
BlockType::Nothing => " "
};
print!("{}", repr);
window.printw(repr);
}
fn render_world(window: &Window, world: &World) {
let grid = world.get_world();
for (linenum, line) in grid.iter().enumerate() {
for block in line.iter() {
draw_block(&window, block);
}
window.mv(linenum as i32, 0);
println!("");
}
}
fn main() {
let mut world = World::new(30);
world.generate();
let window = initscr();
render_world(&window, &world);
window.refresh();
window.getch();
endwin();
}
|