private void DrawTetromino(ITetrominoModel tetromino) { // Draw normal tetromino for (int blockLine = 0; blockLine < tetromino.NumLines; blockLine++) { for (int blockColumn = 0; blockColumn < tetromino.NumColumns; blockColumn++) { int blockType = tetromino.Blocks[blockLine, blockColumn]; if (blockType > Utils.TetrominoUtils.NoPiece) { // Converts the block line and column to board line and column int boardLine = tetromino.CurrentLine + blockLine; int boardColumn = tetromino.CurrentColumn + blockColumn; if (boardLine >= 0 && boardLine < BoardModel.NumLines && boardColumn >= 0 && boardColumn < BoardModel.NumColumns) { BoardModel.Blocks[boardLine, boardColumn] = blockType; } } } } // Update view after showing tetromino int endLine = tetromino.CurrentLine + tetromino.NumLines; int endColumn = tetromino.CurrentColumn + tetromino.NumColumns; BoardView.UpdateView(BoardModel, tetromino.CurrentLine, tetromino.CurrentColumn, endLine, endColumn, _blocks); }
private void DrawGhostTetromino(ITetrominoModel ghostTetromino) { // Draw ghost tetromino for (int blockLine = 0; blockLine < ghostTetromino.NumLines; blockLine++) { for (int blockColumn = 0; blockColumn < ghostTetromino.NumColumns; blockColumn++) { int blockType = ghostTetromino.Blocks[blockLine, blockColumn]; if (blockType > Utils.TetrominoUtils.NoPiece) { // Converts the block line and column to board line and column int boardLine = ghostTetromino.CurrentLine + blockLine; int boardColumn = ghostTetromino.CurrentColumn + blockColumn; if (boardLine >= 0 && boardLine < BoardModel.NumLines && boardColumn >= 0 && boardColumn < BoardModel.NumColumns) { BoardModel.Blocks[boardLine, boardColumn] = Utils.TetrominoUtils.GhostPiece; } } } } // Update view after showing tetromino int ghostEndLine = ghostTetromino.CurrentLine + ghostTetromino.NumLines; int ghostEndColumn = ghostTetromino.CurrentColumn + ghostTetromino.NumColumns; BoardView.UpdateView(BoardModel, ghostTetromino.CurrentLine, ghostTetromino.CurrentColumn, ghostEndLine, ghostEndColumn, _blocks); }
private bool CanPlaceTetromino(ITetrominoModel tetromino) { for (int blockLine = 0; blockLine < tetromino.NumLines; blockLine++) { for (int blockColumn = 0; blockColumn < tetromino.NumColumns; blockColumn++) { // Converts the block line and column to board line and column int boardLine = tetromino.CurrentLine + blockLine; int boardColumn = tetromino.CurrentColumn + blockColumn; if (boardLine >= 0 && boardLine < BoardModel.NumLines && boardColumn >= 0 && boardColumn < BoardModel.NumColumns) { if (tetromino.Blocks[blockLine, blockColumn] > Utils.TetrominoUtils.NoPiece && BoardModel.Blocks[boardLine, boardColumn] > Utils.TetrominoUtils.NoPiece) { return(false); } } else if (tetromino.Blocks[blockLine, blockColumn] > Utils.TetrominoUtils.NoPiece) { return(false); } } } return(true); }
public PlayerActionHappenedCommand(PlayerAction playerAction, IGameStateModel gameStateModel, ITetrominoModel tetrominoModel, IGridModel gridModel) { _playerAction = playerAction; _gameStateModel = gameStateModel; _tetrominoModel = tetrominoModel; _gridModel = gridModel; }
public FellCommand(ITetrominoModel tetrominoModel, IGridModel gridModel, IGameStateModel gameStateModel, IScoreModel scoreModel) { _tetrominoModel = tetrominoModel; _gridModel = gridModel; _gameStateModel = gameStateModel; _scoreModel = scoreModel; }
public GameSetupCommand(IDataService dataService, IGridModel gridModel, IGameStateModel gameStateModel, IScoreModel scoreModel, ITetrominoModel tetrominoModel) { _dataService = dataService; _gridModel = gridModel; _gameStateModel = gameStateModel; _scoreModel = scoreModel; _tetrominoModel = tetrominoModel; }
public static ITetrominoModel CloneTetromino(ITetrominoModel tetrominoModel) { ITetrominoModel clone = GetTetromino(tetrominoModel.PieceType); //clone.CurrentLine = tetrominoModel.CurrentLine; //clone.CurrentColumn = tetrominoModel.CurrentColumn; clone.Rotation = tetrominoModel.Rotation; return(clone); }
public int Hold(int pieceType) { int previousHoldPieceType = _holdPieceType; _holdPieceType = pieceType; ITetrominoModel tetrominoModel = TetrominoUtils.GetTetromino(_holdPieceType); DrawHoldPiece(_boardModel, _boardView, tetrominoModel); return(previousHoldPieceType); }
private void DrawHoldPiece(IBoardModel boardModel, IBoardView boardView, ITetrominoModel tetromino) { for (int line = 0; line < boardModel.NumLines; line++) { for (int column = 0; column < boardModel.NumColumns; column++) { int blockType = tetromino.BlocksPreview[line, column]; boardModel.Blocks[line, column] = blockType; } } // Update view after showing tetromino boardView.UpdateView(boardModel, _blocks); }
private IEnumerator SpawnTetromino(bool useHoldPiece) { // Create the first tetromino if (_tetrominosFactory == null) { _tetrominosFactory = GetComponent <ITetrominosFactory>(); } if (!useHoldPiece) { _currentTetromino = _tetrominosFactory.GetNextPiece(0, 3); _isHoldPiece = false; } else { // Play this as a _soundController.PlayHoldTetromino(); int previousHoldPieceType = _holdController.Hold(_currentTetromino.PieceType); if (previousHoldPieceType > Utils.TetrominoUtils.NoPiece) { _currentTetromino = _tetrominosFactory.GetNextPiece(previousHoldPieceType, 0, 3); } else { _currentTetromino = _tetrominosFactory.GetNextPiece(0, 3); } _isHoldPiece = true; } if (CanPlaceTetrominoWithWallKick(_currentTetromino)) { ClearTetromino(_currentTetromino); // Show the tetromino _ghostTetromino = Utils.TetrominoUtils.CloneTetromino(_currentTetromino); UpdateGhostTetromino(_currentTetromino, _ghostTetromino); DrawGhostTetromino(_ghostTetromino); DrawTetromino(_currentTetromino); yield return(StartCoroutine(MoveTetromino())); } else { yield return(StartCoroutine(ShowGameOver())); } }
private void UpdateGhostTetromino(ITetrominoModel tetromino, ITetrominoModel ghostTetromino) { ghostTetromino.CurrentLine = tetromino.CurrentLine; ghostTetromino.CurrentColumn = tetromino.CurrentColumn; ghostTetromino.Rotation = tetromino.Rotation; for (int line = ghostTetromino.CurrentLine; line < BoardModel.NumLines; line++) { int previousLine = ghostTetromino.CurrentLine; ghostTetromino.CurrentLine = line; if (!CanPlaceTetromino(ghostTetromino)) { ghostTetromino.CurrentLine = previousLine; break; } } }
private bool CanPlaceTetrominoWithWallKick(ITetrominoModel tetromino) { // first try int currentColumnCache = tetromino.CurrentColumn; if (!CanPlaceTetromino(tetromino)) { // second try tetromino.CurrentColumn -= 1; if (!CanPlaceTetromino(tetromino)) { // additional try that can only be used for I Pieces if (tetromino.PieceType == TetrominoUtils.IPieceType) { tetromino.CurrentColumn -= 1; if (CanPlaceTetromino(tetromino)) { return(true); } } // last try tetromino.CurrentColumn = currentColumnCache; tetromino.CurrentColumn += 1; if (!CanPlaceTetromino(tetromino)) { // additional try that can only be used for I Pieces if (tetromino.PieceType == TetrominoUtils.IPieceType) { tetromino.CurrentColumn += 1; if (CanPlaceTetromino(tetromino)) { return(true); } } tetromino.CurrentColumn = currentColumnCache; return(false); } } } return(true); }