Tetris.Board.MoveFigureDown C# (CSharp) Method

MoveFigureDown() public method

public MoveFigureDown ( ) : void
return void
        public void MoveFigureDown()
        {
            // Sorting blocks fro dynamic figure to correct moving
            SortingVector2(ref DynamicFigure, false, DynamicFigure.GetLowerBound(0), 
                DynamicFigure.GetUpperBound(0));
            // Check colisions
            for (int i = 0; i < BlocksCountInFigure; i++)
            {
                if ((DynamicFigure[i].Y == height - 1))
                {
                    for (int k = 0; k < BlocksCountInFigure; k++)
                        boardFields[(int)DynamicFigure[k].X, (int)DynamicFigure[k].Y] = FieldState.Static;
                    showNewBlock = true;
                    return;
                }
                if (boardFields[(int)DynamicFigure[i].X, (int)DynamicFigure[i].Y + 1] == FieldState.Static)
                {
                    for (int k = 0; k < BlocksCountInFigure; k++)
                        boardFields[(int)DynamicFigure[k].X, (int)DynamicFigure[k].Y] = FieldState.Static;
                    showNewBlock = true;
                    return;
                }
            }
            // Move figure on board
            for (int i = BlocksCountInFigure - 1; i >= 0; i--)
            {
                boardFields[(int)DynamicFigure[i].X, (int)DynamicFigure[i].Y + 1] =
                    boardFields[(int)DynamicFigure[i].X, (int)DynamicFigure[i].Y];
                BoardColor[(int)DynamicFigure[i].X, (int)DynamicFigure[i].Y + 1] =
                    BoardColor[(int)DynamicFigure[i].X, (int)DynamicFigure[i].Y];
                ClearBoardField((int)DynamicFigure[i].X, (int)DynamicFigure[i].Y);
                // Change position for blocks in DynamicFigure
                DynamicFigure[i].Y = DynamicFigure[i].Y + 1;
            }
            // Change position vector
            //if (PositionForDynamicFigure.Y < height - 1)
            PositionForDynamicFigure.Y++;
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // Check pause
            bool pauseKey = (oldKeyboardState.IsKeyDown(Keys.P) && (keyboardState.IsKeyUp(Keys.P)));

            oldKeyboardState = keyboardState;

            if (pauseKey)
            {
                pause = !pause;
            }

            if (!pause)
            {
                // Find dynamic figure position
                board.FindDynamicFigure();

                // Increase player score
                int lines = board.DestroyLines();
                if (lines > 0)
                {
                    score.Value += (int)((5.0f / 2.0f) * lines * (lines + 3));
                    board.Speed += 0.005f;
                }

                score.Level = (int)(10 * board.Speed);

                // Create new shape in game
                if (!board.CreateNewFigure())
                {
                    GameOver();
                }
                else
                {
                    // If left key is pressed
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        board.MoveFigureLeft();
                    }
                    // If right key is pressed
                    if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        board.MoveFigureRight();
                    }
                    // If down key is pressed
                    if (keyboardState.IsKeyDown(Keys.Down))
                    {
                        board.MoveFigureDown();
                    }

                    // Rotate figure
                    if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Space))
                    {
                        board.RotateFigure();
                    }

                    // Moving figure
                    if (board.Movement >= 1)
                    {
                        board.Movement = 0;
                        board.MoveFigureDown();
                    }
                    else
                    {
                        board.Movement += board.Speed;
                    }
                }
            }

            base.Update(gameTime);
        }