move clear line function

This commit is contained in:
mii8080
2021-10-02 01:25:22 +00:00
committed by GitHub
parent 760c51b8c4
commit 53d133260f
2 changed files with 34 additions and 29 deletions

View File

@ -270,33 +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) {
if let Block::Air = rustris.game_data.field[x][y] {
air = true;
}
}
if !air {
clear_lines += 1;
for y in 0..(rustris.game_data.field_size.0) {
rustris.game_data.field[x][y] = Block::Air;
}
for x2 in (0..(rustris.game_data.field_size.1)).rev() {
if x2 < x && x2 < 20 {
for y2 in 0..(rustris.game_data.field_size.0) {
rustris.game_data.field[x2 + 1][y2] = rustris.game_data.field[x2][y2];
rustris.game_data.field[x2][y2] = Block::Air;
}
}
}
}
}
rustris.game_data.score += clear_lines * 100;
rustris.check_clear();
}
{

View File

@ -6,12 +6,43 @@ use crate::{block::Block, game_data::*, game_status::GameStatus, mino::Mino, min
#[derive(Debug)]
pub struct Rustris {
pub game_data: GameData,
pub game_status: GameStatus
pub game_status: GameStatus,
pub t_spin: bool,
}
impl Rustris {
pub fn new(game_data: GameData) -> Rustris {
Rustris { game_data, game_status: GameStatus::Playing }
Rustris { game_data, game_status: GameStatus::Playing, t_spin: false }
}
pub fn check_clear(&mut self) {
let mut clear_lines = 0;
for x in 0..(self.game_data.field_size.1) {
let mut air = false;
for y in 0..(self.game_data.field_size.0) {
if let Block::Air = self.game_data.field[x][y] {
air = true;
}
}
if !air {
clear_lines += 1;
for y in 0..(self.game_data.field_size.0) {
self.game_data.field[x][y] = Block::Air;
}
for x2 in (0..(self.game_data.field_size.1)).rev() {
if x2 < x && x2 < 20 {
for y2 in 0..(self.game_data.field_size.0) {
self.game_data.field[x2 + 1][y2] = self.game_data.field[x2][y2];
self.game_data.field[x2][y2] = Block::Air;
}
}
}
}
}
self.game_data.score += clear_lines * 100;
}
pub fn get_next_mino(&mut self) -> Mino {