diff options
author | Iago Garrido <iago086@gmail.com> | 2019-11-12 14:28:58 +0100 |
---|---|---|
committer | Iago Garrido <iago086@gmail.com> | 2019-11-12 14:28:58 +0100 |
commit | d84906ec92e45ed2cf2611c2f646d72ef5f1bb64 (patch) | |
tree | 0086b9f87fcef11fe795fb624164c0f33b9b00cf /src/state.rs | |
parent | e58d24c9a945b29ca9a4fd18647749941ba5e48b (diff) |
add state
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..3e8516b --- /dev/null +++ b/src/state.rs @@ -0,0 +1,48 @@ +use pancurses::Window; +use std::env; + +use crate::character::Character; +use crate::character::Player; +use crate::computer::Enemy; +use crate::world::{Dungeon, Generable, Level}; + +pub struct State { + pub character: Character, + pub dungeon: Dungeon, + pub level: usize, +} + +impl State { + pub fn new( + character: Character, + dungeon: Dungeon, + ) -> State { + State { + character: character, + dungeon: dungeon, + level: 0, + } + } + + pub fn init(&mut self) { + self.dungeon.generate(); + self.character.place(self.current_level().get_start_point()); + } + + pub fn debug(&self) { + match env::var("DEBUG") { + Ok(_) => { + self.dungeon.debug_levels(); + }, + Err(_) => () + }; + } + + pub fn render_level(&self, window: &Window) { + self.current_level().render(window); + } + + fn current_level(&self) -> &Level { + &self.dungeon.levels[self.level] + } +}
\ No newline at end of file |