public void Start() { isRunning = GenerateNextTetromino(); if (isRunning) { gravity.Start(); OnTetrominoStateChanged?.Invoke(fallingTetromino); OnBoardStateChanged?.Invoke(board); } }
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(); } }
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); } }