Extract constants and make monsters variable per level
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -2,6 +2,12 @@ use std::io::stdout;
|
||||
use std::io::Result;
|
||||
use std::time::Instant;
|
||||
|
||||
use constants::FRAME_LENGTH;
|
||||
use constants::LEVELS;
|
||||
use constants::LEVEL_HEIGHT;
|
||||
use constants::LEVEL_WIDTH;
|
||||
use constants::MIN_HEIGHT;
|
||||
use constants::MIN_WIDTH;
|
||||
use crossterm::{
|
||||
event::{self, KeyCode, KeyEventKind},
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
@@ -22,6 +28,7 @@ use crate::player::Player;
|
||||
use crate::position::HasPosition;
|
||||
|
||||
mod artifacts;
|
||||
mod constants;
|
||||
mod game;
|
||||
mod level;
|
||||
mod level_generator;
|
||||
@@ -30,12 +37,6 @@ mod monster;
|
||||
mod player;
|
||||
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));
|
||||
@@ -79,15 +80,15 @@ fn main() -> Result<()> {
|
||||
area.width = MIN_WIDTH;
|
||||
}
|
||||
if area.height > MIN_HEIGHT {
|
||||
area.y = (area.height - level::LEVEL_HEIGHT as u16) / 2;
|
||||
area.height = level::LEVEL_HEIGHT as u16;
|
||||
area.y = (area.height - LEVEL_HEIGHT as u16) / 2;
|
||||
area.height = LEVEL_HEIGHT as u16;
|
||||
}
|
||||
|
||||
let map_area = Rect {
|
||||
x: area.x,
|
||||
y: area.y,
|
||||
width: level::LEVEL_WIDTH as u16,
|
||||
height: level::LEVEL_HEIGHT as u16,
|
||||
width: LEVEL_WIDTH as u16,
|
||||
height: LEVEL_HEIGHT as u16,
|
||||
};
|
||||
frame.render_stateful_widget(LevelWidget {}, map_area, &mut game);
|
||||
|
||||
@@ -109,12 +110,13 @@ fn main() -> Result<()> {
|
||||
.style(Style::default().bg(Color::Blue));
|
||||
frame.render_widget(
|
||||
Paragraph::new(format!(
|
||||
"Health: {}/{}\nExp: {}\nGold: {}\nLevel: {}\nInventory: {}/{}",
|
||||
"Health: {} of {}\nExp: {}\nGold: {}\nLevel: {} of {}\nInventory used: {} of {}",
|
||||
game.get_player().get_life(),
|
||||
game.get_player().get_max_life(),
|
||||
game.get_player().get_experience(),
|
||||
game.get_player().get_gold(),
|
||||
game.get_player().get_immutable_position().get_level() + 1,
|
||||
LEVELS,
|
||||
game.get_player().inventory_size().0,
|
||||
game.get_player().inventory_size().1,
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user