示例#1
0
    private bool comprobarBloque(Vector3Int bInicio, Vector3Int bFin,
                                 Vector3Int tuberiaInicio, Vector3Int tuberiaFin)
    {
        //Crear matriz del bloque
        Vector3Int[,] matriz = new Vector3Int[Mathf.Abs(bFin.x - bInicio.x) + 1,
                                              Mathf.Abs(bFin.y - bInicio.y) + 1];
        for (int i = 0; i < matriz.GetLength(0); i++)
        {
            for (int j = 0; j < matriz.GetLength(1); j++)
            {
                matriz[i, j] = new Vector3Int(bInicio.x + i, bInicio.y + j, 0);
                //print(matriz[i, j]);

                //print("NUEVA COMPROBACION");

                if (tuberiaInicio.x == tuberiaFin.x)
                {
                    if (tuberiaFin.y < tuberiaInicio.y)
                    {
                        Vector3Int aux = tuberiaFin;
                        tuberiaFin    = tuberiaInicio;
                        tuberiaInicio = aux;
                    }

                    for (int k = 0; k < tuberiaFin.y - tuberiaInicio.y + 1; k++)
                    {
                        Vector3Int tuberiaPos = new Vector3Int(tuberiaInicio.x, tuberiaInicio.y + k, 0);
                        //print("Comprobando si " + tuberiaPos + " es igual a " + matriz[i, j]);

                        if (tuberiaPos.x == matriz[i, j].x && tuberiaPos.y == matriz[i, j].y)
                        {
                            return(true);
                        }
                    }
                }
                if (tuberiaInicio.y == tuberiaFin.y)
                {
                    if (tuberiaFin.x < tuberiaInicio.x)
                    {
                        Vector3Int aux = tuberiaFin;
                        tuberiaFin    = tuberiaInicio;
                        tuberiaInicio = aux;
                    }

                    for (int k = 0; k < tuberiaFin.x - tuberiaInicio.x + 1; k++)
                    {
                        Vector3Int tuberiaPos = new Vector3Int(tuberiaInicio.x + k, tuberiaInicio.y, 0);
                        //print("Comprobando si " + tuberiaPos + " es igual a " + matriz[i, j]);

                        if (tuberiaPos.x == matriz[i, j].x && tuberiaPos.y == matriz[i, j].y)
                        {
                            return(true);
                        }
                    }
                }
            }
        }
        return(false);
    }