-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
50 lines (39 loc) · 1.21 KB
/
main.rs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-FileCopyrightText: 2022 Julian Merkle
// SPDX-License-Identifier: GPL-3.0-only
use std::io::Read;
use mines::*;
mod mines;
mod term;
fn main() {
let term = term::FastTerm::new();
let mut stdin_iter = std::io::stdin().bytes();
let mut field = Minesweeper::new(10, 10);
term.clear();
loop {
print!("{}", field);
let byte = match stdin_iter.next() {
Some(opt) => opt.unwrap(),
None => break,
};
term.clear();
match byte {
b'w' => field.move_cursor(Direction::Up),
b's' => field.move_cursor(Direction::Down),
b'a' => field.move_cursor(Direction::Left),
b'd' => field.move_cursor(Direction::Right),
b'f' => field.toggle_marked_at_cursor(),
b' ' => match field.click() {
GameStatus::YouWin => {
println!("{}\nYou win! :-)", field);
break;
}
GameStatus::YouLose => {
println!("{}\nYou lose :-(", field);
break;
}
GameStatus::Continue => {}
},
_ => { /* Key not mapped */ }
};
}
}