Monsters can move

This commit is contained in:
Joachim Lusiardi 2023-12-03 09:36:58 +01:00
parent 1ba1ed7de4
commit 209a277684
1 changed files with 21 additions and 1 deletions

View File

@ -169,7 +169,7 @@ fn test_discover_get_monster() {
m.get_position().set(0, 10, 10);
assert_eq!(l.add_monster(m), Ok(()));
let elem =l.get_element(10, 10);
let elem = l.get_element(10, 10);
assert_eq!(elem.0.unwrap(), StructureElement::Floor);
assert!(elem.1.is_some());
let m = elem.1.unwrap();
@ -178,3 +178,23 @@ fn test_discover_get_monster() {
m.decrease_life(2);
assert_eq!(l.get_element(10, 10).1.unwrap().get_life(), 21);
}
#[test]
fn test_discover_get_monster_can_move() {
let mut l = Level::new(0);
let p = Position::new(0, 10, 10);
l.discover(&p);
let mut m = Monster::new(23);
m.get_position().set(0, 10, 10);
l.add_monster(m).expect("Panic because of");
let m = l.get_element(10, 10).1.unwrap();
m.get_position().change(1, 1);
let m = l.get_element(10, 10).1;
assert!(m.is_none());
let m = l.get_element(11, 11).1;
assert!(m.is_some());
assert_eq!(m.unwrap().get_life(), 23);
}