diff options
author | Iago Garrido <iago086@gmail.com> | 2019-11-12 14:28:58 +0100 |
---|---|---|
committer | Iago Garrido <iago086@gmail.com> | 2019-11-12 14:28:58 +0100 |
commit | d84906ec92e45ed2cf2611c2f646d72ef5f1bb64 (patch) | |
tree | 0086b9f87fcef11fe795fb624164c0f33b9b00cf /src/main.rs | |
parent | e58d24c9a945b29ca9a4fd18647749941ba5e48b (diff) |
add state
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 91 |
1 files changed, 24 insertions, 67 deletions
diff --git a/src/main.rs b/src/main.rs index 06fcd0f..8662438 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,86 +6,41 @@ extern crate text_io; mod character; mod computer; +mod state; mod world; -use std::env; use character::Player; use character::Character; -use computer::Enemy; -use pancurses::{Window, initscr, endwin, Input, noecho}; -use world::{Dungeon, Level, Generable, TileType}; - -fn tile_to_str(tile: &TileType) -> &str { - match tile { - TileType::Floor => ".", - TileType::Wall => "#", - TileType::Empty => " ", - TileType::StairsDown => ">", - TileType::StairsUp => "<", - TileType::Character => "@", - _ => "?" - } -} - -fn draw_block(window: &Window, block: &TileType) { - window.printw(tile_to_str(block)); -} - -fn render_level(window: &Window, level: &Level) { - let grid = level.to_tilegrid().unwrap(); - - for (linenum, line) in grid.raw_data().iter().enumerate() { - for block in line.iter() { - draw_block(&window, block); - } - window.mv(linenum as i32, 0); - } -} - -fn debug_level(level: Level) { - let grid = level.to_tilegrid().unwrap(); - - for line in grid.raw_data().iter() { - for block in line.iter() { - print!("{}", tile_to_str(block)); - } - print!("\n"); - } -} +use pancurses::{ + initscr, + endwin, + Input +}; +use state::State; +use world::Dungeon; fn main() { - let mut level = 0; - let mut dungeon = Dungeon::new(80, 24, 5); - dungeon.generate(); - - let start_location = dungeon.levels[0].get_start_point(); - - let mut character: Character = Character::new( - "Kshar".to_string(), - "Warror".to_string(), - 30, - 10, - 10, - 20, - start_location + let mut state = State::new( + Character::new( + "Kshar".to_string(), + "Warror".to_string(), + 30, + 10, + 10, + 20, + ), + Dungeon::new(80, 24, 5), ); - character.place(start_location); + + state.init(); // Dump the whole dungeon structure in terminal for debugging - match env::var("DEBUG") { - Ok(_) => { - for l in dungeon.levels { - debug_level(l); - } - return - }, - Err(_) => () - }; + state.debug(); let window = initscr(); - render_level(&window, &dungeon.levels[0]); + state.render_level(&window); loop { // update actors @@ -106,4 +61,6 @@ fn main() { } } endwin(); + + println!("You quit with {} gold pieces", state.character.get_gold()) } |