tavern_keeper/src/site.rs

58 lines
1.0 KiB
Rust
Raw Permalink Normal View History

2023-01-04 16:52:58 +00:00
use std::fmt;
2023-01-07 09:08:42 +00:00
use crate::{entity::{Entity, Location}, generators::TownNameGenerator};
2023-01-04 16:52:58 +00:00
#[derive(Clone)]
pub struct Town {
pub name: String,
}
#[derive(Clone)]
pub struct Tavern {
pub name: String,
}
#[derive(Clone)]
pub enum Structure {
Town(Town),
Tavern(Tavern),
}
pub struct Site {
pub entity: Entity,
2023-01-07 09:08:42 +00:00
pub loc: Location,
2023-01-04 16:52:58 +00:00
pub structure: Structure,
2023-01-08 10:57:13 +00:00
pub coins: u32,
2023-01-04 16:52:58 +00:00
}
impl Town {
pub fn new() -> Town {
Town {
name: TownNameGenerator::name(),
}
}
}
impl Tavern {
pub fn new() -> Tavern {
Tavern {
name: TownNameGenerator::name(),
}
}
}
impl fmt::Display for Structure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Structure::Town(t) => write!(f, "Town: {}", t.name),
Structure::Tavern(t) => write!(f, "Tavern: {}", t.name),
}
}
}
impl fmt::Display for Site {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.structure)
}
}