make variable inventory slots
This commit is contained in:
parent
5949b2a2d6
commit
9ae713b6c8
|
@ -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<String>) {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }),
|
||||
|
|
|
@ -12,6 +12,7 @@ pub struct Player {
|
|||
gold: usize,
|
||||
experience: usize,
|
||||
inventory: Vec<Potion>,
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue