Exemple #1
0
    public bool IsValid(Mino mino, int rotationId, Vector2Int centerPos)
    {
        Mino t = new Mino(mino.id);

        t.SetRotation(rotationId);
        return(IsValid(t, centerPos));
    }
Exemple #2
0
    static Rotate GetNextRotation(Move rotate, Mino mino)
    {
        int value;

        if (rotate == Move.RightRotate)
        {
            value = ((int)mino.rotation);
            value++;
            if (value == 4)
            {
                value = 0;
            }
        }
        else if (rotate == Move.LeftRotate)
        {
            value = ((int)mino.rotation);
            value--;
            if (value == -1)
            {
                value = 3;
            }
        }
        else
        {
            throw new Exception();
        }

        return((Rotate)value);
    }
        private void CreateMino()
        {
            Mino mino = ScriptableObject.CreateInstance <Mino>();

            List <Vector2Int> localCoordinates = CalculateLocalCoordinates();
            //BlocksLocalCoordinates
            Vector2IntList vectorList = new Vector2IntList();

            vectorList.List.AddRange(localCoordinates);
            mino.AddPairInCreating(MinoSide.Bottom, vectorList);
            List <Vector2Int> rotateCoordinates = new List <Vector2Int>(localCoordinates);

            ShowCollectiction(rotateCoordinates);
            Debug.Log(Enum.GetNames(typeof(MinoSide)).Length);

            for (int index = 1; index < Enum.GetNames(typeof(MinoSide)).Length; index++)
            {
                Debug.Log("rotate");
                MinoSide key = (MinoSide)index;
                rotateCoordinates = CalculateRotateDirectionCoordinates(rotateCoordinates);
                vectorList        = new Vector2IntList();
                vectorList.List.AddRange(rotateCoordinates);
                mino.AddPairInCreating(key, vectorList);
                ShowCollectiction(rotateCoordinates);
            }


            SaveMinoAsset(mino);
        }
Exemple #4
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);
    }
Exemple #5
0
        public void HandleEvent(IFallable sender, FallEventArgs e)
        {
            if (sender == null || e == null)
            {
                return;
            }

            if (sender is Mino)
            {
                Mino mino = sender as Mino;
                Counter += mino.Game.TargetElapsedTime;
                if (Counter >= FallTimeSpan)
                {
                    mino.Position += new Vector2(0, FallVelocity);
                    Counter       -= FallTimeSpan;
                }
            }

            if (sender is Polyomino)
            {
                Polyomino polyomino = sender as Polyomino;
                Counter += polyomino.Game.TargetElapsedTime;
                if (Counter >= FallTimeSpan)
                {
                    foreach (Mino mino in polyomino.Minoes)
                    {
                        mino.Position += new Vector2(0, FallVelocity);
                    }
                    Counter -= FallTimeSpan;
                }
            }
        }
Exemple #6
0
    /// <summary>
    /// 回転したあとキックテーブルのテスト
    /// </summary>
    /// <param name="tryValue">キックテーブル</param>
    /// <param name="mino">回転させるミノ</param>
    /// <param name="field">盤面</param>
    /// <param name="afterRotate">回転後のrotatio算出出用</param>
    /// <returns></returns>
    static private bool TryMovetoValidPosition(Vector2[] tryValue, ref Mino mino, int[,] field, Rotate afterRotate)
    {
        Rotate temp = mino.rotation;

        mino.rotation = afterRotate;
        foreach (Vector2 pos in tryValue)
        {
            if (CheckValidPosition(field, mino.positions, pos))
            {
                mino.positions[0].x += pos.x;
                mino.positions[1].x += pos.x;
                mino.positions[2].x += pos.x;
                mino.positions[3].x += pos.x;

                mino.positions[0].y += pos.y;
                mino.positions[1].y += pos.y;
                mino.positions[2].y += pos.y;
                mino.positions[3].y += pos.y;
                return(true);
            }
        }
        //回転できなかった場合元に戻す処理
        SimpleRotate(temp, ref mino);
        mino.rotation = temp;
        return(false);
    }
