138 lines
4.2 KiB
Rust
138 lines
4.2 KiB
Rust
use std::{collections::HashMap, ops::RangeInclusive};
|
|
|
|
use crate::{monster::MonsterTypes, room::RoomType};
|
|
|
|
/// the number of rooms in vertical direction
|
|
pub const ROOMS_HORIZONTAL: usize = 8;
|
|
/// the number of rooms in horizontal direction
|
|
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;
|
|
/// 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 = 4;
|
|
|
|
/// length of a game frame in ms
|
|
pub const FRAME_LENGTH: u64 = 100;
|
|
|
|
/// define the minimum width of a terminal to run the game, must be at least the level width plus some space for stats and messages
|
|
pub const MIN_WIDTH: u16 = 120;
|
|
/// define the minimum height of a terminal to run the game, this must be at least the level height!
|
|
pub const MIN_HEIGHT: u16 = LEVEL_HEIGHT as u16;
|
|
|
|
/// the calculated width of a level
|
|
pub const LEVEL_WIDTH: usize = 1 + ROOMS_HORIZONTAL * ROOM_WIDTH;
|
|
/// the calculated height of a level
|
|
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 = [
|
|
// 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),
|
|
],
|
|
// level 4
|
|
vec![
|
|
(MonsterTypes::Orc, 34),
|
|
(MonsterTypes::Skeleton, 33),
|
|
(MonsterTypes::Snake, 33),
|
|
],
|
|
];
|
|
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));
|
|
sum += monster.1;
|
|
}
|
|
if sum != 100 {
|
|
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, 50),
|
|
(RoomType::ArtifactRoom, 10),
|
|
(RoomType::MonsterRoom, 20),
|
|
(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::BasicRoom, 25),
|
|
(RoomType::MonsterRoom, 25),
|
|
],
|
|
// level 4
|
|
vec![
|
|
(RoomType::BasicRoom, 33),
|
|
(RoomType::MonsterRoom, 33),
|
|
(RoomType::ArtifactRoom, 34),
|
|
],
|
|
];
|
|
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);
|
|
}
|
|
result
|
|
}
|