it works
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ impl Board {
|
||||
lines_cleared += 1;
|
||||
} else {
|
||||
new_grid[new_y] = self.grid[y].clone();
|
||||
new_y -= 1;
|
||||
new_y = new_y.wrapping_sub(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-12
@@ -32,6 +32,7 @@ pub struct Game {
|
||||
drop_interval: u64,
|
||||
last_drop: u64,
|
||||
status: GameStatus,
|
||||
_input_handler: input::InputHandler,
|
||||
input_rx: mpsc::Receiver<Input>,
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ impl Game {
|
||||
pub fn new() -> io::Result<Game> {
|
||||
let current_piece = Piece::new(PieceType::random());
|
||||
let next_piece = Piece::new(PieceType::random());
|
||||
let (_, input_rx) = input::InputHandler::new();
|
||||
let (_input_handler, input_rx) = input::InputHandler::new();
|
||||
|
||||
Ok(Game {
|
||||
board: Board::new(),
|
||||
@@ -52,6 +53,7 @@ impl Game {
|
||||
drop_interval: DROP_INTERVAL,
|
||||
last_drop: 0,
|
||||
status: GameStatus::Running,
|
||||
_input_handler,
|
||||
input_rx,
|
||||
})
|
||||
}
|
||||
@@ -87,9 +89,9 @@ impl Game {
|
||||
self.render(&mut stdout)?;
|
||||
|
||||
// Небольшая пауза для контроля FPS
|
||||
let elapsed = last_tick.duration_since(now).as_millis() as u64;
|
||||
if elapsed < 1000 / FPS {
|
||||
std::thread::sleep(Duration::from_millis(1000 / FPS - elapsed));
|
||||
let frame_time = Instant::now().duration_since(last_tick).as_millis() as u64;
|
||||
if frame_time < 1000 / FPS {
|
||||
std::thread::sleep(Duration::from_millis(1000 / FPS - frame_time));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,12 +237,12 @@ impl Game {
|
||||
|
||||
/// Рендер игры
|
||||
fn render(&self, stdout: &mut Stdout) -> io::Result<()> {
|
||||
stdout.write_all(b"\x1B[2J")?; // Очистка экрана
|
||||
stdout.write_all(b"\x1B[H")?; // Курсор в начало экрана
|
||||
|
||||
// Заголовок
|
||||
writeln!(
|
||||
write!(
|
||||
stdout,
|
||||
"Tetris - Score: {} - Lines: {} - Level: {}",
|
||||
"Tetris - Score: {} - Lines: {} - Level: {}\x1B[K\r\n",
|
||||
self.score, self.lines_cleared, self.level
|
||||
)?;
|
||||
|
||||
@@ -264,7 +266,7 @@ impl Game {
|
||||
}
|
||||
}
|
||||
}
|
||||
stdout.write_all(b"|\n")?;
|
||||
stdout.write_all(b"|\x1B[K\r\n")?;
|
||||
}
|
||||
|
||||
// Нижняя граница
|
||||
@@ -272,14 +274,14 @@ impl Game {
|
||||
for _ in 0..board::BOARD_WIDTH {
|
||||
stdout.write_all(b"-")?;
|
||||
}
|
||||
stdout.write_all(b"+\n")?;
|
||||
stdout.write_all(b"+\x1B[K\r\n")?;
|
||||
|
||||
// Следующая фигура
|
||||
writeln!(stdout, "Next:")?;
|
||||
write!(stdout, "Next:\x1B[K\r\n")?;
|
||||
self.render_preview(stdout, &self.next_piece)?;
|
||||
|
||||
// Управление
|
||||
writeln!(stdout, "Controls: Arrow Keys - Move | Space - Drop | Q - Quit")?;
|
||||
write!(stdout, "Controls: Arrow Keys - Move | Space - Drop | Q - Quit\x1B[K\r\n")?;
|
||||
|
||||
stdout.flush()?;
|
||||
Ok(())
|
||||
@@ -305,7 +307,7 @@ impl Game {
|
||||
stdout.write_all(b" ")?;
|
||||
}
|
||||
}
|
||||
stdout.write_all(b"\n")?;
|
||||
stdout.write_all(b"\x1B[K\r\n")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user