Exemple #7
0
    public void UpdateMinosInGrid()
    {
        if (tetrominoMatrix == null)
        {
            return;
        }

        for (int row = 0; row < tetrominoMatrix.GetLength(0); row++)
        {
            bool removeRow = false;
            for (int col = 0; col < tetrominoMatrix.GetLength(1); col++)
            {
                Mino aux = GetMinoByIndex(row, col);
                if (aux != null)
                {
                    if (!CheckTetrominoInGrid(aux.transform))
                    {
                        removeRow = true;
                        continue;
                    }
                }
            }

            if (removeRow)
            {
                MoveMinoRowDown(row);
                RemoveLastMinosRow(); // we've pulled the minos to the last line
                UpdateMinosInGrid();  // needs to check again the rows //so we can just remove the minos the last line
            }
        }
        RedrawTetromino();
    }
Exemple #8
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));
    }
Exemple #9
0
 public void DisableMino(Mino mino)
 {
     mino.gameObject.SetActive(true);
     mino.transform.SetParent(poolParent.transform);
     mino.transform.name = "";
     transform.position  = Vector2.zero;
 }
Exemple #10
0
    void ApplyCurNudge()
    {
        Mino target      = null;
        bool targetFound = false;

        for (int i = curCoord.y; i < manager.gridSize.y; i++)
        {
            if (manager.gridE[curCoord.x, i].state == bState.mblock)
            {
                target      = manager.gridE[curCoord.x, i].transform.parent.GetComponent <Mino>();
                targetFound = true;
                break;
            }
        }

        if (targetFound)
        {
            target.Nudge(curShot);
        }
        else
        {
            manager.invalidSFO.GetComponent <AudioSource>().Play();
        }

        curShot  = nextShot;
        nextShot = GetRandomShot();

        return;
    }
Exemple #11
0
    public int LinesCanClear(Mino mino)//返回可消除的行数
    {
        int lines            = 0;
        List <Vector2Int> l  = GetAllCoordinates(mino);
        List <int>        ys = new List <int>();//方块占据的所有y坐标,比如竖着的长条占了4行

        foreach (Vector2Int v in l)
        {
            if (!ys.Contains(v.y))
            {
                ys.Add(v.y);
            }
        }
        ys.Sort();
        foreach (int y in ys)
        {
            bool canClear = true;
            for (int j = 0; j < 10; j++)
            {
                if (array[j, y] == 0)
                {
                    canClear = false;
                }
            }
            if (canClear)
            {
                lines++;
            }
        }

        return(lines);
    }
Exemple #12
0
    public bool HasThreeCorners(Mino tMino)//判定tspin的条件之一
    {
        int x      = tMino.position.x;
        int y      = tMino.position.y;
        int corner = 0;

        for (int i = x - 1; i <= x + 1; i += 2)
        {
            for (int j = y - 1; j <= y + 1; j += 2)
            {
                if (i < 0 || 9 < i || j < 0)
                {
                    corner++;
                    continue;
                }
                if (array[i, j] != 0)
                {
                    corner++;
                }
            }
        }
        if (corner >= 3)
        {
            return(true);
        }
        return(false);
    }
Exemple #13
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);
        }
    }
Exemple #14
0
 private void PutMino(Mino mino)
 {
     game.SetActiveMino(mino);
     _ = game.LockMino(out _);
     game.NextMino();
     if (showField)
     {
         UpdateFieldDisplay();
     }
 }
Exemple #15
0
    public override bool Equals(object obj)
    {
        if (obj.GetType() == this.GetType())
        {
            Mino m = obj as Mino;
            return(m.id == id && m.position.x == position.x && m.position.y == position.y && m.rotation == rotation);
        }

        return(base.Equals(obj));
    }
