Ejemplo n.º 1
0
        public void RotateCurrentTetrimino(Rotation rotation)
        {
            ValidateCurrentTetriminoMissing();

            if (TetrisBoard.CanRotate(CurrentTetrimino, rotation))
            {
                TetrisBoard.Rotate(CurrentTetrimino, rotation);
            }
        }
Ejemplo n.º 2
0
 public void Rotate()
 {
     Board.Rotate();
     Invalidate(true);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Window.Title = "Tetris (MonoGame)";
            tetrisBoard  = new TetrisBoard();

            KeyboardListener keyboardListener = new KeyboardListener(new KeyboardListenerSettings());
            GamePadListener  gamePadListener  = new GamePadListener(new GamePadListenerSettings());

            Components.Add(new InputListenerComponent(this, keyboardListener, gamePadListener));

            keyboardListener.KeyPressed += (sender, args) =>
            {
                if (args.Key == Keys.Up && !tetrisBoard.IsOver)
                {
                    tetrisBoard.Rotate();
                }
                else if (args.Key == Keys.Space && !tetrisBoard.IsOver)
                {
                    tetrisBoard.PlaceDown();
                }
                else if (args.Key == Keys.C && !tetrisBoard.IsOver)
                {
                    tetrisBoard.Hold();
                }
                else if (args.Key == Keys.OemMinus)
                {
                    MediaPlayer.Volume -= 0.1f;
                }
                else if (args.Key == Keys.OemPlus)
                {
                    MediaPlayer.Volume += 0.1f;
                }
                else if (args.Key == Keys.M)
                {
                    MediaPlayer.IsMuted = !MediaPlayer.IsMuted;
                }
                else if (args.Key == Keys.R && tetrisBoard.IsOver)
                {
                    tetrisBoard = new TetrisBoard();
                    inTimer     = 500;
                    presses     = 0;
                }
            };

            gamePadListener.ButtonDown += (sender, args) =>
            {
                if (!tetrisBoard.IsOver)
                {
                    if (args.Button == Buttons.DPadUp || args.Button == Buttons.Y)
                    {
                        tetrisBoard.Rotate();
                    }
                    if (args.Button == Buttons.B)
                    {
                        tetrisBoard.PlaceDown();
                    }
                    if (args.Button == Buttons.RightShoulder || args.Button == Buttons.LeftShoulder)
                    {
                        tetrisBoard.Hold();
                    }
                }
            };

            base.Initialize();
        }