about summary refs log tree commit diff
path: root/src/entities/character.rs
blob: 3e8336b129ff3a5b52a5c858b5f73be05e2784b1 (plain) (blame)
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
use crate::display;
use crate::entities::item::Item;
use crate::types::{Position, Speed};
use std::io::{self, Write};

const DEFAULT_SPEED: Speed = Speed(100);

entity! {
    pub struct Character {
        pub o_name: Option<String>,
        pub inventory: Vec<Box<Item>>,
    }
}

static_description!(Character, "yourself");

impl Character {
    pub fn new() -> Character {
        Character {
            id: None,
            position: Position { x: 0, y: 0 },
            o_name: None,
            inventory: Vec::new(),
        }
    }

    pub fn speed(&self) -> Speed {
        Speed(100)
    }

    pub fn damage(&self) -> u16 {
        // TODO
        1
    }

    pub fn name(&self) -> &str {
        self.o_name
            .as_ref()
            .expect("Character name not initialized")
    }

    pub fn set_name(&mut self, name: String) {
        self.o_name = Some(name);
    }
}

impl display::Draw for Character {
    fn do_draw(&self, out: &mut dyn Write) -> io::Result<()> {
        write!(out, "@")
    }
}