updated deps

fixed clippy remarks
This commit is contained in:
2024-10-20 14:59:20 +02:00
parent 210d590e38
commit efc4cdd363
12 changed files with 515 additions and 221 deletions

View File

@@ -36,10 +36,15 @@ impl Artifact for Chest {
("C", Color::Blue)
}
fn get_immutable_position(&self) -> &Position { &self.position }
fn get_immutable_position(&self) -> &Position {
&self.position
}
fn collect(&mut self, player: &mut Player, messages: &mut Vec<String>) {
player.retrieve_gold(self.gold);
messages.insert(0, format!("opened chest and collected {} gold.", self.gold).to_string());
messages.insert(
0,
format!("opened chest and collected {} gold.", self.gold).to_string(),
);
self.gold = 0;
}
@@ -67,21 +72,29 @@ impl Artifact for Potion {
fn get_representation(&self) -> (&str, Color) {
("P", Color::Green)
}
fn get_immutable_position(&self) -> &Position { &self.position }
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() {
let old = player.get_life();
player.change_life(self.health.try_into().unwrap());
let new = player.get_life();
messages.insert(0, format!("picked up potion and gained {} hp.", new - old).to_string());
messages.insert(
0,
format!("picked up potion and gained {} hp.", new - old).to_string(),
);
self.health = 0;
} else {
messages.insert(0, "not using the potion because you're healthy.".to_string());
messages.insert(
0,
"not using the potion because you're healthy.".to_string(),
);
}
}
fn was_collected(&self) -> bool {
self.health == 0
}
}
}