コード例 #1
0
        /// <summary>
        /// Moving the blocks down, left, or right.
        /// </summary>
        public void MoveKeys()
        {
            int blockstate = (int)gbObj.CheckPlacement(loadedBoard, shape, posX, posY);

            // Console.WriteLine("blockstate: {0}, {1}", moveLeftState, moveRightState);
            int rightWall = boundsX + pixelWidth * 9;

            if (oldKeyState.IsKeyDown(Keys.Up) && currentKeyState.IsKeyUp(Keys.Up) && blockstate != 1)
            { //updates when up is pressed
                Rotate(currentShape);

                if ((currentShape == 6 || currentShape == 3 || currentShape == 4) && (moveLeftState >= 362 && moveRightState <= boundsX))
                {
                    if (rotateIndex < 4)
                    {
                        Array.Copy(rotate[rotateIndex++], shape, shape.Length);
                    }
                    else
                    {
                        rotateIndex = 0;
                    }
                }
                else if (currentShape != 6 && currentShape != 4 && currentShape != 3)
                {
                    if (rotateIndex < 4)
                    {
                        Array.Copy(rotate[rotateIndex++], shape, shape.Length);
                    }
                    else
                    {
                        rotateIndex = 0;
                    }
                }
            }
            else if (oldKeyState.IsKeyDown(Keys.Left) && currentKeyState.IsKeyUp(Keys.Left))
            {
                //int blockstate = (int)gbObj.CheckPlacement(gameBoard, shape,(int)tetrisBlock.X, (int)tetrisBlock.Y);
                // moveLeftState = blockstate;
                if (moveLeftState >= 362)
                {
                    Console.WriteLine("moveLeft: {0}", moveLeftState);
                    posX -= pixelWidth;
                }
            }
            else if (oldKeyState.IsKeyDown(Keys.Right) && currentKeyState.IsKeyUp(Keys.Right))
            {
                //int blockstate = (int)gbObj.CheckPlacement(gameBoard, shape, (int)tetrisBlock.X, (int)tetrisBlock.Y);
                //moveRightState = blockstate;

                if (moveRightState <= boundsX)
                {
                    Console.WriteLine("moveRight: {0}", moveRightState);

                    posX += pixelWidth;
                }
            }
            else if (oldKeyState.IsKeyDown(Keys.Down) && currentKeyState.IsKeyUp(Keys.Down))
            {
                //if (moveDownState <= boundsY)
                posY += pixelWidth;
            }
            else if (oldKeyState.IsKeyDown(Keys.Enter) && currentKeyState.IsKeyUp(Keys.Enter))
            { //updates when enter is pressed
                SpawnShape();
            }
        }