finished cli ui, end of TP
This commit is contained in:
@@ -16,6 +16,8 @@ fn main() {
|
|||||||
while playing {
|
while playing {
|
||||||
let mut message = "";
|
let mut message = "";
|
||||||
let mut user_cheated: bool = false;
|
let mut user_cheated: bool = false;
|
||||||
|
let mut game_won: bool = false;
|
||||||
|
|
||||||
match read().unwrap() {
|
match read().unwrap() {
|
||||||
Event::Key(KeyEvent {
|
Event::Key(KeyEvent {
|
||||||
code: KeyCode::Char('q'),
|
code: KeyCode::Char('q'),
|
||||||
@@ -76,13 +78,42 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if taquin_game.is_grid_done() && !user_cheated {
|
if taquin_game.is_grid_done() {
|
||||||
|
if !user_cheated {
|
||||||
message = "Yahoo! Good job!";
|
message = "Yahoo! Good job!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game_won = true;
|
||||||
|
}
|
||||||
|
|
||||||
draw_game(&taquin_game);
|
draw_game(&taquin_game);
|
||||||
print!("{}\r\n", message);
|
print!("{}\r\n", message);
|
||||||
let _ = io::stdout().flush();
|
let _ = io::stdout().flush();
|
||||||
|
|
||||||
|
if game_won {
|
||||||
|
print!("Press 'R' to start a new game, 'Q' to quit.");
|
||||||
|
let _ = io::stdout().flush();
|
||||||
|
let mut good_choice = false;
|
||||||
|
while !good_choice {
|
||||||
|
match read().unwrap() {
|
||||||
|
Event::Key(KeyEvent {
|
||||||
|
code: KeyCode::Char('q'),
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
|
playing = false;
|
||||||
|
good_choice = true;
|
||||||
|
}
|
||||||
|
Event::Key(KeyEvent {
|
||||||
|
code: KeyCode::Char('r'),
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
|
taquin_game.init_grid();
|
||||||
|
good_choice = true;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user