add score

This commit is contained in:
mii8080
2021-10-02 00:51:10 +00:00
committed by GitHub
parent bc01ee65a7
commit 760c51b8c4
3 changed files with 15 additions and 4 deletions

View File

@ -14,7 +14,8 @@ pub struct GameData {
pub mino_rotation: MinoRotation,
pub field_size: (usize, usize),
pub show_ghost: bool,
pub hold_mino: Option<Mino>
pub hold_mino: Option<Mino>,
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,
}
}
}

View File

@ -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();
}

View File

@ -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";