blob: a7b3e59414540c08bfa5cd43f996889a37b8d982 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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}");
}
}
|