39 lines
950 B
Rust
39 lines
950 B
Rust
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||
|
enum LevelElement {
|
||
|
Wall,
|
||
|
Floor,
|
||
|
StairDown,
|
||
|
StairUp,
|
||
|
}
|
||
|
|
||
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||
|
pub struct Level {
|
||
|
structure: [[LevelElement; 25]; 80],
|
||
|
}
|
||
|
|
||
|
impl Level {
|
||
|
pub fn new() -> Level {
|
||
|
let mut s = [[LevelElement::Wall; 25]; 80];
|
||
|
s[4][4] = LevelElement::StairDown;
|
||
|
s[75][20] = LevelElement::StairUp;
|
||
|
Level {
|
||
|
structure: s
|
||
|
}
|
||
|
}
|
||
|
pub fn get_element(&self, x: usize, y: usize) -> Option<LevelElement> {
|
||
|
if x >= 80 || y >= 25 {
|
||
|
return None;
|
||
|
}
|
||
|
Some(self.structure[x][y])
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
fn test_get_element() {
|
||
|
let l = Level::new();
|
||
|
assert_eq!(l.get_element(0, 0).unwrap(), LevelElement::Wall);
|
||
|
assert_eq!(l.get_element(4, 4).unwrap(), LevelElement::StairDown);
|
||
|
assert_eq!(l.get_element(79, 24).unwrap(), LevelElement::Wall);
|
||
|
assert_eq!(l.get_element(80, 25), None);
|
||
|
}
|