Я разрабатываю игру с концепцией Tetris. Но в моей игре я хочу очистить прямоугольник, сформированный игроком, а не строку или строку. Например, я создаю экземпляр, что блоки будут очищены, если в таблице будет 4 строки и 5 столбцов, заполненных блоками Tetris.C# Tetris, очистить сформированный прямоугольник вместо строки или строки
До сих пор это мой код, который удаляет строку:
using UnityEngine;
using System.Collections;
public class Grid : MonoBehaviour {
// The Grid itself
public static int w = 10;
public static int h = 20;
public static Transform[,] grid = new Transform[w, h];
void Start() {
}
public static Vector2 roundVec2(Vector2 v) {
return new Vector2(Mathf.Round(v.x),
Mathf.Round(v.y));
}
// helps to find out if a certain coordinate is in between the borders or if it's outside of the borders:
public static bool insideBorder(Vector2 pos) {
return ((int)pos.x >= 0 &&
(int)pos.x < w &&
(int)pos.y >= 0);
}
//The next function deletes all Blocks in a certain row.
public static void deleteRow(int y) {
for (int x = 0; x < w; ++x)
{
Destroy(grid[x, y].gameObject);
grid[x, y] = null;
}
Score.currentScore += 1;
}
// Whenever a row was deleted, the above rows should fall towards the bottom by one unit
public static void decreaseRow(int y) {
for (int x = 0; x < w; ++x)
{
if (grid[x, y] != null)
{
// Move one towards bottom
grid[x, y - 1] = grid[x, y];
grid[x, y] = null;
// Update Block position
grid[x, y - 1].position += new Vector3(0, -1, 0);
}
}
}
public static void decreaseRowsAbove(int y)
{
for (int i = y; i < h; ++i)
decreaseRow(i);
}
// function that finds out if a row is full of blocks
public static bool isRowFull(int y)
{
for (int x = 0; x < w; ++x)
if (grid[x, y] == null)
return false;
return true;
}
//a function that deletes all full rows and then always decreases the above row's y coordinate by one.
public static void deleteFullRows()
{
for (int y = 0; y < h; ++y)
{
if (isRowFull(y))
{
deleteRow(y);
decreaseRowsAbove(y + 1);
--y;
}
}
}
}
Итак, как я очистить прямоугольник, образованный в моем тетрис?
Обычный Тетрис удаляет строку или строку. Но я хочу очистить прямоугольную призму.
Благодарим Вас за ответ
постановляю: C# или Java? – RealSkeptic
И: в чем вопрос? Вы просто отказались от требований; и код, который у вас есть. – GhostCat
C# вопрос в том, как очистить прямоугольник, сформированный в моем тетрисе. Обычный тетрис удаляет строку или строку. Но я хочу очистить прямоугольную призму. Спасибо за ваш ответ – JaneTho