【发布时间】:2016-09-05 09:46:52
【问题描述】:
我正在开发一款具有俄罗斯方块概念的游戏,但在我的游戏中,我想要清除的是玩家形成的矩形,而不是行或线。例如,我实例化如果网格上有 4 行和 5 列填充有俄罗斯方块块,这些块将被清除。
到目前为止,这是我删除一行的代码:
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?
-
还有:问题是什么?你只是放弃了要求;和您当前拥有的代码。
-
C# 问题是如何清除在俄罗斯方块中形成的矩形。通常的俄罗斯方块删除行或行。但我想要的是清除一个矩形棱镜。感谢您的回复
-
@ChristophKn 不,只有在需要时才写。