Improved fights between player and monster
This commit is contained in:
parent
cefb0cc5f2
commit
b3d85ac7b3
|
@ -83,7 +83,7 @@ impl Artifact for Potion {
|
|||
let new = player.get_life();
|
||||
messages.insert(
|
||||
0,
|
||||
format!("picked up potion and gained {} hp.", new - old).to_string(),
|
||||
format!("picked up potion and gained {} health.", new - old).to_string(),
|
||||
);
|
||||
self.health = 0;
|
||||
} else {
|
||||
|
|
36
src/game.rs
36
src/game.rs
|
@ -165,24 +165,32 @@ impl Game {
|
|||
None => {}
|
||||
Some(m) => {
|
||||
// TODO fight the monster
|
||||
|
||||
let monster_dmg = m.damage() as i16;
|
||||
let player_dmg = self.player.damage();
|
||||
self.player.change_life(-monster_dmg);
|
||||
m.decrease_life(player_dmg);
|
||||
|
||||
// inform player
|
||||
self.messages.insert(
|
||||
0,
|
||||
format!("{} hits you for {} damage.", m.get_name(), monster_dmg).to_string(),
|
||||
);
|
||||
self.messages.insert(
|
||||
0,
|
||||
format!("you hit {} for {} damage.", m.get_name(), player_dmg).to_string(),
|
||||
);
|
||||
// monster died, player gains experience
|
||||
if m.is_dead() {
|
||||
self.player.gain_experience(m.get_experience_gain());
|
||||
self.messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you hit {} for {} damage and kill it.",
|
||||
m.get_name(),
|
||||
player_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
} else {
|
||||
self.messages.insert(
|
||||
0,
|
||||
format!("you hit {} for {} damage.", m.get_name(), player_dmg).to_string(),
|
||||
);
|
||||
let monster_dmg = m.damage() as i16;
|
||||
self.player.change_life(-monster_dmg);
|
||||
|
||||
self.messages.insert(
|
||||
0,
|
||||
format!("{} hits you for {} damage.", m.get_name(), monster_dmg)
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
return m.is_dead();
|
||||
}
|
||||
|
|
35
src/level.rs
35
src/level.rs
|
@ -149,10 +149,7 @@ impl Level {
|
|||
{
|
||||
// TODO handle fight between monster and player
|
||||
let monster_dmg = self.monsters[index].damage() as i16;
|
||||
let player_dmg = player.damage();
|
||||
self.monsters[index].decrease_life(player_dmg);
|
||||
player.change_life(-monster_dmg);
|
||||
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
|
@ -162,18 +159,32 @@ impl Level {
|
|||
)
|
||||
.to_string(),
|
||||
);
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you hit {} for {} damage.",
|
||||
self.monsters[index].get_name(),
|
||||
player_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
let player_dmg = player.damage();
|
||||
self.monsters[index].decrease_life(player_dmg);
|
||||
|
||||
// if the attack did not kill the opponent, back down
|
||||
if !player.is_dead() {
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you hit {} for {} damage and kill it.",
|
||||
self.monsters[index].get_name(),
|
||||
player_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
self.monsters[index].get_position().change(-dx, -dy);
|
||||
} else {
|
||||
messages.insert(
|
||||
0,
|
||||
format!(
|
||||
"you hit {} for {} damage.",
|
||||
self.monsters[index].get_name(),
|
||||
player_dmg
|
||||
)
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -108,7 +108,7 @@ fn main() -> Result<()> {
|
|||
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().get_immutable_position().get_level() + 1
|
||||
))
|
||||
.block(block)
|
||||
.wrap(Wrap { trim: true }),
|
||||
|
|
Loading…
Reference in New Issue