public void MoveTetromino(MovementDirection direction) { if (this.fallingTetromino != null && this.gameState == GameState.Running) { var movingContext = TetrominoMover.GetMoveContext(fallingTetromino, direction, movementSpeed); if (!CollisionDetector.CollisionDetected(this.fallingTetromino, this.playfieldInfo.FieldMatrix, movingContext.Positions)) { TetrominoMover.Move(this.fallingTetromino, this.playfieldInfo.FieldMatrix, movingContext); this.renderer.RenderGameField(); } else { if (direction == MovementDirection.Down) { int clearedRowsCount = this.playfieldInfo.ClearFullRows(); this.ClearedLinesCount += clearedRowsCount; if (this.clearedLinesCount >= ((this.currentLevel * 10) + 10)) { this.CurrentLevel++; int currentTimerInterval = this.frameRenderTimer.Interval.Milliseconds; this.frameRenderTimer.Interval = TimeSpan.FromMilliseconds(currentTimerInterval - 50); } this.AddToScore(ScoringSystem.GetScore(this.currentLevel, clearedRowsCount)); this.renderer.RenderGameField(); this.DropNewTetromino(); } } } }
public void RotateTetromino(bool isCounterClockwise = false) { if (this.fallingTetromino.ShapeType != TetrominoShapeType.O && this.gameState == GameState.Running) { MoveContext rotationContext = TetrominoMover.GetRotationContext(this.fallingTetromino, isCounterClockwise); if (!CollisionDetector.CollisionDetected(this.fallingTetromino, this.playfieldInfo.FieldMatrix, rotationContext.Positions)) { TetrominoMover.Rotate(this.fallingTetromino, this.playfieldInfo.FieldMatrix, rotationContext); this.renderer.RenderGameField(); } } }
private void DropNewTetromino() { if (this.TryDropNewTetromino()) { TetrominoMover.UpdateField(this.fallingTetromino, this.playfieldInfo.FieldMatrix); this.renderer.RenderGameField(); this.renderer.RenderNextShape(TetrominoPositionMatricesCache.GetTetrominoMatrix(this.nextTetromino.ShapeType), this.nextTetromino.Brush); } else { this.EndGame(); } }
private bool TryDropNewTetromino() { Tetromino tetromino = this.nextTetromino != null ? this.nextTetromino : TetrominoGenerator.GenerateRandomTetromino(new PositionInfo(3, 0)); this.nextTetromino = TetrominoGenerator.GenerateRandomTetromino(new PositionInfo(3, 0)); var movingContext = TetrominoMover.GetMoveContext(tetromino, MovementDirection.Down, movementSpeed); if (!CollisionDetector.CollisionDetected(tetromino, this.playfieldInfo.FieldMatrix, movingContext.Positions)) { this.fallingTetromino = tetromino; return(true); } return(false); }
public void Move(MovementDirection direction, int speed) { var moveContext = TetrominoMover.GetMoveContext(this, direction, speed); this.Move(moveContext); }