From 209a277684745efc2109ca898b17908e704754ed Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Sun, 3 Dec 2023 09:36:58 +0100 Subject: [PATCH] Monsters can move --- src/level.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/level.rs b/src/level.rs index 53b00b3..279aa87 100644 --- a/src/level.rs +++ b/src/level.rs @@ -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); +}