make variable inventory slots

This commit is contained in:
2024-10-22 13:39:43 +02:00
parent 5949b2a2d6
commit 9ae713b6c8
3 changed files with 14 additions and 10 deletions

View File

@@ -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 {