diff options
author | Guillaume <g@bitimplosion.com> | 2019-11-12 14:57:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-12 14:57:54 +0100 |
commit | e8e931794052455d93517d35c75bb98b7829e70d (patch) | |
tree | 99df93ff7678775a4cb179fbd6a0b52a15ede426 /src/state.rs | |
parent | 8fa3fa881bc3b954e136295fe6cc7022737ae9db (diff) | |
parent | 76fc41b3c803ad4db3c19a76d408ab301438aa1e (diff) |
Merge pull request #5 from iagogarrido/master
Add state
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..20b49d7 --- /dev/null +++ b/src/state.rs @@ -0,0 +1,46 @@ +use pancurses::Window; +use std::env; + +use crate::entities::{Character, Entity}; +use crate::world::{Dungeon, Generatable, 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 |