Time for action – handling mouse input
Add the
HandleMouseInput()
helper method to the Game1 class:private void HandleMouseInput(MouseState mouseState) { int x = ((mouseState.X - (int)gameBoardDisplayOrigin.X) / GamePiece.PieceWidth); int y = ((mouseState.Y - (int)gameBoardDisplayOrigin.Y) / GamePiece.PieceHeight); if ((x >= 0) && (x < GameBoard.GameBoardWidth) && (y >= 0) && (y < GameBoard.GameBoardHeight)) { if (mouseState.LeftButton == ButtonState.Pressed) { gameBoard.RotatePiece(x, y, false); timeSinceLastInput = 0.0f; } if (mouseState.RightButton == ButtonState.Pressed) { gameBoard.RotatePiece(x, y, true); timeSinceLastInput = 0.0f; } } }
What just happened?
The MouseState class reports the X
and Y
position of the mouse relative to the upper left corner of the window. What we really need to know is what square...