diff --git a/Arch.md b/Arch.md new file mode 100644 index 0000000..c64fe7e --- /dev/null +++ b/Arch.md @@ -0,0 +1,46 @@ +- Use ECS? + +- World +- Creatures + - Human + - Animal + - Monster +- Sites + - Towns + - Dungeons + - Caves + - Ruins + - Tavern +- Items + - Weapons + - Armor + - Food + - Potions + - Scrolls + - Books + - Gems + - Artifacts + + +- Creatures need agency + - Need to be able to move around + - Need to be able to interact with the world + - Need to be able to interact with other creatures + - Need to be able to interact with items + - Need to be able to interact with sites + - Need an inventory +- Sites + - Need an inventory +- Items + - Need to know their history + + +## Step System + +- For each creature + - create clone + - run creature step + - return list of actions + - run actions + - update creature + \ No newline at end of file diff --git a/src/game.rs b/src/game.rs new file mode 100644 index 0000000..b906c24 --- /dev/null +++ b/src/game.rs @@ -0,0 +1,58 @@ +use crate::state::GameState; + +/** + * This is the main game struct. + * It takes care of stepping the game forward. + * Changes are made to the state struct through the step function. + */ +pub struct Game { + pub state: GameState, +} + +impl Game { + pub fn new(state: GameState) -> Game { + Game { + state: state, + } + } + + pub fn step(&mut self) { + // get list of all people ids + let ids: Vec = self.state.people.keys().map(|id| *id).collect(); + + // step each person + for id in ids { + let person = self.state.people.get_mut(&id); + match person { + Some(p) => { + let mut p = p.clone(); + p.step(&mut self.state); + self.state.people.insert(id, p); + }, + // person is dead + None => (), + } + + } + // increment time + self.state.time.time += 1; + } + +} + +#[cfg(test)] +mod tests { + + use crate::world::World; + + use super::*; + + #[test] + fn test_step() { + let state = GameState::new(World::new(100)); + let mut game = Game::new(state); + game.step(); + assert_eq!(game.state.time.time, 1); + } + +} \ No newline at end of file