Exemple #16
0
        static public Mino Clone(Mino mino)
        {
            Mino mino_clone = new Mino();

            mino_clone.kind      = mino.kind;
            mino_clone.positions = (Vector2[])mino.positions.Clone();
            mino_clone.rotation  = mino.rotation;

            return(mino_clone);
        }
Exemple #17
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);
        }
    }
Exemple #18
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;
    }
Exemple #19
0
    public int LandHeight(Mino m)
    {
        Vector2Int pos = m.position;

        while (IsValid(m, pos))
        {
            pos.y--;
        }
        return(pos.y + 1);
    }
Exemple #20
0
    public int GetScore(Mino mino)
    {
        Field f = Clone();

        f.LockMino(mino);
        if (f.LinesCanClear(mino) > 0)
        {
            f.Clear(mino);
        }
        return(f.GetScore());
    }
Exemple #21
0
 public bool Get_ContainMino(Mino m)
 {
     if (m.MinoType == minotype && minos.Contains(m))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #22
0
 private void MoveDown()
 {
     mino.MoveDown();
     if (IsCorrectPosition(mino.Blocks))
     {
         return;
     }
     FillStateMino(mino.Blocks);
     mino = null;
     TryDellLines();
 }
Exemple #23
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);
    }
Exemple #24
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);
    }
Exemple #25
0
    public static List <SearchNode> GetLandPoints(Field field, Mino mino)
    {
        return(GetLandPointsKick(field, mino));

        if (field.CountHole(out _) == 0)
        {
            return(GetLandPointsLite(field, mino));
        }
        else
        {
            return(GetLandPointsKick(field, mino));
        }
    }
Exemple #26
0
 // Start is called before the first frame update
 void Start()
 {
     mino                 = new Mino(NextManager.Get());
     fieldTransform       = FieldMinos.GetComponent <Transform>();
     blockTransforms      = new Transform[4];
     blockSpriteRenderers = new SpriteRenderer[4];
     for (int i = 0; i < blocks.Length; ++i)
     {
         blockTransforms[i]      = blocks[i].GetComponent <Transform>();
         blockSpriteRenderers[i] = blocks[i].GetComponent <SpriteRenderer>();
     }
     SetSprites();
 }
Exemple #27
0
    void RemoveLastMinosRow()
    {
        int lastRow = tetrominoMatrix.GetLength(0) - 1;

        for (int col = 0; col < tetrominoMatrix.GetLength(1); col++)
        {// the line has switched so i want to remove the above one now
            Mino aux = GetMinoByIndex(lastRow, col);
            if (aux != null)
            {
                RemoveMinoFromMatrix(aux);
            }
        }
    }
Exemple #28
0
    public bool MoveDown(Field field, out SearchNode sn)
    {
        Vector2Int newPos = mino.position;
        Mino       tmp    = mino.Clone();
        bool       ok     = false;

        newPos.y--;
        if (field.IsValid(mino, newPos))
        {
            tmp.Fall();
            ok = true;
        }
        sn = new SearchNode(tmp, op + "d");
        return(ok);
    }
Exemple #29
0
    public bool MoveRight(Field field, out SearchNode sn)
    {
        Vector2Int newPos = mino.position;
        Mino       tmp    = mino.Clone();
        bool       ok     = false; //是否不能再往右了

        newPos.x++;
        if (field.IsValid(mino, newPos))
        {
            tmp.Move(1);
            ok = true;
        }
        sn = new SearchNode(tmp, op + "r");
        return(ok);
    }
Exemple #30
0
        private void SpawnCell(Vector2Int position, Mino minoData)
        {
            if (minoData == null)
            {
                throw new ArgumentNullException("minoData");
            }
            var cell = cellPool.Spawn();

            cells[position.x, position.y] = cell;
            cell.SetColor(minoData.Color);
            var newPosition = gridComponent.CellToLocal(new Vector3Int(position.x, position.y, 0)) + gridCornerOffset;

            cell.SetLocalPosition(newPosition);
            cell.SetLocalScale(gridComponent.cellSize);
        }