diff --git a/src/level.rs b/src/level.rs index 1d3e1e9..604d59a 100644 --- a/src/level.rs +++ b/src/level.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use pancurses::Window; -use rand::{thread_rng, Rng}; +use rand::Rng; use specs::prelude::*; use crate::{ @@ -79,15 +79,15 @@ impl DungeonLevel { } /// Creates a new level and registers it with the given world. - pub fn generate_level(world: &mut World) -> LevelExits { - let level = rooms::generate_level(100, &mut thread_rng(), 1, 1); + pub fn generate_level(world: &mut World, rng: &mut impl Rng) -> LevelExits { + let level = rooms::generate_level(100, rng, 1, 1); world.insert(level.clone()); // inefficient but whatever // Spawn some zombies in the world. for _ in 0..20 { let (x, y) = ( - thread_rng().gen_range(0..LEVEL_SIZE.0 as _), - thread_rng().gen_range(0..LEVEL_SIZE.1 as _), + rng.gen_range(0..LEVEL_SIZE.0 as _), + rng.gen_range(0..LEVEL_SIZE.1 as _), ); if level.tile(x, y).is_navigable() { world diff --git a/src/main.rs b/src/main.rs index 7560ab6..163077c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use level::DungeonLevel; use pancurses::{endwin, initscr, noecho, Window}; use player::player_turn; +use rand::thread_rng; use specs::prelude::*; use systems::{MobSystem, TimeSystem}; @@ -20,7 +21,7 @@ fn main() { register_all(&mut world); - let level = DungeonLevel::generate_level(&mut world); + let level = DungeonLevel::generate_level(&mut world, &mut thread_rng()); let spawn_pos = level.upstairs[0]; world.insert(level);