make size of levels variable

This commit is contained in:
2024-10-23 15:54:33 +02:00
parent 5111fec1fa
commit 6f4c37728f
3 changed files with 33 additions and 23 deletions

View File

@@ -33,6 +33,9 @@ mod position;
/// length of a game frame in ms
pub const FRAME_LENGTH: u64 = 100;
pub const MIN_WIDTH: u16 = 120;
pub const MIN_HEIGHT: u16 = 30;
//
fn main() -> Result<()> {
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)
// 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()
.title("Info")
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::White))
.border_type(BorderType::Rounded)
.style(Style::default().bg(Color::Black));
let paragraph = Paragraph::new("Terminal needs to be at leas 80x25!")
.block(block)
.wrap(Wrap { trim: true });
let paragraph = Paragraph::new(format!(
"Terminal needs to be at leas {}x{}!",
MIN_WIDTH, MIN_HEIGHT
))
.block(block)
.wrap(Wrap { trim: true });
frame.render_widget(paragraph, area);
return;
}
if area.width > 80 {
area.x = (area.width - 80) / 2;
area.width = 80;
if area.width > MIN_WIDTH {
area.x = (area.width - MIN_WIDTH) / 2;
area.width = MIN_WIDTH;
}
if area.height > 25 {
area.y = (area.height - 25) / 2;
area.height = 25;
if area.height > MIN_HEIGHT {
area.y = (area.height - level::LEVEL_HEIGHT as u16) / 2;
area.height = level::LEVEL_HEIGHT as u16;
}
let map_area = Rect {
@@ -86,10 +92,10 @@ fn main() -> Result<()> {
frame.render_stateful_widget(LevelWidget {}, map_area, &mut game);
let stats_area = Rect {
x: area.x + 50,
x: area.x + map_area.width,
y: area.y,
width: 30,
height: 15,
width: MIN_WIDTH - map_area.width,
height: map_area.height / 2 + 1,
};
let block = Block::default()
.title(
@@ -117,10 +123,10 @@ fn main() -> Result<()> {
stats_area,
);
let messages_area = Rect {
x: area.x + 50,
y: area.y + 15,
width: 30,
height: 10,
x: area.x + map_area.width,
y: area.y + map_area.height / 2 + 1,
width: MIN_WIDTH - map_area.width,
height: map_area.height / 2,
};
// Display the latest messages from the game to the user
let block = Block::default()