first version of the level new generator
monsters and artefact are missing roomsize is fixed
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use std::{collections::HashMap, ops::RangeInclusive};
|
||||
|
||||
use crate::monster::MonsterTypes;
|
||||
use crate::{monster::MonsterTypes, room::RoomType};
|
||||
|
||||
|
||||
/// the number of rooms in vertical direction
|
||||
pub const ROOMS_VERTICAL: usize = 7;
|
||||
pub const ROOMS_HORIZONAL: usize = 8;
|
||||
/// the number of rooms in horizontal direction
|
||||
pub const ROOMS_HORIZONTAL: usize = 7;
|
||||
pub const ROOMS_VERTICAL: usize = 7;
|
||||
|
||||
/// the width of a room in the grid of rooms (number of characters)
|
||||
pub const ROOM_WIDTH: usize = 9;
|
||||
@@ -13,7 +14,7 @@ pub const ROOM_WIDTH: usize = 9;
|
||||
pub const ROOM_HEIGHT: usize = 6;
|
||||
|
||||
/// How many levels does the dungeon have?
|
||||
pub const LEVELS: usize = 3;
|
||||
pub const LEVELS: usize = 2;
|
||||
|
||||
/// length of a game frame in ms
|
||||
pub const FRAME_LENGTH: u64 = 100;
|
||||
@@ -24,33 +25,89 @@ pub const MIN_WIDTH: u16 = 120;
|
||||
pub const MIN_HEIGHT: u16 = LEVEL_HEIGHT as u16;
|
||||
|
||||
/// the calculated width of a level
|
||||
pub const LEVEL_WIDTH: usize = 1 + ROOMS_VERTICAL * ROOM_WIDTH;
|
||||
pub const LEVEL_WIDTH: usize = 1 + ROOMS_HORIZONAL * ROOM_WIDTH;
|
||||
/// the calculated height of a level
|
||||
pub const LEVEL_HEIGHT: usize = 1 + ROOMS_HORIZONTAL * ROOM_HEIGHT;
|
||||
pub const LEVEL_HEIGHT: usize = 1 + ROOMS_VERTICAL * ROOM_HEIGHT;
|
||||
|
||||
pub fn get_monsters_per_level() -> Vec<HashMap<MonsterTypes, std::ops::RangeInclusive<u8>>> {
|
||||
let tmp =[
|
||||
let tmp = [
|
||||
// level 1
|
||||
vec![(MonsterTypes::Rat, 50), (MonsterTypes::Spider, 50)],
|
||||
// level 2
|
||||
vec![(MonsterTypes::Rat, 50), (MonsterTypes::Snake, 50)],
|
||||
// level 3
|
||||
vec![(MonsterTypes::Orc, 34), (MonsterTypes::Skeleton, 33), (MonsterTypes::Snake, 33)],
|
||||
vec![
|
||||
(MonsterTypes::Orc, 34),
|
||||
(MonsterTypes::Skeleton, 33),
|
||||
(MonsterTypes::Snake, 33),
|
||||
],
|
||||
];
|
||||
if tmp.len() != LEVELS {
|
||||
panic!("Only {} monster sets defined for {} levels!", tmp.len(), LEVELS);
|
||||
if tmp.len() < LEVELS {
|
||||
panic!(
|
||||
"Only {} monster sets defined for {} levels!",
|
||||
tmp.len(),
|
||||
LEVELS
|
||||
);
|
||||
}
|
||||
let mut result: Vec<HashMap<MonsterTypes, std::ops::RangeInclusive<u8>>> = vec![];
|
||||
for (idx, level) in tmp.iter().enumerate() {
|
||||
let mut sum = 0;
|
||||
let mut map: HashMap<MonsterTypes, RangeInclusive<u8>> = HashMap::new();
|
||||
for monster in level {
|
||||
map.insert(monster.0, RangeInclusive::new(sum+1, sum+monster.1));
|
||||
map.insert(monster.0, RangeInclusive::new(sum + 1, sum + monster.1));
|
||||
sum += monster.1;
|
||||
|
||||
}
|
||||
if sum != 100 {
|
||||
panic!("all percentages must add to 100 (was {}) per level, error in level {}!", sum, idx+1);
|
||||
panic!(
|
||||
"all percentages must add to 100 (was {}) per level, error in level {}!",
|
||||
sum,
|
||||
idx + 1
|
||||
);
|
||||
}
|
||||
result.push(map);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
pub fn get_room_type_per_level() -> Vec<HashMap<RoomType, std::ops::RangeInclusive<u8>>> {
|
||||
let tmp = [
|
||||
// level 1
|
||||
vec![
|
||||
(RoomType::EmptyRoom, 75),
|
||||
(RoomType::MonsterRoom, 5),
|
||||
(RoomType::BasicRoom, 20),
|
||||
],
|
||||
// level 2
|
||||
vec![
|
||||
(RoomType::EmptyRoom, 50),
|
||||
(RoomType::BasicRoom, 25),
|
||||
(RoomType::MonsterRoom, 12),
|
||||
(RoomType::ArtifactRoom, 13),
|
||||
],
|
||||
// level 3
|
||||
vec![(RoomType::EmptyRoom, 50), (RoomType::MonsterRoom, 50)],
|
||||
];
|
||||
if tmp.len() < LEVELS {
|
||||
panic!(
|
||||
"Only {} room sets defined for {} levels!",
|
||||
tmp.len(),
|
||||
LEVELS
|
||||
);
|
||||
}
|
||||
let mut result: Vec<HashMap<RoomType, std::ops::RangeInclusive<u8>>> = vec![];
|
||||
for (idx, level) in tmp.iter().enumerate() {
|
||||
let mut sum = 0;
|
||||
let mut map: HashMap<RoomType, RangeInclusive<u8>> = HashMap::new();
|
||||
for room in level {
|
||||
map.insert(room.0, RangeInclusive::new(sum + 1, sum + room.1));
|
||||
sum += room.1;
|
||||
}
|
||||
if sum != 100 {
|
||||
panic!(
|
||||
"all percentages must add to 100 (was {}) per level, error in level {}!",
|
||||
sum,
|
||||
idx + 1
|
||||
);
|
||||
}
|
||||
result.push(map);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user