diff --git a/src/game_data.rs b/src/game_data.rs index 05173a3..629cf43 100644 --- a/src/game_data.rs +++ b/src/game_data.rs @@ -14,7 +14,8 @@ pub struct GameData { pub mino_rotation: MinoRotation, pub field_size: (usize, usize), pub show_ghost: bool, - pub hold_mino: Option + pub hold_mino: Option, + pub score: i64, } impl GameData { @@ -91,7 +92,8 @@ impl GameData { mino_rotation: MinoRotation::Up, field_size, show_ghost, - hold_mino: None + hold_mino: None, + score: 0, } } } diff --git a/src/main.rs b/src/main.rs index 5bc60c0..e39fef6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -270,6 +270,7 @@ fn main() { { let mut rustris = rustris.lock().unwrap(); + let mut clear_lines = 0; for x in 0..(rustris.game_data.field_size.1) { let mut air = false; for y in 0..(rustris.game_data.field_size.0) { @@ -279,6 +280,7 @@ fn main() { } if !air { + clear_lines += 1; for y in 0..(rustris.game_data.field_size.0) { rustris.game_data.field[x][y] = Block::Air; } @@ -293,6 +295,8 @@ fn main() { } } } + + rustris.game_data.score += clear_lines * 100; } { @@ -314,6 +318,11 @@ fn main() { cursor::MoveTo(console_size.0 / 2, console_size.1 / 2), Print("Game Over") ).unwrap(); + execute!( + stdout, + cursor::MoveTo(console_size.0 / 2, console_size.1 / 2 + 1), + Print(format!("Score : {}", rustris.game_data.score)) + ).unwrap(); thread::sleep(Duration::from_secs(3)); @@ -340,7 +349,7 @@ fn main() { } *exit_flag.lock().unwrap() = true; - frame_thread.join(); + frame_thread.join().unwrap(); main(); } diff --git a/src/rustris.rs b/src/rustris.rs index c0fc0f2..f92379b 100644 --- a/src/rustris.rs +++ b/src/rustris.rs @@ -205,7 +205,7 @@ impl Rustris { print_buffer += "\n"; } } - print_buffer += "     Z ホールド, X 左回転, C 右回転\n"; + print_buffer += &format!("     Z ホールド, X 左回転, C 右回転 score: {}\n", self.game_data.score); for _ in 0..(if (console_size.1 - print_buffer.lines().count() as u16) > 0 { console_size.1 - print_buffer.lines().count() as u16 - 1 } else { console_size.1 - print_buffer.lines().count() as u16 }) { print_buffer += "\n";