randomize content of chests and potions

This commit is contained in:
Joachim Lusiardi 2024-10-21 08:27:55 +02:00
parent b3d85ac7b3
commit 8dfe56a3c2
5 changed files with 9 additions and 8 deletions

View File

@ -1,3 +1,4 @@
use rand::Rng;
use ratatui::style::Color;
use crate::player::Player;
@ -22,11 +23,11 @@ pub struct Chest {
impl Chest {
pub fn new(position: Position) -> Self {
let level = position.get_level();
let min_gold = 10 * (position.get_level()+1);
let max_gold = min_gold + 10*position.get_level();
Self {
position,
// TODO maybe randomize this?
gold: (level + 1) * 10,
gold: rand::thread_rng().gen_range(min_gold..=max_gold),
}
}
}
@ -61,9 +62,11 @@ pub struct Potion {
impl Potion {
pub fn new(position: Position) -> Self {
let min_health_gain = 5 + position.get_level();
let max_health_gain = min_health_gain + 3 * position.get_level();
Self {
position,
health: 5,
health: rand::thread_rng().gen_range(min_health_gain..=max_health_gain),
}
}
}

View File

@ -164,7 +164,6 @@ impl Game {
match m {
None => {}
Some(m) => {
// TODO fight the monster
let player_dmg = self.player.damage();
m.decrease_life(player_dmg);
if m.is_dead() {

View File

@ -147,7 +147,6 @@ impl Level {
if player.get_immutable_position().get_x() == new_x
&& player.get_immutable_position().get_y() == new_y
{
// TODO handle fight between monster and player
let monster_dmg = self.monsters[index].damage() as i16;
player.change_life(-monster_dmg);
messages.insert(

View File

@ -45,7 +45,7 @@ impl StatefulWidget for LevelWidget {
self.set_cell(buf, x, y, "Ω", Color::Black, Color::Gray);
}
StructureElement::Wall => {
// TODO add fancy walls
// TODO add fancy walls with https://en.wikipedia.org/wiki/Box-drawing_characters
self.set_cell(buf, x, y, "#", FG_BROWN, Color::Gray);
}
StructureElement::Floor => {

View File

@ -8,7 +8,7 @@ pub trait HasPosition {
fn get_immutable_position(&self) -> &Position;
}
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Clone, Copy)]
pub struct Position {
level: usize,
x: usize,