Work on more references
This commit is contained in:
parent
0ef034f14f
commit
227e44dd43
@ -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>,
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user