make size of levels variable
This commit is contained in:
parent
5111fec1fa
commit
6f4c37728f
|
@ -6,6 +6,10 @@ use rand::Rng;
|
||||||
use crate::artifacts::Artifact;
|
use crate::artifacts::Artifact;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use crate::artifacts::{Chest, Potion};
|
use crate::artifacts::{Chest, Potion};
|
||||||
|
use crate::level_generator::ROOMS_HORIZONTAL;
|
||||||
|
use crate::level_generator::ROOMS_VERTICAL;
|
||||||
|
use crate::level_generator::ROOM_HEIGHT;
|
||||||
|
use crate::level_generator::ROOM_WIDTH;
|
||||||
use crate::monster::Monster;
|
use crate::monster::Monster;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use crate::monster::{Orc, Rat};
|
use crate::monster::{Orc, Rat};
|
||||||
|
@ -13,8 +17,8 @@ use crate::player::Player;
|
||||||
use crate::position::HasPosition;
|
use crate::position::HasPosition;
|
||||||
use crate::position::Position;
|
use crate::position::Position;
|
||||||
|
|
||||||
pub const LEVEL_WIDTH: usize = 50;
|
pub const LEVEL_WIDTH: usize = 1 + ROOMS_VERTICAL * ROOM_WIDTH;
|
||||||
pub const LEVEL_HEIGHT: usize = 25;
|
pub const LEVEL_HEIGHT: usize = 1 + ROOMS_HORIZONTAL * ROOM_HEIGHT;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub enum StructureElement {
|
pub enum StructureElement {
|
||||||
|
|
|
@ -14,11 +14,11 @@ use crate::level::{Level, StructureElement};
|
||||||
use crate::monster::{Monster, Orc, Rat, Snake};
|
use crate::monster::{Monster, Orc, Rat, Snake};
|
||||||
use crate::position::Position;
|
use crate::position::Position;
|
||||||
|
|
||||||
const ROOMS_VERTICAL: usize = 7;
|
pub const ROOMS_VERTICAL: usize = 9;
|
||||||
const ROOMS_HORIZONTAL: usize = 4;
|
pub const ROOMS_HORIZONTAL: usize = 7;
|
||||||
|
|
||||||
const ROOM_WIDTH: usize = 7;
|
pub const ROOM_WIDTH: usize = 7;
|
||||||
const ROOM_HEIGHT: usize = 6;
|
pub const ROOM_HEIGHT: usize = 6;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
enum RoomType {
|
enum RoomType {
|
||||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -33,6 +33,9 @@ mod position;
|
||||||
/// length of a game frame in ms
|
/// length of a game frame in ms
|
||||||
pub const FRAME_LENGTH: u64 = 100;
|
pub const FRAME_LENGTH: u64 = 100;
|
||||||
|
|
||||||
|
pub const MIN_WIDTH: u16 = 120;
|
||||||
|
pub const MIN_HEIGHT: u16 = 30;
|
||||||
|
|
||||||
//
|
//
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let mut game = Game::new(Player::new(realname().as_str(), 30));
|
let mut game = Game::new(Player::new(realname().as_str(), 30));
|
||||||
|
@ -54,27 +57,30 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
// don't draw stuff except an info box if the terminal is too small (less than 80x25)
|
// don't draw stuff except an info box if the terminal is too small (less than 80x25)
|
||||||
// to prevent the read drawing code from crashing the game.
|
// to prevent the read drawing code from crashing the game.
|
||||||
if area.width < 80 || area.height < 25 {
|
if area.width < MIN_WIDTH || area.height < MIN_HEIGHT {
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
.title("Info")
|
.title("Info")
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_style(Style::default().fg(Color::White))
|
.border_style(Style::default().fg(Color::White))
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.style(Style::default().bg(Color::Black));
|
.style(Style::default().bg(Color::Black));
|
||||||
let paragraph = Paragraph::new("Terminal needs to be at leas 80x25!")
|
let paragraph = Paragraph::new(format!(
|
||||||
|
"Terminal needs to be at leas {}x{}!",
|
||||||
|
MIN_WIDTH, MIN_HEIGHT
|
||||||
|
))
|
||||||
.block(block)
|
.block(block)
|
||||||
.wrap(Wrap { trim: true });
|
.wrap(Wrap { trim: true });
|
||||||
frame.render_widget(paragraph, area);
|
frame.render_widget(paragraph, area);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if area.width > 80 {
|
if area.width > MIN_WIDTH {
|
||||||
area.x = (area.width - 80) / 2;
|
area.x = (area.width - MIN_WIDTH) / 2;
|
||||||
area.width = 80;
|
area.width = MIN_WIDTH;
|
||||||
}
|
}
|
||||||
if area.height > 25 {
|
if area.height > MIN_HEIGHT {
|
||||||
area.y = (area.height - 25) / 2;
|
area.y = (area.height - level::LEVEL_HEIGHT as u16) / 2;
|
||||||
area.height = 25;
|
area.height = level::LEVEL_HEIGHT as u16;
|
||||||
}
|
}
|
||||||
|
|
||||||
let map_area = Rect {
|
let map_area = Rect {
|
||||||
|
@ -86,10 +92,10 @@ fn main() -> Result<()> {
|
||||||
frame.render_stateful_widget(LevelWidget {}, map_area, &mut game);
|
frame.render_stateful_widget(LevelWidget {}, map_area, &mut game);
|
||||||
|
|
||||||
let stats_area = Rect {
|
let stats_area = Rect {
|
||||||
x: area.x + 50,
|
x: area.x + map_area.width,
|
||||||
y: area.y,
|
y: area.y,
|
||||||
width: 30,
|
width: MIN_WIDTH - map_area.width,
|
||||||
height: 15,
|
height: map_area.height / 2 + 1,
|
||||||
};
|
};
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
.title(
|
.title(
|
||||||
|
@ -117,10 +123,10 @@ fn main() -> Result<()> {
|
||||||
stats_area,
|
stats_area,
|
||||||
);
|
);
|
||||||
let messages_area = Rect {
|
let messages_area = Rect {
|
||||||
x: area.x + 50,
|
x: area.x + map_area.width,
|
||||||
y: area.y + 15,
|
y: area.y + map_area.height / 2 + 1,
|
||||||
width: 30,
|
width: MIN_WIDTH - map_area.width,
|
||||||
height: 10,
|
height: map_area.height / 2,
|
||||||
};
|
};
|
||||||
// Display the latest messages from the game to the user
|
// Display the latest messages from the game to the user
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
|
|
Loading…
Reference in New Issue