diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-09-12 01:04:48 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-09-12 01:04:48 +0200 |
commit | 1a1df3f1613a5c8814c6eb6d3d91744cca63cf3b (patch) | |
tree | 584b02079796dcef7152fcdcb650804ce0feea62 /src/main.rs | |
download | rs2048-1a1df3f1613a5c8814c6eb6d3d91744cca63cf3b.tar.xz |
Initial commit
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a7b3e59 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,31 @@ +pub mod display; +pub mod game; + +use game::{Board, Dir::*, Pos}; + +fn main() { + let mut rng = rand::thread_rng(); + let getch = getch::Getch::new(); + let board = Board::new(Pos::new(4, 4)); + + board.spawn(&mut rng); + clearscreen::clear().unwrap(); + print!("{board}"); + + while let Ok(ch) = getch.getch() { + if !board.step(match ch { + b'w' => Up, + b'a' => Left, + b's' => Down, + b'd' => Right, + b'q' => break, + _ => continue, + }) { + continue; + } + + board.spawn(&mut rng); + clearscreen::clear().unwrap(); + print!("{board}"); + } +} |