Exemplo n.º 1
0
    public static Vector2Int WallKickOffset(Field field, Mino mino, int A, int B, Vector2Int coordinate)//A和B都是rotationId
    {
        int size = mino.GetSize();

        if (size == 3)
        {
            for (int i = 0; i < 5; i++)
            {
                //Debug.Log("A:" + A + "  B:" + B);
                //Debug.Log(coordinate + OFFSET_3x3[i, A] - OFFSET_3x3[i, B] + " " + i);

                if (field.IsValid(mino, B, coordinate + OFFSET_3x3[i, A] - OFFSET_3x3[i, B]))
                {
                    return(OFFSET_3x3[i, A] - OFFSET_3x3[i, B]);
                }
            }
        }
        else if (size == 5)
        {
            for (int i = 0; i < 5; i++)
            {
                if (field.IsValid(mino, B, coordinate + OFFSET_I[i, A] - OFFSET_I[i, B]))
                {
                    return(OFFSET_I[i, A] - OFFSET_I[i, B]);
                }
            }
        }
        return(new Vector2Int(0, 0));
    }
Exemplo n.º 2
0
    List <Vector2Int> GetAllCoordinates()//mino四个格子的坐标
    {
        List <Vector2Int> l = new List <Vector2Int>();
        int size            = activeMino.GetSize();

        if (size == 3)
        {
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (activeMino.array[j, i] == 1)
                    {
                        l.Add(new Vector2Int(i - 1 + activeMino.GetPosition().x, j - 1 + activeMino.GetPosition().y));
                    }
                }
            }
        }
        else if (size == 5)
        {
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (activeMino.array[j, i] == 1)
                    {
                        l.Add(new Vector2Int(i - 2 + activeMino.GetPosition().x, j - 2 + activeMino.GetPosition().y));
                    }
                }
            }
        }

        else if (size == 2)
        {
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    l.Add(new Vector2Int(i + activeMino.GetPosition().x, j + activeMino.GetPosition().y));
                }
            }
        }
        return(l);
    }
Exemplo n.º 3
0
    public bool RotateCCW(Field field, out SearchNode sn)
    {
        bool   ok            = false;
        Mino   tmp           = mino.Clone();
        int    size          = tmp.GetSize();
        int    newRotationId = (tmp.GetRotationId() + 3) % 4;
        string k             = "z";


        if (size == 3)
        {
            if (field.IsValid(tmp, newRotationId, tmp.GetPosition()))//如果可以直接转进去
            {
                tmp.CCWRotate();
                ok = true;
            }
            else//如果不能就做踢墙检定
            {
                Vector2Int o = Game.WallKickOffset(field, tmp, tmp.GetRotationId(), newRotationId, tmp.GetPosition());
                if (o != new Vector2Int(0, 0))
                {
                    tmp.CCWRotate();
                    tmp.Move(o);
                    k  = "Z";
                    ok = true;
                }
                else
                {
                    ok = false;
                }
            }
        }
        else if (size == 5)
        {
            Vector2Int o = Game.WallKickOffset_I(field, tmp, tmp.GetRotationId(), newRotationId, tmp.GetPosition(), out bool iSpin);
            if (o != new Vector2Int(0, 0))
            {
                tmp.CCWRotate();
                tmp.Move(o);
                if (iSpin)
                {
                    k = "Z";
                }
                ok = true;
            }
            else
            {
                ok = false;
            }
        }
        sn = new SearchNode(tmp, op + k);
        return(ok);
    }
Exemplo n.º 4
0
    public void RefreshField(Mino currentMino)
    {                                //在确定新的方块坐标和方向后,刷新field中的元素
        for (int i = 0; i < 10; i++) //先清除地形以外的元素
        {
            for (int j = 0; j < 40; j++)
            {
                if (array[i, j] > 0)
                {
                    array[i, j] = 0;
                }
            }
        }
        ghostDist = 0;//阴影距离
        int  size = currentMino.GetSize();
        bool shadowTouchGround = false;
        List <Vector2Int> l    = GetAllCoordinates(currentMino);

        while (!shadowTouchGround)//方块下方阴影只要有一块即将重叠,就停止增加阴影距离
        {
            foreach (Vector2Int pos in l)
            {
                if (pos.y - ghostDist <= 0)
                {
                    shadowTouchGround = true;
                    break;
                }
                if (array[pos.x, pos.y - ghostDist - 1] < 0)
                {
                    shadowTouchGround = true;
                    break;
                }
            }
            if (!shadowTouchGround)
            {
                ghostDist++;
            }
        }
        foreach (Vector2Int pos in l)//写入阴影
        {
            array[pos.x, pos.y - ghostDist] = 20 + currentMino.GetIdInt();
        }
        foreach (Vector2Int pos in l)//写入方块
        {
            array[pos.x, pos.y] = currentMino.GetIdInt();
        }
    }
Exemplo n.º 5
0
    public static List <Vector2Int> GetAllCoordinates(Mino m)//mino四个格子的坐标
    {
        List <Vector2Int> l = new List <Vector2Int>();
        int size            = m.GetSize();

        if (size == 3)
        {
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (m.array[j, i] == 1)
                    {
                        l.Add(new Vector2Int(i - 1 + m.position.x, j - 1 + m.position.y));
                    }
                }
            }
        }
        else if (size == 5)
        {
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (m.array[j, i] == 1)
                    {
                        l.Add(new Vector2Int(i - 2 + m.position.x, j - 2 + m.position.y));
                    }
                }
            }
        }

        else if (size == 2)
        {
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    l.Add(new Vector2Int(i + m.position.x, j + m.position.y));
                }
            }
        }
        return(l);
    }