Fix human player able to make illegal move during bot's turn

This commit is contained in:
Sebastian Lague 2023-07-22 13:18:30 +02:00
parent 3711d23f1e
commit 85219733d3

View file

@ -14,6 +14,7 @@ namespace ChessChallenge.Application
// State // State
bool isDragging; bool isDragging;
int selectedSquare; int selectedSquare;
bool isTurnToMove;
public HumanPlayer(BoardUI boardUI) public HumanPlayer(BoardUI boardUI)
@ -25,7 +26,7 @@ namespace ChessChallenge.Application
public void NotifyTurnToMove() public void NotifyTurnToMove()
{ {
isTurnToMove = true;
} }
public void SetPosition(string fen) public void SetPosition(string fen)
@ -35,6 +36,10 @@ namespace ChessChallenge.Application
public void Update() public void Update()
{ {
if (!isTurnToMove)
{
return;
}
Vector2 mouseScreenPos = Raylib.GetMousePosition(); Vector2 mouseScreenPos = Raylib.GetMousePosition();
Vector2 mouseWorldPos = Program.ScreenToWorldPos(mouseScreenPos); Vector2 mouseWorldPos = Program.ScreenToWorldPos(mouseScreenPos);
@ -98,6 +103,7 @@ namespace ChessChallenge.Application
if (isLegal) if (isLegal)
{ {
isTurnToMove = false;
MoveChosen?.Invoke(move); MoveChosen?.Invoke(move);
} }
} }