mirror of
https://github.com/mii443/rustris.git
synced 2025-08-22 16:25:42 +00:00
add score
This commit is contained in:
@ -14,7 +14,8 @@ pub struct GameData {
|
|||||||
pub mino_rotation: MinoRotation,
|
pub mino_rotation: MinoRotation,
|
||||||
pub field_size: (usize, usize),
|
pub field_size: (usize, usize),
|
||||||
pub show_ghost: bool,
|
pub show_ghost: bool,
|
||||||
pub hold_mino: Option<Mino>
|
pub hold_mino: Option<Mino>,
|
||||||
|
pub score: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameData {
|
impl GameData {
|
||||||
@ -91,7 +92,8 @@ impl GameData {
|
|||||||
mino_rotation: MinoRotation::Up,
|
mino_rotation: MinoRotation::Up,
|
||||||
field_size,
|
field_size,
|
||||||
show_ghost,
|
show_ghost,
|
||||||
hold_mino: None
|
hold_mino: None,
|
||||||
|
score: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
src/main.rs
11
src/main.rs
@ -270,6 +270,7 @@ fn main() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let mut rustris = rustris.lock().unwrap();
|
let mut rustris = rustris.lock().unwrap();
|
||||||
|
let mut clear_lines = 0;
|
||||||
for x in 0..(rustris.game_data.field_size.1) {
|
for x in 0..(rustris.game_data.field_size.1) {
|
||||||
let mut air = false;
|
let mut air = false;
|
||||||
for y in 0..(rustris.game_data.field_size.0) {
|
for y in 0..(rustris.game_data.field_size.0) {
|
||||||
@ -279,6 +280,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !air {
|
if !air {
|
||||||
|
clear_lines += 1;
|
||||||
for y in 0..(rustris.game_data.field_size.0) {
|
for y in 0..(rustris.game_data.field_size.0) {
|
||||||
rustris.game_data.field[x][y] = Block::Air;
|
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),
|
cursor::MoveTo(console_size.0 / 2, console_size.1 / 2),
|
||||||
Print("Game Over")
|
Print("Game Over")
|
||||||
).unwrap();
|
).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));
|
thread::sleep(Duration::from_secs(3));
|
||||||
|
|
||||||
@ -340,7 +349,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*exit_flag.lock().unwrap() = true;
|
*exit_flag.lock().unwrap() = true;
|
||||||
frame_thread.join();
|
frame_thread.join().unwrap();
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ impl Rustris {
|
|||||||
print_buffer += "\n";
|
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 }) {
|
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";
|
print_buffer += "\n";
|
||||||
|
Reference in New Issue
Block a user