Exemplo n.º 1
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.º 2
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.º 3
0
    private void UpdateActiveMinoDisplay()
    {
        DestroyAllChild(ActiveMinoParent);
        Mino tmpMino = game.GetActiveMino();

        //方块
        List <Vector2Int> l = Field.GetAllCoordinates(game.activeMino);
        int ghostDist       = tmpMino.GetPosition().y - game.GetGhostY();

        foreach (Vector2Int v in l)
        {
            DisplayUtils.InstChild(MinoTiles[tmpMino.GetIdInt() - 1], new Vector3(v.x, v.y, 0), ActiveMinoParent);
            if (game.Playing())
            {
                DisplayUtils.InstChild(MinoTiles[tmpMino.GetIdInt() - 1], new Vector3(v.x, v.y - ghostDist, 0), ActiveMinoParent, 1, 0.5f);
            }
        }
    }
Exemplo n.º 4
0
    public void ShowMino(Mino mino)
    {
        List <Vector2Int> l = Field.GetAllCoordinates(mino);

        foreach (Vector2Int v in l)
        {
            DisplayUtils.InstChild(MinoTiles[mino.GetIdInt() - 1], new Vector3(v.x, v.y, 0), MinoParent);
        }
    }
Exemplo n.º 5
0
    public void LockMino(Mino currentMino)
    {
        List <Vector2Int> l = GetAllCoordinates(currentMino);

        foreach (Vector2Int pos in l)
        {
            array[pos.x, pos.y] = currentMino.GetIdInt();
        }
        dig = 0;
    }
Exemplo n.º 6
0
    public void ShowMino(int minoID, int x, int y, int rotation)
    {
        Mino mino           = new Mino(minoID, x, y, rotation);
        List <Vector2Int> l = Field.GetAllCoordinates(mino);

        foreach (Vector2Int v in l)
        {
            DisplayUtils.InstChild(MinoTiles[mino.GetIdInt() - 1], new Vector3(v.x, v.y, 0), MinoParent);
        }
    }
Exemplo n.º 7
0
    public static ClearType CheckClearType(Field field, Mino mino, string op, int combo, bool wasB2B)
    {
        ClearType clearType;
        Field     fClone = field.Clone();

        fClone.LockMino(mino);

        int minoId = mino.GetIdInt();
        int lines  = fClone.LinesCanClear(mino);

        bool tSpin     = false;
        int  tSpinType = 0;//0mini 1single 2double 3triple
        bool spin      = IsWallKick(op);
        bool pc        = fClone.IsAllClear(lines);

        //bool wasB2b;
        //int combo;


        if (mino.id == Mino.MinoID.T)//tspin判定
        {
            bool c, f;
            c = field.HasThreeCorners(mino);
            f = field.HasTwoFeets(mino);
            if (lines == 1)
            {
                //Debug.Log(cannotGoUp);
                if (c && f)//t-spin single
                {
                    tSpin     = true;
                    tSpinType = 1;
                }
                else if (c && !f && spin)//t-spin mini
                {
                    tSpin     = true;
                    tSpinType = 0;
                }
            }
            else if (lines == 2 && (c || spin))//t-spin double
            {
                tSpin     = true;
                tSpinType = 2;
            }
            else if (lines == 3)
            {
                tSpin     = true;
                tSpinType = 3;
            }
        }
        clearType = new ClearType(minoId, lines, tSpin, tSpinType, pc, combo, wasB2B);

        return(clearType);
    }
Exemplo n.º 8
0
    public void UpdateMino(Mino activeMino)
    {
        foreach (Transform child in this.gameObject.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        int cellSize = (int)gameObject.GetComponent <RectTransform>().rect.width / 10;
        int minoId   = activeMino.GetIdInt();

        foreach (Vector2Int v in Field.GetAllCoordinates(activeMino))
        {
            AddImage(minoId, v.x, v.y, cellSize);
        }
    }
Exemplo n.º 9
0
    public void UpdateActiveMino(Field field, Mino activeMino)
    {
        foreach (Transform child in this.gameObject.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        int cellSize    = (int)gameObject.GetComponent <RectTransform>().rect.width / 10;
        int minoId      = activeMino.GetIdInt();
        int ghostHeight = field.LandHeight(activeMino);

        foreach (Vector2Int v in Field.GetAllCoordinates(activeMino))
        {
            AddImage(minoId, v.x, v.y, cellSize);
            AddGhostImage(minoId, v.x, v.y - activeMino.position.y + ghostHeight, cellSize);
        }
    }
Exemplo n.º 10
0
    public void ApplyNextSeq()
    {
        int  len = nextSeq.Length;
        Mino m   = new Mino();
        bool ValidNextSequence = true;

        Debug.Log(nextSeq);
        foreach (char c in nextSeq)
        {
            if (Mino.NameToId(c.ToString()) == -1)
            {
                ValidNextSequence = false;
            }
        }
        ;
        if (ValidNextSequence)
        {
            nextQueue.Clear();
            foreach (char c in nextSeq)
            {
                nextQueue.Enqueue(m.GetIdInt());
            }
        }
    }
Exemplo n.º 11
0
 public int GetActiveMinoId()
 {
     return(activeMino.GetIdInt());
 }