Esempio n. 1
0
        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();
                    }
                }
            }
        }
Esempio n. 2
0
        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();
                }
            }
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public void Move(MovementDirection direction, int speed)
        {
            var moveContext = TetrominoMover.GetMoveContext(this, direction, speed);

            this.Move(moveContext);
        }