This commit is contained in:
Niko Abeler 2023-01-04 14:54:57 +01:00
parent 03fae90899
commit bdcebeafa8
7 changed files with 13 additions and 51 deletions

View File

@ -1,8 +1,7 @@
use std::any::Any;
use crossterm::event::{read, Event, KeyCode};
use tui::{backend::Backend, Frame, layout::Layout};
use crate::{game::Game, person::Creature, entity::{Entity, EntityId}};
use crate::{game::Game, entity::EntityId};
/**
* |........................|

View File

@ -1,13 +1,11 @@
use std::{rc::Rc, fmt::Display};
use rand::prelude::*;
use crate::{time::Time, world::{Town, World}, generators::PersonNameGenerator, state::{GameState, Action}, entity::{Entity, Location}};
use crate::{time::Time, world::{World}, generators::PersonNameGenerator, state::{GameState, Action}, entity::{Entity, Location, EntityId}};
#[derive(Clone, Copy)]
pub enum Profession {
Peasant,
Adventurer,
Blacksmith,
}
#[derive(Clone, Copy)]
@ -21,18 +19,16 @@ pub struct Creature {
pub entity: Entity,
pub name: String,
pub birth_date: Time,
pub birth_location: Rc<Town>,
pub profession: Profession,
pub agenda: Agenda,
}
impl Creature {
pub fn new(birth_date: Time, birth_location: Rc<Town>, location: Location) -> Creature {
pub fn new(birth_date: Time, location: Location) -> Creature {
Creature {
entity: Entity { id: 0, loc: location },
name: PersonNameGenerator::name(),
birth_date: birth_date,
birth_location: birth_location,
profession: Profession::Peasant,
agenda: Agenda::Idle(0),
}
@ -102,19 +98,19 @@ impl Display for Creature {
#[cfg(test)]
mod tests {
use crate::world::{World, Structure};
use crate::world::{World, Structure, Town};
use super::*;
#[test]
fn test_person_creation() {
let person = Creature::new(Time { time: 0 }, Rc::new(Town::new()), Location{x: 0, y: 0});
let person = Creature::new(Time { time: 0 }, Location{x: 0, y: 0});
assert_ne!(person.name, "");
}
#[test]
fn test_traveling() {
let mut person = Creature::new(Time { time: 0 }, Rc::new(Town::new()), Location{x: 0, y: 0});
let mut person = Creature::new(Time { time: 0 }, Location{x: 0, y: 0});
person.agenda = Agenda::Traveling(Location{x: 10, y: 0});
person.step(&World::new(32));
assert_eq!(person.entity.loc, Location{x: 1, y: 0});
@ -122,7 +118,7 @@ mod tests {
#[test]
fn test_start_traveling() {
let mut person = Creature::new(Time { time: 0 }, Rc::new(Town::new()), Location{x: 0, y: 0});
let mut person = Creature::new(Time { time: 0 }, Location{x: 0, y: 0});
person.agenda = Agenda::Idle(0);
let mut world = World::new(32);
world.add_structure(Location{x: 10, y: 10}, Structure::Town(Rc::new(Town::new())));

View File

@ -1,6 +1,6 @@
use std::rc::Rc;
use crate::{state::{GameState, Action}, world::Town, person::Creature};
use crate::{state::{GameState, Action}, world::Town, creature::Creature};
pub struct PersonGenesis {
pub town: Rc<Town>,

View File

@ -50,7 +50,7 @@ mod tests {
use std::rc::Rc;
use crate::{world::{World, Terrain, Town}, person::{Creature, Agenda}, time::Time, entity::Location};
use crate::{world::{World, Terrain, Town}, creature::{Creature, Agenda}, time::Time, entity::Location};
use super::*;
@ -72,7 +72,6 @@ mod tests {
let mut creature = Creature::new(
Time { time: 0 },
Rc::new(Town::new()),
Location { x: 0, y: 0 }
);
creature.set_agenda(Agenda::Traveling(Location { x: 2, y: 2 }));

View File

@ -3,7 +3,7 @@ mod state;
mod events;
mod time;
mod generators;
mod person;
mod creature;
mod app;
mod entity;
mod game;
@ -13,21 +13,15 @@ use noise::{Perlin, ScalePoint, Add, NoiseFn, ScaleBias};
use noise::utils::{NoiseMapBuilder, PlaneMapBuilder};
use image::{RgbImage, Rgb};
use rand::prelude::*;
use tui::Frame;
use tui::backend::Backend;
use tui::style::{Style, Color, Modifier};
use tui::widgets::List;
use world::World;
use std::{io, thread, time::Duration};
use std::{io};
use tui::{
backend::CrosstermBackend,
widgets::{Widget, Block, Borders},
layout::{Layout, Constraint, Direction},
Terminal
};
use crossterm::{
event::{read, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
event::{DisableMouseCapture, EnableMouseCapture},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
@ -110,22 +104,6 @@ fn build_world() -> World {
world
}
fn draw_state<B: Backend>(f: &mut Frame<B>, state: &state::GameState) {
let mut items: Vec<tui::widgets::ListItem> = vec![];
for e in state.events.iter() {
items.push(tui::widgets::ListItem::new(format!("{}", e.description())));
}
let main_window = List::new(items)
.block(Block::default().title("List").borders(Borders::ALL))
.style(Style::default().fg(Color::White))
.highlight_style(Style::default().add_modifier(Modifier::ITALIC))
.highlight_symbol(">>");
f.render_widget(main_window, f.size());
}
fn main() -> Result<(), io::Error> {
// build game state
let mut world_state = state::GameState::new(build_world());
@ -166,9 +144,4 @@ fn main() -> Result<(), io::Error> {
Ok(())
// for event in &state.events {
// println!("{}", event.description());
// }
}

View File

@ -4,7 +4,7 @@ use std::rc::Rc;
use rand::prelude::*;
use crate::entity::{Location, EntityId};
use crate::person::Creature;
use crate::creature::Creature;
use crate::time::Time;
use crate::world::{World, Terrain, Town, Tavern};
use crate::events::{FoundTown, WorldGenesis, PersonGenesis, TavernBuilt};
@ -120,7 +120,6 @@ impl GameState {
town: town.clone(),
person: Creature::new(
self.time.substract_years(rng.gen_range(18..30)),
town.clone(),
self.world.get_town_location(&town)
),
})
@ -161,9 +160,6 @@ impl GameState {
#[cfg(test)]
mod tests {
use crate::person::Agenda;
use super::*;
#[test]

View File

@ -1,5 +1,4 @@
use std::{rc::Rc, collections::HashMap, fmt};
use rand::prelude::*;
use crate::{generators::TownNameGenerator, entity::Location};