コード例 #1
0
        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();
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
 public void MoveLinesUp(int count)
 {
     State = State.MoveLinesUp(count, new Random(Environment.TickCount).Next(0, 10));
 }