From 5311f56ca042bd68b6931f323b57255224a47b34 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Sun, 3 Nov 2024 10:32:04 +0100 Subject: [PATCH] extract minimal room size as constant --- src/constants.rs | 6 ++++++ src/room.rs | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index e6233d0..f108f93 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -12,6 +12,12 @@ pub const ROOM_WIDTH: usize = 9; /// the height of a room in the grid of rooms (number of characters) pub const ROOM_HEIGHT: usize = 6; +// the minmal width of a room +pub const ROOM_MIN_WIDTH: usize = 4; + +// the minmal height of a room +pub const ROOM_MIN_HEIGHT: usize = 4; + /// How many levels does the dungeon have? pub const LEVELS: usize = 2; diff --git a/src/room.rs b/src/room.rs index ed10a6c..9c2afb7 100644 --- a/src/room.rs +++ b/src/room.rs @@ -4,7 +4,7 @@ use std::{ }; use crate::{ - constants::{LEVEL_HEIGHT, LEVEL_WIDTH, ROOM_HEIGHT, ROOM_WIDTH}, + constants::{LEVEL_HEIGHT, LEVEL_WIDTH, ROOM_HEIGHT, ROOM_MIN_HEIGHT, ROOM_MIN_WIDTH, ROOM_WIDTH}, level::StructureElement, }; use rand::rngs::ThreadRng; @@ -119,8 +119,8 @@ pub struct Room { impl Room { pub fn new(rng: &mut ThreadRng) -> Self { - let width = rng.gen_range(3..ROOM_WIDTH); - let height = rng.gen_range(3..ROOM_HEIGHT); + let width = rng.gen_range(ROOM_MIN_WIDTH..ROOM_WIDTH); + let height = rng.gen_range(ROOM_MIN_HEIGHT..ROOM_HEIGHT); let offset_x = rng.gen_range(0..(ROOM_WIDTH - width)); let offset_y = rng.gen_range(0..(ROOM_HEIGHT - height)); let sx = offset_x + rng.gen_range(1..width - 1);