extract minimal room size as constant

This commit is contained in:
Joachim Lusiardi 2024-11-03 10:32:04 +01:00
parent df80dfdd8a
commit 5311f56ca0
2 changed files with 9 additions and 3 deletions

View File

@ -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;

View File

@ -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);