blademaster/types/
player.rs1use std::borrow::Cow;
2
3use tui::{
4 style::{Color, Style},
5 widgets::Text,
6};
7
8pub struct Player {
9 x: f64,
10 y: f64,
11 lvl: u32,
12 hp: (i32, u32),
13 xp: (i32, u32),
14}
15
16impl Player {
17 pub fn new(x: f64, y: f64) -> Self {
18 Self {
19 x,
20 y,
21 lvl: 1,
22 hp: (10, 10),
23 xp: (10, 10),
24 }
25 }
26
27 pub fn list<'a>(&self) -> Vec<Text<'a>> {
28 let mut list = Vec::with_capacity(3);
29 list.push(Text::Styled(
30 Cow::from(format!("Level: {}", self.lvl)),
31 Style::default().fg(Color::Blue),
32 ));
33 list.push(Text::Styled(
34 Cow::from(format!("HP: {} / {}", self.hp.0, self.hp.1)),
35 Style::default().fg(Color::Blue),
36 ));
37 list.push(Text::Styled(
38 Cow::from(format!("XP: {} / {}", self.xp.0, self.xp.1)),
39 Style::default().fg(Color::Blue),
40 ));
41 list
42 }
43
44 pub fn x(&self) -> f64 {
45 self.x
46 }
47 pub fn y(&self) -> f64 {
48 self.y
49 }
50}