2021年1月23日星期六

Issues with picking in c# XNA

Im attempting to make a chess game, to move the pieces im using picking, so the user clicks on a piece to set it as the selected piece, then on the square they want to move it to. This works the first time, but when you click on a different piece to make that the selected piece, and then an empty square to move it, it moves the first selected piece instead. Here's my code and thanks in advance to anyone who can help.

string[,] Board =      {          {"BRook1", "BKnight1", "BBisop1", "BQueen", "BKing", "BBishop2", "BKnight2", "BRook2"},          {"BPawn1", "BPawn2", "BPawn3", "BPawn4", "BPawn5", "BPawn6", "BPawn7", "BPawn8"},          {null, null, null, null, null, null, null, null },          {null, null, null, null, null, null, null, null },          {null, null, null, null, null, null, null, null },          {null, null, null, null, null, null, null, null },          {"WPawn1", "WPawn2", "WPawn3", "WPawn4", "WPawn5", "WPawn6", "WPawn7", "WPawn8"},          {"WRook1", "WKnight1", "WBishop1", "WQueen", "WKing", "WBishop2", "WKnight2", "WRook2"},      };            MouseState mouseState = Mouse.GetState();          decimal decMousex = mouseState.X;          decimal decMousey = mouseState.Y;          y = Convert.ToInt32(Math.Floor(decMousex / 75));          x = Convert.ToInt32(Math.Floor(decMousey / 75));                      if (mouseState.LeftButton == ButtonState.Pressed              && Board[x,y] != null && pieceSelected == null)          {              pieceSelected = Board[x, y];              selectedX = x;              selectedY = y;          }            else if (mouseState.LeftButton == ButtonState.Pressed                  && Board[x,y] == null && pieceSelected != null)          {              Board[selectedX, selectedY] = null;              Board[x, y] = pieceSelected;              pieceSelected = null;          }  
https://stackoverflow.com/questions/65865827/issues-with-picking-in-c-sharp-xna January 24, 2021 at 07:59AM

没有评论:

发表评论