mirror of
https://github.com/mii443/rustris.git
synced 2025-09-03 07:59:15 +00:00
move clear line function
This commit is contained in:
28
src/main.rs
28
src/main.rs
@ -270,33 +270,7 @@ fn main() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let mut rustris = rustris.lock().unwrap();
|
let mut rustris = rustris.lock().unwrap();
|
||||||
let mut clear_lines = 0;
|
rustris.check_clear();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -6,12 +6,43 @@ use crate::{block::Block, game_data::*, game_status::GameStatus, mino::Mino, min
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Rustris {
|
pub struct Rustris {
|
||||||
pub game_data: GameData,
|
pub game_data: GameData,
|
||||||
pub game_status: GameStatus
|
pub game_status: GameStatus,
|
||||||
|
pub t_spin: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rustris {
|
impl Rustris {
|
||||||
pub fn new(game_data: GameData) -> 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 {
|
pub fn get_next_mino(&mut self) -> Mino {
|
||||||
|
Reference in New Issue
Block a user