diff options
-rw-r--r-- | src/main.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 11b0dbf..63089ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -297,6 +297,7 @@ struct Game { bag: Bag, figure_next: [Figure; NEXT_COUNT], figure_on_hold: Figure, + lines: usize, } impl Default for Game { @@ -334,6 +335,7 @@ impl Default for Game { bag, figure_next, figure_on_hold, + lines: 0, } } } @@ -354,6 +356,7 @@ impl Game { (self.x, self.y) = (3, 17); self.fall_timeout = Timeout::from_duration(std::time::Duration::from_millis(500)); self.place_timeout = None; + self.lines = 0; } fn place_figure(&mut self) { @@ -367,6 +370,7 @@ impl Game { for line in 0..FIELD_ROWS - 1 { while self.field.is_line_complete(line) { self.field.kill_line(line); + self.lines += 1; } } self.stop_place_timeout(); @@ -541,9 +545,10 @@ struct Tui { } impl Tui { - fn display_hold(&self, figure: &Figure, y_global: usize) { + fn display_hold_and_scores(&self, figure: &Figure, lines: usize, y_global: usize) { let offset = DISPLAY_HOLD_OFFSET_DOWN; let at_figure = y_global >= (1 + offset) && y_global < FIGURE_SIZE_ROWS + (1 + offset); + let at_lines_count = y_global == FIELD_ROWS_VISIBLE - 2; if y_global == offset { print!(" Hold: "); } else if at_figure { @@ -558,6 +563,9 @@ impl Tui { } } print!(" "); + } else if at_lines_count { + let lines_clamped = std::cmp::min(99999999, lines); + print!(" {lines_clamped:08} "); } else { print!(" "); } @@ -617,7 +625,7 @@ impl Tui { field.render(&ghost, game.x, y_ghost); field.render(&game.figure, game.x, game.y); for y in 0..FIELD_ROWS_VISIBLE { - self.display_hold(&game.figure_on_hold, y); + self.display_hold_and_scores(&game.figure_on_hold, game.lines, y); self.display_field(&field, y); self.display_next(&game.figure_next, y); print!("\r\x1b[1B"); |