make variable inventory slots
This commit is contained in:
parent
5949b2a2d6
commit
9ae713b6c8
|
@ -72,15 +72,21 @@ impl Potion {
|
||||||
was_collected: false,
|
was_collected: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_health(&self) -> usize {
|
||||||
|
self.health
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Artifact for Potion {
|
impl Artifact for Potion {
|
||||||
fn get_representation(&self) -> (&str, Color) {
|
fn get_representation(&self) -> (&str, Color) {
|
||||||
("P", Color::Green)
|
("P", Color::Green)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_immutable_position(&self) -> &Position {
|
fn get_immutable_position(&self) -> &Position {
|
||||||
&self.position
|
&self.position
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect(&mut self, player: &mut Player, messages: &mut Vec<String>) {
|
fn collect(&mut self, player: &mut Player, messages: &mut Vec<String>) {
|
||||||
// only consume potion of the player can gain at least one health point
|
// only consume potion of the player can gain at least one health point
|
||||||
if !player.is_healthy() {
|
if !player.is_healthy() {
|
||||||
|
@ -105,8 +111,3 @@ impl Artifact for Potion {
|
||||||
self.was_collected
|
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));
|
.style(Style::default().bg(Color::Blue));
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new(format!(
|
Paragraph::new(format!(
|
||||||
"Health: {}/{}\nExp: {}\nGold: {}\nLevel: {}\nInventory: {}/10",
|
"Health: {}/{}\nExp: {}\nGold: {}\nLevel: {}\nInventory: {}/{}",
|
||||||
game.get_player().get_life(),
|
game.get_player().get_life(),
|
||||||
game.get_player().get_max_life(),
|
game.get_player().get_max_life(),
|
||||||
game.get_player().get_experience(),
|
game.get_player().get_experience(),
|
||||||
game.get_player().get_gold(),
|
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(),
|
game.get_player().inventory_size().0,
|
||||||
|
game.get_player().inventory_size().1,
|
||||||
))
|
))
|
||||||
.block(block)
|
.block(block)
|
||||||
.wrap(Wrap { trim: true }),
|
.wrap(Wrap { trim: true }),
|
||||||
|
|
|
@ -12,6 +12,7 @@ pub struct Player {
|
||||||
gold: usize,
|
gold: usize,
|
||||||
experience: usize,
|
experience: usize,
|
||||||
inventory: Vec<Potion>,
|
inventory: Vec<Potion>,
|
||||||
|
inventory_slots: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Player {
|
impl Player {
|
||||||
|
@ -24,6 +25,7 @@ impl Player {
|
||||||
gold: 0,
|
gold: 0,
|
||||||
experience: 0,
|
experience: 0,
|
||||||
inventory: vec![],
|
inventory: vec![],
|
||||||
|
inventory_slots: 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_name(&self) -> String {
|
pub fn get_name(&self) -> String {
|
||||||
|
@ -70,7 +72,7 @@ impl Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_to_inventory(&mut self, potion: &Potion) -> bool {
|
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);
|
self.inventory.push(*potion);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,8 +80,8 @@ impl Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inventory_size(&self) -> usize {
|
pub fn inventory_size(&self) -> (usize, usize) {
|
||||||
self.inventory.len()
|
(self.inventory.len(), self.inventory_slots)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn consume_inventory(&mut self) -> usize {
|
pub fn consume_inventory(&mut self) -> usize {
|
||||||
|
|
Loading…
Reference in New Issue