示例#1
0
 public void MovePiece(int row, int col)
 {
     if (currentFallingPiece != null)
     {
         bool moveLeftAllowed  = col < 0 && !tetrisBoard.IsObstructed(currentFallingPiece, TetrisBoard.ObstructionDirection.LEFT);
         bool moveRightAllowed = col > 0 && !tetrisBoard.IsObstructed(currentFallingPiece, TetrisBoard.ObstructionDirection.RIGHT);
         if (moveLeftAllowed || moveRightAllowed)
         {
             currentFallingPiece.Move(row, col);
             currentFallingPiece.ApplyChange();
             currentFallingPiece.RefreshView();
         }
     }
 }
示例#2
0
    public void AttachPiece(TetrisPiece piece, int row, int col)
    {
        piece.SetPos(row, col);
        piece.ApplyChange();
        piece.RefreshView();

        tetrisBoard.AttachPiece(piece);
        tetrisBoard.CheckRowClear();
    }
示例#3
0
    //TODO: Refactor to factory
    void RenderPiece(TetrisPiece piece)
    {
        for (int i = 0; i < piece.size.row; i++)
        {
            for (int j = 0; j < piece.size.col; j++)
            {
                if (piece.GetPiece(i, j) == 1)
                {
                    GameObject  block       = Instantiate(tetrisBlockPrefab, this.transform);
                    BoxCollider boxCollider = block.GetComponent <BoxCollider>();

                    TetrisCell tetrisCell = block.AddComponent <TetrisCell>();
                    tetrisCell.objectSize = new Vector3(boxCollider.size.x * block.transform.localScale.x, boxCollider.size.y * block.transform.localScale.y);

                    piece.objectSize = new Vector3(boxCollider.size.x * block.transform.localScale.x, boxCollider.size.y * block.transform.localScale.y);
                    piece.SetCell(i, j, tetrisCell);
                }
            }
        }

        piece.RefreshView();
    }