Avoid use of thread_rng
outside of main
This commit is contained in:
parent
aa7361df6b
commit
dd584d2d19
10
src/level.rs
10
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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue