diff --git a/src/artifacts.rs b/src/artifacts.rs index cb2aafd..e0e0d50 100644 --- a/src/artifacts.rs +++ b/src/artifacts.rs @@ -72,15 +72,21 @@ impl Potion { was_collected: false, } } + + pub fn get_health(&self) -> usize { + self.health + } } impl Artifact for Potion { fn get_representation(&self) -> (&str, Color) { ("P", Color::Green) } + fn get_immutable_position(&self) -> &Position { &self.position } + fn collect(&mut self, player: &mut Player, messages: &mut Vec) { // only consume potion of the player can gain at least one health point if !player.is_healthy() { @@ -105,8 +111,3 @@ impl Artifact for Potion { self.was_collected } } -impl Potion { - pub fn get_health(&self) -> usize { - self.health - } -} diff --git a/src/main.rs b/src/main.rs index 37bb337..a0627b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,13 +103,14 @@ fn main() -> Result<()> { .style(Style::default().bg(Color::Blue)); frame.render_widget( Paragraph::new(format!( - "Health: {}/{}\nExp: {}\nGold: {}\nLevel: {}\nInventory: {}/10", + "Health: {}/{}\nExp: {}\nGold: {}\nLevel: {}\nInventory: {}/{}", game.get_player().get_life(), game.get_player().get_max_life(), game.get_player().get_experience(), game.get_player().get_gold(), game.get_player().get_immutable_position().get_level() + 1, - game.get_player().inventory_size(), + game.get_player().inventory_size().0, + game.get_player().inventory_size().1, )) .block(block) .wrap(Wrap { trim: true }), diff --git a/src/player.rs b/src/player.rs index 5263a7a..e0eb10a 100644 --- a/src/player.rs +++ b/src/player.rs @@ -12,6 +12,7 @@ pub struct Player { gold: usize, experience: usize, inventory: Vec, + inventory_slots: usize, } impl Player { @@ -24,6 +25,7 @@ impl Player { gold: 0, experience: 0, inventory: vec![], + inventory_slots: 2, } } pub fn get_name(&self) -> String { @@ -70,7 +72,7 @@ impl Player { } pub fn add_to_inventory(&mut self, potion: &Potion) -> bool { - if self.inventory.len() < 10 { + if self.inventory.len() < self.inventory_slots { self.inventory.push(*potion); true } else { @@ -78,8 +80,8 @@ impl Player { } } - pub fn inventory_size(&self) -> usize { - self.inventory.len() + pub fn inventory_size(&self) -> (usize, usize) { + (self.inventory.len(), self.inventory_slots) } pub fn consume_inventory(&mut self) -> usize {