refactoring 2
This commit is contained in:
parent
26700b9277
commit
f8b994e6b2
|
@ -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
|
||||||
|
|
|
@ -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<u32> = 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue