Open milewski opened 1 year ago
game.field()
doesn't contain the current tetrimino. If you want to know the field with the current tetrimino, use the following code:
fn field_with_current_tetrimino(game: &Game) -> Vec<Vec<Cell>> {
let mut field = game.field().as_vec().to_owned();
for (x, y) in game.tetrimino().blocks() {
if x < 0 || y < 0 {
continue;
}
field[y as usize][x as usize] = Cell::Block(game.tetrimino().kind());
}
field
}
loop {
...
game.soft_drop();
println!("{:?}", field_with_current_tetrimino(&game));
}
The second example fails because game.save()
saves the current tetrimino and changes it to the next one. Since the first tetrimino is right below, the next tetrimino can't go down, and it is saved outside, which halts the game.
Trying to figure out how to "tick" the game.. looks like it is done via the
soft_drop()
however, whenever calling it either field doesn't gets updated / or when callinggame.save()
theis_end
is set to true which halts the game ...