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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
extern crate pancurses;
use pancurses::{initscr, endwin, noecho, start_color, Input, init_pair, COLOR_YELLOW, COLOR_BLACK, COLOR_WHITE, COLOR_BLUE, COLOR_GREEN, cbreak, curs_set};
mod map;
mod view;
mod list;
mod location;
mod character;
mod constants;
use map::Map;
use view::View;
use list::List;
use location::Location;
use character::Character;
use constants::{Colors, Commands};
fn init() -> pancurses::Window {
let main = initscr();
main.clear();
noecho();
cbreak();
curs_set(0);
main.timeout(100);
start_color();
init_pair(Colors::Grass as i16, COLOR_GREEN, COLOR_BLACK);
init_pair(Colors::Tree as i16, COLOR_YELLOW, COLOR_BLACK);
init_pair(Colors::White as i16, COLOR_WHITE, COLOR_WHITE);
init_pair(Colors::BlueUnit as i16, COLOR_WHITE, COLOR_BLUE);
main
}
fn main() {
let main = init();
let mut map = Map::new();
let mut view = View::new(main.get_max_yx(), &map.window);
let mut cursor = Character::new('X', Colors::White as u8, Location(150, 150));
let mut list = List::new(map.impassable.to_vec());
let mut paused = false;
let mut first_location = None;
let mut draw_box = false;
loop{
let command = match main.getch() {
Some(Input::Character(ch)) => {
match ch {
'h' => {cursor.location.1 -= 1; None}
'l' => {cursor.location.1 += 1; None}
'k' => {cursor.location.0 -= 1; None}
'j' => {cursor.location.0 += 1; None}
'q' => break,
'o' => Some(Commands::Go),
's' => Some(Commands::Grid),
'\n' => Some(Commands::Finish),
_ => None,
}
},
Some(Input::KeyEnter) => Some(Commands::Finish),
_ => None,
};
map.fill();
match command {
Some(Commands::Go) => list.give_destination(cursor.location),
Some(Commands::Grid) => {
paused = true;
draw_box = true;
first_location = Some(cursor.location);
},
Some(Commands::Finish) => {
paused = false;
draw_box = false;
match first_location {
Some(first_location) => list.give_grid(first_location, cursor.location),
None => (),
}
},
None => (),
}
if !paused {
list.action();
}
map.draw(&cursor);
if draw_box {
match first_location {
Some(first_location) => map.draw_box(first_location, cursor.location),
None => (),
}
}
for man in list.men.iter() {
map.draw(man);
}
view.center(cursor.clone(), &map.window);
}
endwin();
}
|