예제 #1
0
 public void Start()
 {
     isRunning = GenerateNextTetromino();
     if (isRunning)
     {
         gravity.Start();
         OnTetrominoStateChanged?.Invoke(fallingTetromino);
         OnBoardStateChanged?.Invoke(board);
     }
 }
예제 #2
0
        private void TetrominoLanded()
        {
            board.AddTetromino(fallingTetromino);
            board.RemoveFullRows(fallingTetromino.Position.y, fallingTetromino.BoundingBox.height);
            OnBoardStateChanged?.Invoke(board);
            bool tetrominoAdded = GenerateNextTetromino();

            if (tetrominoAdded)
            {
                gravity.Reset();
                OnTetrominoStateChanged?.Invoke(fallingTetromino);
            }
            else
            {
                Stop();
            }
        }
예제 #3
0
        public void HandleCommand(Command command)
        {
            if (!isRunning)
            {
                return;
            }
            bool stateChanged = false;

            switch (command)
            {
            case Command.ROTATE:
                stateChanged = RotatetTetromino();
                break;

            case Command.MOVE_LEFT:
                stateChanged = MoveTetrominoLeft();
                break;

            case Command.MOVE_RIGHT:
                stateChanged = MoveTetrominoRight();
                break;

            case Command.MOVE_DOWN:
                gravity.Reset();
                stateChanged = MoveTetrominoDown();
                break;

            case Command.FALL:
                stateChanged = MoveTetrominoDown();
                break;

            case Command.DROP:
                bool lastMovedDown;
                do
                {
                    lastMovedDown = MoveTetrominoDown();
                    stateChanged |= lastMovedDown;
                } while (lastMovedDown);
                break;
            }
            if (stateChanged && isRunning)
            {
                OnTetrominoStateChanged?.Invoke(fallingTetromino);
            }
        }