From d84906ec92e45ed2cf2611c2f646d72ef5f1bb64 Mon Sep 17 00:00:00 2001 From: Iago Garrido Date: Tue, 12 Nov 2019 14:28:58 +0100 Subject: add state --- src/state.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/state.rs (limited to 'src/state.rs') 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 -- cgit v1.2.3