diff --git a/src/artifacts.rs b/src/artifacts.rs index e7dc603..cb2aafd 100644 --- a/src/artifacts.rs +++ b/src/artifacts.rs @@ -93,10 +93,11 @@ impl Artifact for Potion { ); self.health = 0; self.was_collected = true; - } else { + } else if player.add_to_inventory(self) { messages.insert(0, "move potion to inventory.".to_string()); - player.add_to_inventory(self); self.was_collected = true; + } else { + messages.insert(0, "inventory is full.".to_string()); } } diff --git a/src/main.rs b/src/main.rs index 27dabc3..37bb337 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,7 +103,7 @@ fn main() -> Result<()> { .style(Style::default().bg(Color::Blue)); frame.render_widget( Paragraph::new(format!( - "Health: {}/{}\nExp: {}\nGold: {}\nLevel: {}\nInventory: {}", + "Health: {}/{}\nExp: {}\nGold: {}\nLevel: {}\nInventory: {}/10", game.get_player().get_life(), game.get_player().get_max_life(), game.get_player().get_experience(), diff --git a/src/player.rs b/src/player.rs index 11f3248..5263a7a 100644 --- a/src/player.rs +++ b/src/player.rs @@ -69,8 +69,13 @@ impl Player { rand::thread_rng().gen_range(1..4) } - pub fn add_to_inventory(&mut self, potion: &Potion) { - self.inventory.push(*potion); + pub fn add_to_inventory(&mut self, potion: &Potion) -> bool { + if self.inventory.len() < 10 { + self.inventory.push(*potion); + true + } else { + false + } } pub fn inventory_size(&self) -> usize {