Example #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            var state = inputManager.HandleInput();

            if (state.isPausePressed)
            {
                paused = !paused;
            }

            if (!paused && !gameLost)
            {
                board.ClearBlock(currBlock);

                if (state.isUpPressed)
                {
                    while (board.BlockCanMove(currBlock, 0, 1))
                    {
                        currBlock.MoveDown(1);
                    }
                    currBlock.IsSet = true;
                }
                if (state.isDownPressed && board.BlockCanMove(currBlock, 0, 1))
                {
                    currBlock.MoveDown(1);
                }
                if (state.isRightPressed && board.BlockCanMove(currBlock, 1, 0))
                {
                    currBlock.HorizontalMove(true);
                }
                if (state.isLeftPressed && board.BlockCanMove(currBlock, -1, 0))
                {
                    currBlock.HorizontalMove(false);
                }
                if (state.isRotateLeftPressed)
                {
                    currBlock.RotateLeft();
                }
                if (state.isRotateRightPressed)
                {
                    currBlock.RotateRight();
                }
                if (state.isHoldPressed)
                {
                    HoldBlock();
                }


                // TODO: Add your update logic here
                var time  = gameTime.TotalGameTime;
                var delta = time - _lastUpdate;
                totalTime += gameTime.ElapsedGameTime;


                if (delta.TotalMilliseconds > blockUpdateDelta)
                {
                    _lastUpdate = time;
                    if (board.BlockCanMove(currBlock, 0, 1))
                    {
                        currBlock.MoveDown(1);
                    }
                }

                currBlock.Update((float)gameTime.ElapsedGameTime.TotalMilliseconds);
                board.UpdateBlock(currBlock);

                if (currBlock.IsSet)
                {
                    currBlock = blockQueue.Dequeue();
                    AddBlock();
                    score   += board.Update();
                    gameLost = board.DidLose();
                }
            }
            nextBlockDisplay.Block = blockQueue.Peek();

            base.Update(gameTime);
        }