示例#1
0
 void Update()
 {
     _timer += Time.deltaTime;
     if (Input.anyKey)
     {
         if (Input.GetKeyDown(KeyCode.S))
         {
             Fall();
         }
         if (Input.GetKeyDown(KeyCode.D))
         {
             _currentpiece.Move("right");
         }
         if (Input.GetKeyDown(KeyCode.A))
         {
             _currentpiece.Move("left");
         }
         if (Input.GetKeyDown(KeyCode.Q))
         {
             _currentpiece.Turn("left");
         }
         if (Input.GetKeyDown(KeyCode.E))
         {
             _currentpiece.Turn("right");
         }
         UpdateMatrix();
     }
     if (_timer > turntime)
     {
         _timer = 0; Fall(); UpdateMatrix();
     }
 }
示例#2
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();
         }
     }
 }