48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
|
use std::{
|
||
|
io::{self, Stdout, Write},
|
||
|
time::Duration,
|
||
|
};
|
||
|
|
||
|
use crossterm::style::style;
|
||
|
pub use crossterm::{
|
||
|
cursor,
|
||
|
event::{self, Event, KeyCode, KeyEvent},
|
||
|
execute, queue, style,
|
||
|
terminal::{self, ClearType},
|
||
|
Command, Result,
|
||
|
};
|
||
|
|
||
|
const dungeon: [[i32; 17]; 5] = [
|
||
|
[0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0,],
|
||
|
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,],
|
||
|
[1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0,],
|
||
|
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,],
|
||
|
[0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0,],
|
||
|
];
|
||
|
|
||
|
fn main() -> Result<()> {
|
||
|
let mut stdout = io::stdout();
|
||
|
execute!(stdout, terminal::EnterAlternateScreen)?;
|
||
|
terminal::enable_raw_mode();
|
||
|
execute!(stdout, cursor::MoveTo(0, 0));
|
||
|
for row in (0..dungeon.len()) {
|
||
|
for cell in dungeon[row] {
|
||
|
if (row % 2 == 0) {
|
||
|
execute!(stdout, style::SetForegroundColor(style::Color::Red));
|
||
|
} else {
|
||
|
execute!(stdout, style::SetForegroundColor(style::Color::Magenta));
|
||
|
}
|
||
|
if cell == 1 {
|
||
|
execute!(stdout, style::Print('#'));
|
||
|
} else {
|
||
|
execute!(stdout, style::Print(' '));
|
||
|
}
|
||
|
}
|
||
|
execute!(stdout, cursor::MoveToNextLine(1));
|
||
|
}
|
||
|
event::read()?;
|
||
|
terminal::disable_raw_mode();
|
||
|
execute!(stdout, terminal::LeaveAlternateScreen)?;
|
||
|
Ok(())
|
||
|
}
|