/// <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(); }