add test & fix bug
This commit is contained in:
parent
6aee9d974f
commit
7b0eaf6640
24
src/level.rs
24
src/level.rs
|
@ -23,9 +23,9 @@ pub struct Level {
|
|||
pub(crate) discovered: [[bool; LEVEL_HEIGHT]; LEVEL_WIDTH],
|
||||
pub(crate) monsters: Vec<Monster>,
|
||||
pub(crate) artifacts: Vec<Box<dyn Artifact>>,
|
||||
/// the position of the start in the level (eiter stair up or start point)
|
||||
/// the position of the start in the level (either stair up or start point)
|
||||
pub(crate) start: (usize, usize),
|
||||
/// the position of the end in the level (eiter stair down or end point)
|
||||
/// the position of the end in the level (either stair down or end point)
|
||||
pub(crate) end: (usize, usize),
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ impl Level {
|
|||
}
|
||||
for (index, a) in &mut self.artifacts.iter().enumerate() {
|
||||
if a.get_immutable_position() == position {
|
||||
self.monsters.remove(index);
|
||||
self.artifacts.remove(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -304,3 +304,21 @@ fn test_monster_can_be_removed() {
|
|||
|
||||
assert!(level.get_element(10, 10).1.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_artefact_can_be_removed() {
|
||||
let mut l = Level::new(0);
|
||||
let p = Position::new(0, 10, 10);
|
||||
l.discover(&p);
|
||||
assert_eq!(l.get_element(10, 10).0.unwrap(), StructureElement::Floor);
|
||||
assert!(l.get_element(10, 10).2.is_none());
|
||||
|
||||
let a = Chest::new(Position::new(0, 10, 10));
|
||||
assert_eq!(l.add_artifact(a), Ok(()));
|
||||
|
||||
l.remove_artifact(&Position::new(0, 10, 10)).expect("Foo");
|
||||
|
||||
let elem = l.get_element(10, 10);
|
||||
assert_eq!(elem.0.unwrap(), StructureElement::Floor);
|
||||
assert!(elem.2.is_none());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue