unused potions now are collected in the inventory and can be consumed with the p key

This commit is contained in:
2024-10-21 21:52:07 +02:00
parent a0635de65a
commit 2b8f7eebba
3 changed files with 54 additions and 7 deletions

View File

@@ -103,12 +103,13 @@ fn main() -> Result<()> {
.style(Style::default().bg(Color::Blue));
frame.render_widget(
Paragraph::new(format!(
"Health: {}/{}\nExp: {}\nGold: {}\nLevel: {}",
"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().get_immutable_position().get_level() + 1,
game.get_player().inventory_size(),
))
.block(block)
.wrap(Wrap { trim: true }),
@@ -155,6 +156,19 @@ fn main() -> Result<()> {
.to_string(),
);
}
KeyCode::Char('p') => {
let gained_health = game.get_mutable_player().consume_inventory();
if gained_health > 0 {
game.messages.insert(
0,
format!(
"used a potion from inventory and gained {} health.",
gained_health
)
.to_string(),
);
}
}
KeyCode::Char('q') => {
break;
}