public TetrisBoard(IPieceGenerator generator, IPlayerInput playerInput)
        {
            PlayerInput = playerInput;
            PressTime = Enum.GetValues(typeof(InputButton)).OfType<InputButton>().ToDictionary(k => k, k => TimeSpan.Zero);

            State = TetrisGameState.NewGameState(generator);
            UpdateLevel();
        }
        public void Update(GameTime gameTime)
        {
            if (State.IsFinished)
                return;

            _gravityTickTimeCount += gameTime.ElapsedGameTime;

            bool forceTick = false;

            PlayerInput.Update(gameTime);
            foreach (var button in PressTime.Keys.ToArray())
                PressTime[button] += gameTime.ElapsedGameTime;

            if (Press(InputButton.Left))
            {
                State = State.MoveLeft();
                MainGame.Move.Play();
            }
            if (Press(InputButton.Right))
            {
                State = State.MoveRight();
                MainGame.Move.Play();
            }
            if (Press(InputButton.Down))
                forceTick = true;
            if (Press(InputButton.RotateCW))
            {
                State = State.RotateClockwise();
                MainGame.Move.Play();
            }
            if (Press(InputButton.RotateCCW))
            {
                State = State.RotateCounterClockwise();
                MainGame.Move.Play();
            }

            if (_gravityTickTimeCount > CurrentTickTime || forceTick)
            {
                var oldRows = State.Rows;
                State = State.Tick();
                UpdateLevel();
                var clearedRows = State.Rows - oldRows;
                if (clearedRows > 0)
                    FireLinesCleared(clearedRows);

                _gravityTickTimeCount -= CurrentTickTime;
                if (_gravityTickTimeCount < TimeSpan.Zero)
                    _gravityTickTimeCount = TimeSpan.Zero;
            }
        }
 public void MoveLinesUp(int count)
 {
     State = State.MoveLinesUp(count, new Random(Environment.TickCount).Next(0, 10));
 }