clige_rs/game/object/
mod.rs

1//! Module for game objects.
2
3mod entity;
4mod item;
5mod level;
6mod door;
7
8pub use entity::*;
9pub use item::*;
10pub use level::*;
11pub use door::*;
12
13use crate::error::GameError;
14
15/// Possible actions player can take on an `Object`.
16#[derive(PartialEq, Debug)]
17pub enum Action {
18    Help,
19    Attack,
20    Throw,
21    Take,
22    Eat,
23    Enter,
24    Equip,
25    Back,
26}
27
28/// What the parent of an `Object` should do with it, after it's done handling logic.
29pub enum Message {
30    Keep(Box<dyn Object>),
31    Remove,
32    Equip(Box<Weapon>),
33    ChangeLocation(*mut Level)
34}
35
36/// All game objects must implement this trait.
37///
38/// Each `Object` can be drawn on screen and can be interacted with.
39pub trait Object {
40    /// Handles interactions.
41    fn handle(
42        self: Box<Self>,
43        sender: &mut dyn Entity,
44        action: Action,
45    ) -> Result<Message, GameError>;
46
47    /// Prints itself to `stdout`.
48    fn draw(&self);
49}