diff --git a/src/game.rs b/src/game.rs index 9e2694f..049b647 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,7 +1,7 @@ use crate::level::Level; use crate::player::Player; -pub struct Game { - pub player: Player, - pub levels: [Level; 25] +pub struct Game<'game> { + pub player: &'game mut Player, + pub levels: Vec<&'game mut Level>, } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4d70693..f0efdca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,9 +8,14 @@ mod level; mod position; fn main() { + let mut p = Player::new("Teddy Tester", 10); let g = Game { - player: Player::new("Teddy Tester", 10), - levels: [Level::new();25] + player: &mut p, + levels: Vec::new() }; + println!("{}",g.player.get_name()); + println!("{}",g.player.get_life()); + g.player.change_life(-1); + println!("{}",g.player.get_life()); } diff --git a/src/player.rs b/src/player.rs index a5e6388..ed2e6cd 100644 --- a/src/player.rs +++ b/src/player.rs @@ -23,6 +23,9 @@ impl Player { pub fn change_life(&mut self, by: i16) { self.life = max(0, min(self.max_life, self.life + by)); } + pub fn get_life(&self) -> i16 { + self.life + } } #[test]