Exemplo n.º 1
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.º 2
0
    public bool IsValid(Mino mino, Vector2Int centerPos)
    {
        int  minoId  = mino.GetIdInt();
        int  x       = centerPos.x;
        int  y       = centerPos.y;
        Mino tmpMino = new Mino(mino.id);

        tmpMino.SetRotation(mino.GetRotationId());
        tmpMino.SetPosition(centerPos);

        List <Vector2Int> l = GetAllCoordinates(tmpMino);

        foreach (Vector2Int v in l)
        {
            int i = v.x;
            int j = v.y;
            if (i > 9 || i < 0)
            {
                return(false);
            }
            if (j < 0)
            {
                return(false);
            }
            if (array[i, j] != 0)
            {
                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 3
0
    public int CCWRotate()//逆时针旋转
    {
        int size          = activeMino.GetSize();
        int newRotationId = (activeMino.GetRotationId() + 3) % 4;

        if (size == 3)
        {
            if (field.IsValid(activeMino, newRotationId, activeMino.GetPosition()))//如果可以直接转进去
            {
                operation += "z";
                activeMino.CCWRotate();
                return(0);
            }
            else//如果不能就做踢墙检定
            {
                Vector2Int o = WallKickOffset(activeMino, activeMino.GetRotationId(), newRotationId, activeMino.GetPosition());
                if (o != new Vector2Int(0, 0))
                {
                    activeMino.CCWRotate();
                    activeMino.Move(o);

                    operation += "Z";
                    return(0);
                }
            }
        }
        else if (size == 5)
        {
            bool       iSpin = true;
            Vector2Int o     = WallKickOffset_I(field, activeMino, activeMino.GetRotationId(), newRotationId, activeMino.GetPosition(), out iSpin);
            if (o != new Vector2Int(0, 0))
            {
                activeMino.CCWRotate();
                activeMino.Move(o);
                if (iSpin)
                {
                    operation += "Z";
                }
                else
                {
                    operation += "z";
                }
                return(0);
            }
        }
        return(-1);
    }