C#俄罗斯方块,清除形成的矩形,而不是行或线
我正在开发一个具有俄罗斯方块概念的游戏,但在我的游戏中,我想澄清的是玩家形成的矩形,而不是行或线。例如,我举例说明,如果网格上有4行5列填充了俄罗斯方块块,那么这些块将被清除 到目前为止,这是我删除一行的代码:C#俄罗斯方块,清除形成的矩形,而不是行或线,c#,unity3d,tetris,C#,Unity3d,Tetris,我正在开发一个具有俄罗斯方块概念的游戏,但在我的游戏中,我想澄清的是玩家形成的矩形,而不是行或线。例如,我举例说明,如果网格上有4行5列填充了俄罗斯方块块,那么这些块将被清除 到目前为止,这是我删除一行的代码: using UnityEngine; using System.Collections; public class Grid : MonoBehaviour { // The Grid itself public static int w = 10; publ
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;
}
}
}
}
使用UnityEngine;
使用系统集合;
公共类网格:单行为{
//网格本身
公共静态int w=10;
公共静态int h=20;
公共静态变换[,]网格=新变换[w,h];
无效开始(){
}
公共静态矢量2 RONDVEC2(矢量2 v){
返回新矢量2(数学圆(v.x),
数学圆(v.y));
}
//有助于确定某个坐标是在边界之间还是在边界之外:
公共静态布尔内部订单(矢量2位置){
返回((int)pos.x>=0&&
(内部)位置x=0);
}
//下一个函数删除特定行中的所有块。
公共静态void deleteRow(int y){
对于(int x=0;x
那么,如何清除俄罗斯方块中形成的矩形呢
通常的俄罗斯方块删除行或行。但我想要的是清除一个矩形棱镜
感谢您的回复诸如此类:
public static void deleteGrid(int startX, int startY, int width = 5, int height = 4)
{
// to avoid Errors, Check if indexes are in bound for grid.
// if condition code goes here
// then...
for (int i = startX; i < startX + width; i++)
{
for (int j = startY; j < startY + height; j++)
{
Destroy(grid[i, j].gameObject);
grid[i, j] = null;
}
}
Score.currentScore += 1;
}
Grid.deleteGrid(2,3); // default width = 5, height = 4 will be used here.
或
决定:C#还是Java?问题是什么?你只是放弃了要求;问题是如何清除俄罗斯方块中形成的矩形。通常的俄罗斯方块删除行或行。但我想要的是清除一个矩形棱镜。谢谢你的支持response@ChristophKn没有。你只在需要的时候才写。谢谢你的回复和编辑我的问题。它有一个错误,说明“没有重载方法'deleteRow'接受'1'参数。很抱歉,我是游戏开发新手。我将编辑我的问题并放入我的整个脚本。谢谢我已更新了我的答案。您在哪里调用
deleteRow()<代码> > DeleTeReG/<代码>对我来说仍然不起作用。我认为你的代码没有问题。我真的不知道如何应用它。真的。你能考虑一下我的全部源代码吗?谢谢你帮我一个忙。这是你的一部分,找出使用这个代码的地方。请把答案标记为“所有连接”。删除块。当块被清除时,上面的俄罗斯方块会掉下来。我所做的是将deleteRow()替换为您建议的。但是它显示了一个重载错误。
Grid.deleteGrid(2,3,3,3); // this will delete 3X3 grid at index (2,3)