blob: cc154554cd926af3e9549b537cca559981314294 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
//! The `dungon` crate contains the core functionality for
//! interacting with a `Dungeon` and its components.
mod map;
mod pos;
pub use map::*;
pub use pos::*;
/// The `Dungeon` type represents the game state of the
/// dungeon crawler.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Dungeon {
player: Entity,
floor: Floor,
}
impl Dungeon {
/// Creates a new `Dungeon`.
///
/// # Examples
///
/// ```no_run
/// use dungeon::Dungeon;
///
/// let dungeon = Dungeon::new();
/// ```
#[must_use]
pub fn new() -> Self {
let floor = Floor::generate();
let player = Entity::player(floor.player_start());
Self { player, floor }
}
/// Creates a new `Dungeon` with a provided seed.
///
/// # Examples
///
/// ```no_run
/// use dungeon::Dungeon;
///
/// let seed = 234690523482u64;
/// let dungeon = Dungeon::new_seeded(seed);
/// ```
#[must_use]
pub fn new_seeded(seed: u64) -> Self {
let floor = Floor::generate_seeded(seed);
let player = Entity::player(floor.player_start());
Self { player, floor }
}
/// Returns a reference to the player
#[must_use]
pub fn player(&self) -> &Entity {
&self.player
}
/// Returns a mutable reference to the player
#[must_use]
pub fn player_mut(&mut self) -> &mut Entity {
&mut self.player
}
/// Returns a reference to the current floor
#[must_use]
pub fn floor(&self) -> &Floor {
&self.floor
}
/// Returns a mutable reference to the current floor
#[must_use]
pub fn floor_mut(&mut self) -> &mut Floor {
&mut self.floor
}
}
impl Default for Dungeon {
fn default() -> Self {
let floor = Floor::default();
let player = Entity::player(floor.player_start());
Self { player, floor }
}
}
|